Skip to content

Merge branch 'main' of https://github.com/oddsteam/training-api #22

Merge branch 'main' of https://github.com/oddsteam/training-api

Merge branch 'main' of https://github.com/oddsteam/training-api #22

Workflow file for this run

name: Continuous Integration (Dev)
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+-dev'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DOCKER_IMAGE: 844772501268.dkr.ecr.ap-southeast-1.amazonaws.com/training-api
DOCKER_REGISTRY: 844772501268.dkr.ecr.ap-southeast-1.amazonaws.com
DB_URI: ${{ secrets.DB_URI_DEV }}
jobs:
ci:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Prepare metadata for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=raw,value=${{ github.ref_name }}
- name: Build a Docker image
uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: ./Dockerfile
push: false
load: true
tags: ${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
- name: Login to Amazon ECR
if: ${{ github.event_name == 'push' }}
uses: docker/login-action@v2
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ env.AWS_ACCESS_KEY_ID }}
password: ${{ env.AWS_SECRET_ACCESS_KEY }}
- name: Push the Docker image
if: ${{ github.event_name == 'push' }}
uses: docker/build-push-action@v4
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
file: ./Dockerfile
labels: ${{ steps.meta.outputs.labels }}
push: true
tags: ${{ steps.meta.outputs.tags }}
- name: executing remote ssh commands using ssh key
uses: appleboy/ssh-action@v1.0.3
env:
DOCKER_IMAGE_WITH_TAG: ${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}
with:
host: ${{ secrets.HOST_DEV }}
username: ubuntu
key: ${{ secrets.HOST_DEV_KEY }}
port: 22
envs: DOCKER_IMAGE_WITH_TAG, DB_URI
script: |
export $AWS_ACCESS_KEY_ID
export $AWS_SECRET_ACCESS_KEY
aws ecr get-login-password --region ap-southeast-1 | docker login --username AWS --password-stdin 844772501268.dkr.ecr.ap-southeast-1.amazonaws.com
docker pull $DOCKER_IMAGE_WITH_TAG
docker rm -f training-api | true
docker run -p 3001:3001 --name training-api -e DB_URI=$DB_URI -d $DOCKER_IMAGE_WITH_TAG