Skip to content

Merge pull request #42 from WildCodeSchool/staging #25

Merge pull request #42 from WildCodeSchool/staging

Merge pull request #42 from WildCodeSchool/staging #25

Workflow file for this run

name: CD Pipeline for Angular Frontend
on:
push:
branches:
- staging
- production
jobs:
build-and-push:
name: 🛠️ Build & Push Angular Docker image
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS }}
- name: Set Docker image tag
id: set_tag
run: |
if [[ "${GITHUB_REF##*/}" == "production" ]]; then
echo "tag=production" >> "$GITHUB_OUTPUT"
else
echo "tag=staging" >> "$GITHUB_OUTPUT"
fi
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: hryssssy/handy-frontend:${{ steps.set_tag.outputs.tag }}
build-args: |
BUILD_CONFIGURATION=${{ steps.set_tag.outputs.tag }}
deploy:
name: 🚀 Deploy Angular to VPS
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.VPS_SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519_staging
chmod 600 ~/.ssh/id_ed25519_staging
- name: SSH to VPS and deploy
run: |
TAG=${{ needs.build-and-push.outputs.tag }}
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_ed25519_staging ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << EOF
cd /home/${{ secrets.VPS_USER }}/frontend/$TAG
docker compose pull
docker compose down && docker compose up -d
EOF