Repository navigation
Merge pull request #86 from Team-Meal/feature/allow-nutritionist-dire… #39
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: CD | |
| on: | |
| push: | |
| branches: [ main, develop ] | |
| tags: [ 'v*.*.*' ] | |
| env: | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: ${{ github.repository }} | |
| jobs: | |
| docker: | |
| name: Build & Push Image | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
| tags: | | |
| type=ref,event=branch | |
| type=semver,pattern={{version}} | |
| type=sha,format=short | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| - name: Notify Discord | |
| if: always() | |
| uses: sarisia/actions-status-discord@v1 | |
| with: | |
| webhook: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| status: ${{ job.status }} | |
| title: "CD - Docker Build & Push" | |
| deploy: | |
| name: Deploy to on-prem server | |
| needs: docker | |
| runs-on: self-hosted | |
| if: github.ref == 'refs/heads/main' | |
| permissions: | |
| contents: read | |
| packages: read | |
| concurrency: | |
| group: production-deploy | |
| cancel-in-progress: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set image name | |
| id: img | |
| run: echo "image=ghcr.io/$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]'):main" >> "$GITHUB_OUTPUT" | |
| - name: Check .env exists | |
| id: check_env | |
| run: | | |
| if [ -f /opt/hololog/.env ]; then | |
| echo "ready=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "ready=false" >> "$GITHUB_OUTPUT" | |
| echo "::warning::/opt/hololog/.env not found — skipping deploy. Create the file to enable deployment." | |
| fi | |
| - name: Copy .env from server | |
| if: steps.check_env.outputs.ready == 'true' | |
| run: cp /opt/hololog/.env .env | |
| - name: Pull latest image | |
| if: steps.check_env.outputs.ready == 'true' | |
| run: APP_IMAGE=${{ steps.img.outputs.image }} docker compose --env-file /opt/hololog/.env -f docker-compose.prod.yml pull app | |
| - name: Deploy | |
| if: steps.check_env.outputs.ready == 'true' | |
| run: APP_IMAGE=${{ steps.img.outputs.image }} docker compose --env-file /opt/hololog/.env -f docker-compose.prod.yml up -d | |
| - name: Verify deployment | |
| if: steps.check_env.outputs.ready == 'true' | |
| run: | | |
| sleep 30 | |
| echo "=== Container status ===" | |
| docker compose -f docker-compose.prod.yml ps | |
| docker compose -f docker-compose.prod.yml ps | grep "app" | grep -qiE "(Up|running)" || { | |
| echo "=== App container logs ===" | |
| docker compose -f docker-compose.prod.yml logs app --tail=50 | |
| exit 1 | |
| } | |
| - name: Clean up unused images | |
| if: steps.check_env.outputs.ready == 'true' | |
| run: docker image prune -f | |
| - name: Notify Discord | |
| if: always() | |
| uses: sarisia/actions-status-discord@v1 | |
| with: | |
| webhook: ${{ secrets.DISCORD_WEBHOOK_URL }} | |
| status: ${{ job.status }} | |
| title: "CD - Deploy" |