Skip to content

Update build-push-image.yml #6

Update build-push-image.yml

Update build-push-image.yml #6

name: Docker Image CI/CD
on:
push:
branches: [ "main" ]
env:
IMAGE_NAME_API: ontario-park-audio-api
IMAGE_NAME_FRONTEND: ontario-park-audio-frontend
jobs:
push-new-images-and-audo-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker-compose up --build -d
- name: Log into GitHub Container Registry
run: echo "${{ secrets.PERSONAL_ACCESS_TOKEN }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID_API=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_API
echo IMAGE_ID_API=$IMAGE_ID_API
docker tag $IMAGE_NAME_API $IMAGE_ID_API:latest
docker push $IMAGE_ID_API:latest
IMAGE_ID_FRONTEND=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME_FRONTEND
echo IMAGE_ID_FRONTEND=$IMAGE_ID_FRONTEND
docker tag $IMAGE_NAME_FRONTEND $IMAGE_ID_FRONTEND:latest
docker push $IMAGE_ID_FRONTEND:latest
- name: Connect to VM and run updated images
run: |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > private_key && chmod 600 private_key
ssh -o StrictHostKeyChecking=no -i private_key [email protected] '
cd /home/ec2-user/project-24-ontario-parks-T &&
git pull &&
docker-compose pull &&
docker-compose up -d
'