Update docker-compose.stag.yml #15
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: Deploy to TDT4242 server | |
| on: | |
| push: | |
| branches: | |
| - dev | |
| - stage | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| config: | |
| description: "Which compose config file to deploy" | |
| required: true | |
| default: "docker-compose.dev.yml" | |
| type: choice | |
| options: | |
| - "docker-compose.dev.yml" | |
| - "docker-compose.stag.yml" | |
| - "docker-compose.yml" | |
| jobs: | |
| deploy: | |
| runs-on: self-hosted | |
| env: | |
| REPO_NAME: ${{ github.event.repository.name }} | |
| COMPOSE_FILE: >- | |
| ${{ github.event.inputs.config || | |
| (github.ref == 'refs/heads/dev' && 'docker-compose.dev.yml') || | |
| (github.ref == 'refs/heads/stage' && 'docker-compose.stag.yml') || | |
| (github.ref == 'refs/heads/main' && 'docker-compose.yml') | |
| }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| # Debug step to verify repository structure on the runner | |
| - name: List repository structure | |
| run: | | |
| echo "Listing repository structure:" | |
| find . -maxdepth=2 | sort | |
| - name: Dotenv Action | |
| uses: falti/dotenv-action@v1.1.4 | |
| with: | |
| export-variables: true | |
| keys-case: bypass | |
| - name: Check status of config file | |
| run: | | |
| echo "Using compose file: $COMPOSE_FILE" | |
| sudo docker compose version | |
| cd $GITHUB_WORKSPACE | |
| sudo docker compose -f $COMPOSE_FILE config && echo "Compose file is valid" || exit 1 | |
| - name: Build and run docker image | |
| run: | | |
| echo "Deploying with compose file: $COMPOSE_FILE" | |
| sudo docker compose -f $COMPOSE_FILE up --force-recreate --build -d | |
| - name: Verify deployment for Dev | |
| if: github.ref == 'refs/heads/dev' | |
| run: | | |
| echo "Verifying DEV deployment..." | |
| curl -f http://localhost:${DEV_PORT_PREFIX}4/api/health || (echo "DEV backend is down!" && sudo docker logs secfit_dev_backend && exit 1) | |
| curl -f http://localhost:${DEV_PORT_PREFIX}5 || (echo "DEV frontend is down!" && sudo docker logs secfit_dev_frontend && exit 1) | |
| curl -f http://localhost:${DEV_PORT_PREFIX}6 || (echo "DEV gateway is down!" && sudo docker logs secfit_dev_gateway && exit 1) | |
| - name: Verify deployment for Staging | |
| if: github.ref == 'refs/heads/stage' | |
| run: | | |
| echo "Verifying STAGING deployment..." | |
| curl -f http://localhost:${STAG_PORT_PREFIX}4/api/health || (echo "STAGING backend is down!" && sudo docker logs secfit_stag_backend && exit 1) | |
| - name: Verify deployment for Production | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| echo "Verifying PRODUCTION deployment..." | |
| # In production, only the gateway is exposed. | |
| curl -f http://localhost:${PROD_PORT_PREFIX}6 || (echo "PRODUCTION gateway is down!" && sudo docker logs secfit_prod_gateway && exit 1) | |
| - name: Verify that gateway is available | |
| run: sudo docker ps |