|
| 1 | +# Build and publish BOPS container images to ghcr.io |
| 2 | +# |
| 3 | +# Builds two images in parallel: |
| 4 | +# - ghcr.io/co-cddo/ndx_try_aws_scenarios-bops:latest (back-office + worker) |
| 5 | +# - ghcr.io/co-cddo/ndx_try_aws_scenarios-bops-applicants:latest (public portal) |
| 6 | +# |
| 7 | +# Both clone their upstream repos at pinned commits, apply our overlay files, |
| 8 | +# and build using the upstream Dockerfile.production. |
| 9 | + |
| 10 | +name: Build BOPS Container Images |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + branches: [main, feat/bops-planning] |
| 15 | + paths: |
| 16 | + - 'cloudformation/scenarios/bops-planning/docker/**' |
| 17 | + - '.github/workflows/docker-build-bops.yml' |
| 18 | + pull_request: |
| 19 | + paths: |
| 20 | + - 'cloudformation/scenarios/bops-planning/docker/**' |
| 21 | + - '.github/workflows/docker-build-bops.yml' |
| 22 | + workflow_dispatch: |
| 23 | + inputs: |
| 24 | + push_image: |
| 25 | + description: 'Push images to registry' |
| 26 | + required: false |
| 27 | + default: true |
| 28 | + type: boolean |
| 29 | + |
| 30 | +env: |
| 31 | + REGISTRY: ghcr.io |
| 32 | + # Pin to specific commits for reproducibility — update these when upgrading BOPS |
| 33 | + BOPS_REPO: unboxed/bops |
| 34 | + BOPS_COMMIT: main |
| 35 | + BOPS_APPLICANTS_REPO: unboxed/bops-applicants |
| 36 | + BOPS_APPLICANTS_COMMIT: main |
| 37 | + |
| 38 | +jobs: |
| 39 | + changes: |
| 40 | + name: Check for Docker changes |
| 41 | + runs-on: ubuntu-latest |
| 42 | + if: github.event_name == 'pull_request' |
| 43 | + outputs: |
| 44 | + docker: ${{ steps.filter.outputs.docker }} |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v6 |
| 47 | + - uses: dorny/paths-filter@v3 |
| 48 | + id: filter |
| 49 | + with: |
| 50 | + filters: | |
| 51 | + docker: |
| 52 | + - 'cloudformation/scenarios/bops-planning/docker/**' |
| 53 | + - '.github/workflows/docker-build-bops.yml' |
| 54 | +
|
| 55 | + build-bops: |
| 56 | + name: Build BOPS Back-Office |
| 57 | + runs-on: ubuntu-latest |
| 58 | + needs: [changes] |
| 59 | + if: | |
| 60 | + always() && |
| 61 | + (needs.changes.result == 'skipped' || needs.changes.outputs.docker == 'true') |
| 62 | + permissions: |
| 63 | + contents: read |
| 64 | + packages: write |
| 65 | + |
| 66 | + steps: |
| 67 | + - name: Checkout repository |
| 68 | + uses: actions/checkout@v6 |
| 69 | + |
| 70 | + - name: Clone BOPS source |
| 71 | + run: | |
| 72 | + git clone --depth 1 https://github.com/${{ env.BOPS_REPO }}.git bops-src |
| 73 | + if [ "${{ env.BOPS_COMMIT }}" != "main" ]; then |
| 74 | + cd bops-src |
| 75 | + git fetch --depth 1 origin ${{ env.BOPS_COMMIT }} |
| 76 | + git checkout ${{ env.BOPS_COMMIT }} |
| 77 | + cd .. |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Copy overlay files |
| 81 | + run: | |
| 82 | + mkdir -p bops-src/scripts |
| 83 | + cp cloudformation/scenarios/bops-planning/docker/bops/config/initializers/default_local_authority.rb bops-src/config/initializers/ |
| 84 | + cp cloudformation/scenarios/bops-planning/docker/bops/scripts/seed_sample_data.rb bops-src/scripts/ |
| 85 | + cp cloudformation/scenarios/bops-planning/docker/bops/scripts/seed-entrypoint.sh bops-src/scripts/ |
| 86 | + cp cloudformation/scenarios/bops-planning/docker/bops/scripts/init-bops.sh bops-src/scripts/ |
| 87 | + cp cloudformation/scenarios/bops-planning/docker/bops/entrypoint.sh bops-src/ |
| 88 | +
|
| 89 | + - name: Set up Docker Buildx |
| 90 | + uses: docker/setup-buildx-action@v3 |
| 91 | + |
| 92 | + - name: Log in to GitHub Container Registry |
| 93 | + uses: docker/login-action@v3 |
| 94 | + with: |
| 95 | + registry: ${{ env.REGISTRY }} |
| 96 | + username: ${{ github.actor }} |
| 97 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 98 | + |
| 99 | + - name: Extract metadata |
| 100 | + id: meta |
| 101 | + uses: docker/metadata-action@v5 |
| 102 | + with: |
| 103 | + images: ${{ env.REGISTRY }}/co-cddo/ndx_try_aws_scenarios-bops |
| 104 | + tags: | |
| 105 | + type=sha,prefix=sha- |
| 106 | + type=raw,value=latest,enable={{is_default_branch}} |
| 107 | + type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }} |
| 108 | +
|
| 109 | + - name: Build and push BOPS image |
| 110 | + uses: docker/build-push-action@v6 |
| 111 | + with: |
| 112 | + context: bops-src |
| 113 | + file: bops-src/Dockerfile.production |
| 114 | + push: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feat/bops-planning' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image != 'false')) }} |
| 115 | + tags: ${{ steps.meta.outputs.tags }} |
| 116 | + labels: ${{ steps.meta.outputs.labels }} |
| 117 | + cache-from: type=gha,scope=bops |
| 118 | + cache-to: type=gha,mode=max,scope=bops |
| 119 | + platforms: linux/amd64 |
| 120 | + |
| 121 | + - name: Output image details |
| 122 | + run: | |
| 123 | + echo "## BOPS Image Built" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "**Tags:**" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 128 | +
|
| 129 | + build-bops-applicants: |
| 130 | + name: Build BOPS Applicants Portal |
| 131 | + runs-on: ubuntu-latest |
| 132 | + needs: [changes] |
| 133 | + if: | |
| 134 | + always() && |
| 135 | + (needs.changes.result == 'skipped' || needs.changes.outputs.docker == 'true') |
| 136 | + permissions: |
| 137 | + contents: read |
| 138 | + packages: write |
| 139 | + |
| 140 | + steps: |
| 141 | + - name: Checkout repository |
| 142 | + uses: actions/checkout@v6 |
| 143 | + |
| 144 | + - name: Clone BOPS-Applicants source |
| 145 | + run: | |
| 146 | + git clone --depth 1 https://github.com/${{ env.BOPS_APPLICANTS_REPO }}.git bops-applicants-src |
| 147 | + if [ "${{ env.BOPS_APPLICANTS_COMMIT }}" != "main" ]; then |
| 148 | + cd bops-applicants-src |
| 149 | + git fetch --depth 1 origin ${{ env.BOPS_APPLICANTS_COMMIT }} |
| 150 | + git checkout ${{ env.BOPS_APPLICANTS_COMMIT }} |
| 151 | + cd .. |
| 152 | + fi |
| 153 | +
|
| 154 | + - name: Copy overlay files |
| 155 | + run: | |
| 156 | + cp cloudformation/scenarios/bops-planning/docker/bops-applicants/config/initializers/default_local_authority.rb bops-applicants-src/config/initializers/ |
| 157 | +
|
| 158 | + - name: Set up Docker Buildx |
| 159 | + uses: docker/setup-buildx-action@v3 |
| 160 | + |
| 161 | + - name: Log in to GitHub Container Registry |
| 162 | + uses: docker/login-action@v3 |
| 163 | + with: |
| 164 | + registry: ${{ env.REGISTRY }} |
| 165 | + username: ${{ github.actor }} |
| 166 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 167 | + |
| 168 | + - name: Extract metadata |
| 169 | + id: meta |
| 170 | + uses: docker/metadata-action@v5 |
| 171 | + with: |
| 172 | + images: ${{ env.REGISTRY }}/co-cddo/ndx_try_aws_scenarios-bops-applicants |
| 173 | + tags: | |
| 174 | + type=sha,prefix=sha- |
| 175 | + type=raw,value=latest,enable={{is_default_branch}} |
| 176 | + type=ref,event=branch,enable=${{ github.ref != 'refs/heads/main' }} |
| 177 | +
|
| 178 | + - name: Build and push BOPS-Applicants image |
| 179 | + uses: docker/build-push-action@v6 |
| 180 | + with: |
| 181 | + context: bops-applicants-src |
| 182 | + file: bops-applicants-src/Dockerfile.production |
| 183 | + push: ${{ (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/feat/bops-planning' || (github.event_name == 'workflow_dispatch' && github.event.inputs.push_image != 'false')) }} |
| 184 | + tags: ${{ steps.meta.outputs.tags }} |
| 185 | + labels: ${{ steps.meta.outputs.labels }} |
| 186 | + cache-from: type=gha,scope=bops-applicants |
| 187 | + cache-to: type=gha,mode=max,scope=bops-applicants |
| 188 | + platforms: linux/amd64 |
| 189 | + |
| 190 | + - name: Output image details |
| 191 | + run: | |
| 192 | + echo "## BOPS-Applicants Image Built" >> $GITHUB_STEP_SUMMARY |
| 193 | + echo "**Tags:**" >> $GITHUB_STEP_SUMMARY |
| 194 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 195 | + echo "${{ steps.meta.outputs.tags }}" >> $GITHUB_STEP_SUMMARY |
| 196 | + echo '```' >> $GITHUB_STEP_SUMMARY |
0 commit comments