From 57b40559b9f5a6fcbee4221dbe9c7a11bf22f176 Mon Sep 17 00:00:00 2001 From: Henri Date: Tue, 29 Oct 2024 12:22:11 +0100 Subject: [PATCH] Add missing env vars and workflows --- .github/workflows/deploy-app-ionos.yml | 18 +++++------- .github/workflows/deploy-app-staging.yml | 26 +++++++++++++---- .github/workflows/restart-services.yml | 37 ++++++++++++++++++++++++ .github/workflows/setup-env.yml | 1 + 4 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/restart-services.yml diff --git a/.github/workflows/deploy-app-ionos.yml b/.github/workflows/deploy-app-ionos.yml index e99b650b..fc96c1c0 100644 --- a/.github/workflows/deploy-app-ionos.yml +++ b/.github/workflows/deploy-app-ionos.yml @@ -11,13 +11,13 @@ on: NEXT_PUBLIC_APP_ENV: required: true type: string - NEXT_PUBLIC_OSM_API_URL: + APP_ORIGIN: required: true type: string - APP_URL: + ASSETS_BUCKET_HOST: required: true - type: string - CONFIG_CHANGED: + type: boolean + ASSETS_BUCKET_PATH: required: true type: boolean @@ -68,7 +68,6 @@ jobs: build-args: | NEXT_PUBLIC_APP_ENV=${{ inputs.NEXT_PUBLIC_APP_ENV }} NEXT_PUBLIC_APP_ORIGIN=${{ inputs.NEXT_PUBLIC_APP_ORIGIN }} - NEXT_PUBLIC_OSM_API_URL=${{ inputs.NEXT_PUBLIC_OSM_API_URL }} - name: Push nginx image run: | @@ -88,9 +87,8 @@ jobs: public.ecr.aws/n0p8j4k5/trassenscout/nginx:${{ github.sha }} public.ecr.aws/n0p8j4k5/trassenscout/nginx:${{ inputs.ENVIRONMENT }}-latest build-args: | - NEXT_PUBLIC_APP_ENV=${{ inputs.NEXT_PUBLIC_APP_ENV }} - NEXT_PUBLIC_APP_ORIGIN=${{ inputs.NEXT_PUBLIC_APP_ORIGIN }} - NEXT_PUBLIC_OSM_API_URL=${{ inputs.NEXT_PUBLIC_OSM_API_URL }} + ASSETS_BUCKET_HOST=${{ inputs.ASSETS_BUCKET_HOST }} + ASSETS_BUCKET_PATH=${{ inputs.ASSETS_BUCKET_PATH }} - name: Push image run: | @@ -102,7 +100,7 @@ jobs: if: ${{ needs.diff_app.outputs.changes == 'true' || inputs.CONFIG_CHANGED && always() }} environment: name: ${{ inputs.ENVIRONMENT }} - url: https://${{ inputs.APP_URL }} + url: ${{ inputs.APP_ORIGIN }} steps: - name: Stop & Start container on Server uses: appleboy/ssh-action@master @@ -111,7 +109,7 @@ jobs: username: ${{ secrets.SSH_USERNAME }} password: ${{ secrets.SSH_PASSWORD }} script: | - cd /srv + cd /srv/trassenscout-${{ inputs.ENVIRONMENT }} echo "Pulling latest 'app' image" docker compose pull app echo "Restarting 'app' container" diff --git a/.github/workflows/deploy-app-staging.yml b/.github/workflows/deploy-app-staging.yml index 6a960490..9f2dc441 100644 --- a/.github/workflows/deploy-app-staging.yml +++ b/.github/workflows/deploy-app-staging.yml @@ -4,29 +4,45 @@ on: branches: - migration-ionos jobs: + setup_env: + uses: ./.github/workflows/setup-env.yml + with: + ENVIRONMENT: staging + TILES_URL: staging-tiles.radverkehrsatlas.de + CACHELESS_URL: staging-cacheless.radverkehrsatlas.de + NEXT_PUBLIC_APP_ORIGIN: https://staging.radverkehrsatlas.de + NEXT_PUBLIC_APP_ENV: staging + NEXT_PUBLIC_OSM_API_URL: https://master.apis.dev.openstreetmap.org/api/0.6 + APP_URL: staging.radverkehrsatlas.de + secrets: inherit + restart_services: + uses: ./.github/workflows/restart-services.yml + needs: setup_env + with: + ENVIRONMENT: staging + secrets: inherit call-deploy-app: + needs: restart_services uses: ./.github/workflows/deploy-app-ionos.yml with: + ENVIRONMENT: staging APP_ORIGIN: http://staging.trassenscout.de NEXT_PUBLIC_APP_ORIGIN: http://staging.trassenscout.de NEXT_PUBLIC_APP_ENV: staging - SERVICE_NAME: trassenscout-staging S3_UPLOAD_BUCKET: trassenscout S3_UPLOAD_REGION: eu-central-1 S3_UPLOAD_ROOTFOLDER: upload-staging - ENVIRONMENT: staging - URL: staging.trassenscout.de secrets: AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} DATABASE_URL: ${{ secrets.DATABASE_URL }} SESSION_SECRET_KEY: ${{ secrets.SESSION_SECRET_KEY}} - NGINX_HTPASSWD: ${{ secrets.NGINX_HTPASSWD }} MAILJET_APIKEY_PUBLIC: ${{ secrets.MAILJET_APIKEY_PUBLIC }} MAILJET_APIKEY_PRIVATE: ${{ secrets.MAILJET_APIKEY_PRIVATE }} + NGINX_HTPASSWD: ${{ secrets.NGINX_HTPASSWD }} S3_UPLOAD_KEY: ${{ secrets.S3_UPLOAD_KEY }} - FELT_TOKEN: ${{ secrets.FELT_TOKEN }} S3_UPLOAD_SECRET: ${{ secrets.S3_UPLOAD_SECRET }} + FELT_TOKEN: ${{ secrets.FELT_TOKEN }} ASSETS_BUCKET_HOST: ${{ secrets.ASSETS_BUCKET_HOST }} ASSETS_BUCKET_PATH: ${{ secrets.ASSETS_BUCKET_PATH }} ADMIN_EMAIL: ${{ secrets.ADMIN_EMAIL }} diff --git a/.github/workflows/restart-services.yml b/.github/workflows/restart-services.yml new file mode 100644 index 00000000..44ae5409 --- /dev/null +++ b/.github/workflows/restart-services.yml @@ -0,0 +1,37 @@ +name: Restart Services + +on: + workflow_call: + inputs: + ENVIRONMENT: + type: string + required: true + outputs: + CHANGES: + description: "Whether `configs/` or the `docker-compose` files have changed since the last successfull workflow run." + value: ${{ jobs.check_config_changes.outputs.CHANGES }} + +jobs: + check_config_changes: + uses: ./.github/workflows/diff-last-run.yml + with: + CHECK_DIFF_LOCATIONS: docker-compose* .env.example + restart_services: + needs: check_config_changes + if: ${{ needs.check_config_changes.outputs.changes == 'true' }} + runs-on: ubuntu-latest + environment: + name: ${{ inputs.ENVIRONMENT }} + steps: + - name: Restart containers + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.SSH_HOST }} + username: ${{ secrets.SSH_USERNAME }} + password: ${{ secrets.SSH_PASSWORD }} + script: | + cd /srv/trassenscout-${{ inputs.ENVIRONMENT }} + echo "Restarting containers: tiles, db, traefik and proxy" + docker compose pull + docker compose -f docker-compose.yml up db traefik app nginx -d + docker image prune -fa diff --git a/.github/workflows/setup-env.yml b/.github/workflows/setup-env.yml index 7954c1bd..ec463c9d 100644 --- a/.github/workflows/setup-env.yml +++ b/.github/workflows/setup-env.yml @@ -71,5 +71,6 @@ jobs: -e "s|^S3_UPLOAD_KEY=.*$|S3_UPLOAD_KEY='${{ secrets.S3_UPLOAD_KEY }}'|" \ -e "s|^S3_UPLOAD_SECRET=.*$|S3_UPLOAD_SECRET='${{ secrets.S3_UPLOAD_SECRET }}'|" \ -e "s|^S3_UPLOAD_ROOTFOLDER=.*$|S3_UPLOAD_ROOTFOLDER='${{ vars.S3_UPLOAD_ROOTFOLDER }}'|" \ + -e "s|^APP_URL=.*$|APP_URL='${{ vars.APP_URL }}'|" \ -e "s|^TS_API_KEY=.*$|TS_API_KEY='${{ secrets.TS_API_KEY }}'|" \ .env