name: Automatic Deployment on: push: branches: - dev concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: environment: name: ๐ŸŒ Setup Environment runs-on: [self-hosted] outputs: target: ${{ steps.dev.outputs.target || steps.staging.outputs.target }} steps: - name: Verify NPM Token env: # We map the secret here to check its existence NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | if [ -z "$NPM_TOKEN" ]; then echo "::error::The NPM_TOKEN secret is missing or empty. Please add it to your GitHub Secrets." exit 1 fi echo "NPM_TOKEN is present, proceeding with build..." - name: ๐Ÿ› ๏ธ Set Development Environment id: dev if: ${{github.ref_name == 'dev'}} run: | echo "target=dev" >> $GITHUB_OUTPUT - name: ๐Ÿš€ Set Staging Environment id: staging if: ${{github.ref_name == 'staging'}} run: | echo "target=staging" >> $GITHUB_OUTPUT build-base-image: name: ๐Ÿ—๏ธ Build Base Image runs-on: [self-hosted, dev] needs: [environment] steps: - name: ๐Ÿ” Checkout uses: actions/checkout@v4 - name: ๐Ÿณ Build Docker Image env: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | set -euo pipefail # Create the multi-line file cat < .npmrc_temp @tria-plc:registry=https://npm.pkg.github.com //npm.pkg.github.com/:_authToken=${NPM_TOKEN} always-auth=true EOF # Build using the file docker build --secret id=npmrc,src=.npmrc_temp -t edr-${{needs.environment.outputs.target}} . docker build --secret id=npmrc,src=.npmrc_temp --target passenger-migration -t edr-passenger-migration-${{needs.environment.outputs.target}} . # Shred/Remove the sensitive file rm .npmrc_temp deploy-service: name: ${{ matrix.display_name }} runs-on: [self-hosted, dev] needs: [build-base-image, environment] strategy: fail-fast: false matrix: include: - service: freight-api env_file: .env.freight-api display_name: ๐Ÿšš Deploy Freight API Service - service: passenger-api env_file: .env.passenger-api display_name: ๐Ÿง‘โ€๐Ÿฆฒ Deploy Passenger API Service steps: - name: ๐Ÿ” Checkout uses: actions/checkout@v4 - name: ๐Ÿ“‹ Copy ${{ matrix.service }} Environment run: cp ~/environment/edr/${{needs.environment.outputs.target}}/${{ matrix.env_file }} .env - name: ๐Ÿงช Run Passenger API migrations if: ${{ matrix.service == 'passenger-api' }} run: | docker run --rm --env-file .env edr-passenger-migration-${{needs.environment.outputs.target}} - name: ๐Ÿš€ Start ${{ matrix.service }} Service run: docker compose --project-name="edr-${{needs.environment.outputs.target}}" up -d --force-recreate ${{ matrix.service }} --build