CI: change node to v20 and fix docker run #11
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration (Dev) | |
on: | |
push: | |
tags: | |
- 'v[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 | |
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 | |
script: | | |
export $AWS_ACCESS_KEY_ID | |
export $AWS_SECRET_ACCESS_KEY | |
export $DOCKER_IMAGE_WITH_TAG | |
echo "hello" | |
echo "$DOCKER_IMAGE_WITH_TAG" | |
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 stop training-api | |
docker rm training-api | |
docker run -p 3001:3001 --name training-api -d $DOCKER_IMAGE_WITH_TAG |