chore : Update bash script for updating appVersion #8
Workflow file for this run
This file contains hidden or 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: Release Dev | |
| on: | |
| push: | |
| tags: | |
| - "*-dev.*" | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAMESPACE: hervibest | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set version from tag | |
| run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV | |
| - name: Login to GitHub Container Registry | |
| run: | | |
| echo "${{ secrets.GITHUB_TOKEN }}" | \ | |
| docker login ghcr.io \ | |
| -u ${{ github.actor }} \ | |
| --password-stdin | |
| # ====================== | |
| # photo-svc | |
| # ====================== | |
| - name: Build & Push photo-svc | |
| run: | | |
| docker build \ | |
| -f photo-svc/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAMESPACE/photo-svc:$VERSION . | |
| docker push $REGISTRY/$IMAGE_NAMESPACE/photo-svc:$VERSION | |
| # ====================== | |
| # upload-svc | |
| # ====================== | |
| - name: Build & Push upload-svc | |
| run: | | |
| docker build \ | |
| -f upload-svc/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAMESPACE/upload-svc:$VERSION . | |
| docker push $REGISTRY/$IMAGE_NAMESPACE/upload-svc:$VERSION | |
| # ====================== | |
| # user-svc | |
| # ====================== | |
| - name: Build & Push user-svc | |
| run: | | |
| docker build \ | |
| -f user-svc/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAMESPACE/user-svc:$VERSION . | |
| docker push $REGISTRY/$IMAGE_NAMESPACE/user-svc:$VERSION | |
| # ====================== | |
| # transaction-svc | |
| # ====================== | |
| - name: Build & Push transaction-svc | |
| run: | | |
| docker build \ | |
| -f transaction-svc/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAMESPACE/transaction-svc:$VERSION . | |
| docker push $REGISTRY/$IMAGE_NAMESPACE/transaction-svc:$VERSION | |
| # ====================== | |
| # notification-svc | |
| # ====================== | |
| - name: Build & Push notification-svc | |
| run: | | |
| docker build \ | |
| -f notification-svc/Dockerfile \ | |
| -t $REGISTRY/$IMAGE_NAMESPACE/notification-svc:$VERSION . | |
| docker push $REGISTRY/$IMAGE_NAMESPACE/notification-svc:$VERSION | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: build-and-push | |
| env: | |
| APP_VERSION: ${{ github.ref_name }} | |
| REGISTRY: ghcr.io | |
| IMAGE_NAMESPACE: hervibest | |
| steps: | |
| - name: Setup SSH agent | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: ${{ secrets.VPS_SSH_KEY }} | |
| - name: Deploy to VPS | |
| run: | | |
| ssh -o StrictHostKeyChecking=no \ | |
| ${{ secrets.VPS_USER }}@${{ secrets.VPS_HOST }} << EOF | |
| set -euo pipefail | |
| cd /home/ubuntu/app/be-yourmoments-backup | |
| grep -q "^APP_VERSION=" .env && \ | |
| sed -i "s|^APP_VERSION=.*|APP_VERSION=${APP_VERSION}|" .env || \ | |
| echo "APP_VERSION=${APP_VERSION}" >> .env | |
| echo "🔐 Login to GHCR" | |
| echo "${{ secrets.REGISTRY_PASSWORD }}" | \ | |
| docker login ${REGISTRY} \ | |
| -u hervibest \ | |
| --password-stdin | |
| echo "📦 Pull images" | |
| docker compose -f docker-compose-dev.yaml pull | |
| echo "🛑 Stop containers" | |
| docker compose -f docker-compose-dev.yaml down | |
| echo "🚀 Start containers" | |
| docker compose -f docker-compose-dev.yaml up -d | |
| echo "🧹 Cleanup images" | |
| docker image prune -f | |
| echo "✅ Deploy finished" | |
| EOF |