|
| 1 | +name: Build and deploy |
| 2 | + |
| 3 | +concurrency: |
| 4 | + group: "${{ github.workflow }}-${{ github.ref }}-build-deploy" |
| 5 | + cancel-in-progress: true |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_call: |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + env: |
| 13 | + name: Generate environment variables |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + - name: Derive environment from git ref |
| 17 | + id: environment |
| 18 | + run: | |
| 19 | + if [ "${{ github.ref }}" = "refs/heads/main" ]; then |
| 20 | + ENVIRONMENT="production" |
| 21 | + APP_NAME_SUFFIX="" |
| 22 | + elif [ "${{ github.ref }}" = "refs/heads/develop" ]; then |
| 23 | + ENVIRONMENT="development" |
| 24 | + APP_NAME_SUFFIX="-development" |
| 25 | + elif [ "${{github.event_name}}" = "pull_request"]; then |
| 26 | + ENVIRONMENT="pr/${{ github.event.pull_request.number }}" |
| 27 | + APP_NAME_SUFFIX="-pr-${{ github.event.pull_request.number }}" |
| 28 | + else |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_OUTPUT |
| 33 | + echo "APP_NAME_SUFFIX=$APP_NAME_SUFFIX" >> $GITHUB_OUTPUT |
| 34 | + outputs: |
| 35 | + environment: "${{ steps.environment.outputs.ENVIRONMENT }}" |
| 36 | + app_name: "amc-website${{ steps.environment.outputs.APP_NAME_SUFFIX }}" |
| 37 | + registry: "ghcr.io" |
| 38 | + image: "${{ github.repository }}" |
| 39 | + |
| 40 | + vars: |
| 41 | + name: Generate public url |
| 42 | + needs: [env] |
| 43 | + runs-on: ubuntu-latest |
| 44 | + environment: |
| 45 | + name: "${{ needs.env.outputs.environment }}" |
| 46 | + steps: |
| 47 | + - name: Generate public URL |
| 48 | + id: public_url |
| 49 | + run: | |
| 50 | + if [ -z "${{ vars.PUBLIC_URL }}" ]; then |
| 51 | + PUBLIC_URL="https://${{ needs.env.outputs.app_name }}.${{ vars.KUBE_INGRESS_BASE_DOMAIN }}" |
| 52 | + else |
| 53 | + PUBLIC_URL="${{ vars.PUBLIC_URL }}" |
| 54 | + fi |
| 55 | +
|
| 56 | + echo "PUBLIC_URL=$PUBLIC_URL" >> $GITHUB_OUTPUT |
| 57 | + outputs: |
| 58 | + public_url: "${{ steps.public_url.outputs.PUBLIC_URL }}" |
| 59 | + |
| 60 | + build: |
| 61 | + name: Build and push docker image |
| 62 | + needs: [env, vars] |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: read |
| 66 | + packages: write |
| 67 | + |
| 68 | + steps: |
| 69 | + - name: Checkout repository |
| 70 | + uses: actions/checkout@v4 |
| 71 | + |
| 72 | + - name: Set up Docker Buildx |
| 73 | + uses: docker/setup-buildx-action@v3 |
| 74 | + |
| 75 | + - name: Log in to the Container registry |
| 76 | + uses: docker/login-action@v3 |
| 77 | + with: |
| 78 | + registry: "${{ needs.env.outputs.registry }}" |
| 79 | + username: "${{ github.actor }}" |
| 80 | + password: "${{ secrets.GITHUB_TOKEN }}" |
| 81 | + |
| 82 | + - name: Extract metadata (tags, labels) for Docker |
| 83 | + id: meta |
| 84 | + uses: docker/metadata-action@v5 |
| 85 | + with: |
| 86 | + images: "${{ needs.env.outputs.registry }}/${{ needs.env.outputs.image }}" |
| 87 | + tags: | |
| 88 | + type=raw,value={{sha}} |
| 89 | + type=ref,event=branch |
| 90 | + # type=ref,event=pr |
| 91 | + # type=semver,pattern={{version}} |
| 92 | + # type=semver,pattern={{major}}.{{minor}} |
| 93 | + # type=raw,value=latest |
| 94 | + |
| 95 | + - name: Build and push Docker image |
| 96 | + uses: docker/build-push-action@v5 |
| 97 | + with: |
| 98 | + context: . |
| 99 | + push: true |
| 100 | + tags: "${{ steps.meta.outputs.tags }}" |
| 101 | + labels: "${{ steps.meta.outputs.labels }}" |
| 102 | + build-args: | |
| 103 | + "PUBLIC_APP_BASE_URL=${{ needs.vars.outputs.public_url }}" |
| 104 | + "PUBLIC_BOTS=${{ vars.PUBLIC_BOTS }}" |
| 105 | + "PUBLIC_KEYSTATIC_GITHUB_APP_SLUG=${{ vars.PUBLIC_KEYSTATIC_GITHUB_APP_SLUG }}" |
| 106 | + "PUBLIC_KEYSTATIC_GITHUB_REPO_NAME=${{ vars.PUBLIC_KEYSTATIC_GITHUB_REPO_NAME }}" |
| 107 | + "PUBLIC_KEYSTATIC_GITHUB_REPO_OWNER=${{ vars.PUBLIC_KEYSTATIC_GITHUB_REPO_OWNER }}" |
| 108 | + "PUBLIC_KEYSTATIC_MODE=${{ vars.PUBLIC_KEYSTATIC_MODE }}" |
| 109 | + "PUBLIC_MATOMO_BASE_URL=${{ vars.PUBLIC_MATOMO_BASE_URL }}" |
| 110 | + "PUBLIC_MATOMO_ID=${{ vars.PUBLIC_MATOMO_ID }}" |
| 111 | + "PUBLIC_REDMINE_ID=${{ vars.SERVICE_ID }}" |
| 112 | + secrets: | |
| 113 | + "KEYSTATIC_GITHUB_CLIENT_ID=${{ secrets.K8S_SECRET_KEYSTATIC_GITHUB_CLIENT_ID }}" |
| 114 | + "KEYSTATIC_GITHUB_CLIENT_SECRET=${{ secrets.K8S_SECRET_KEYSTATIC_GITHUB_CLIENT_SECRET }}" |
| 115 | + "KEYSTATIC_SECRET=${{ secrets.K8S_SECRET_KEYSTATIC_SECRET }}" |
| 116 | + cache-from: type=gha |
| 117 | + cache-to: type=gha,mode=max |
| 118 | + |
| 119 | + deploy: |
| 120 | + name: Deploy docker image |
| 121 | + needs: [env, vars, build] |
| 122 | + uses: acdh-oeaw/gl-autodevops-minimal-port/.github/workflows/deploy.yml@main |
| 123 | + secrets: inherit |
| 124 | + with: |
| 125 | + environment: "${{ needs.env.outputs.environment }}" |
| 126 | + DOCKER_TAG: "${{ needs.env.outputs.registry }}/${{ needs.env.outputs.image }}" |
| 127 | + APP_NAME: "${{ needs.env.outputs.app_name }}" |
| 128 | + APP_ROOT: "/" |
| 129 | + SERVICE_ID: "${{ vars.SERVICE_ID }}" |
| 130 | + PUBLIC_URL: "${{ needs.vars.outputs.public_url }}" |
| 131 | + default_port: "3000" |
0 commit comments