-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1208 from alphagov/add-build-image-files
Add build image files
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Build and push images | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
buildType: | ||
description: Decide on build type | ||
required: true | ||
type: choice | ||
options: | ||
- build_push | ||
- build_only | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build_and_push: | ||
name: datagovuk_publish | ||
runs-on: ubuntu-latest | ||
permissions: | ||
packages: write | ||
steps: | ||
- name: Login to GHCR | ||
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ inputs.gitRef }} | ||
- name: Build images (without pushing to registry) | ||
if: ${{ inputs.buildType == 'build_only' }} | ||
env: | ||
DRY_RUN: "1" | ||
APP: datagovuk_publish | ||
ARCH: amd64 | ||
run: ./docker/build-image.sh | ||
- name: Build and push images | ||
if: ${{ inputs.buildType == 'build_push' || github.ref == 'refs/heads/main' }} | ||
env: | ||
APP: datagovuk_publish | ||
ARCH: amd64 | ||
run: ./docker/build-image.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM ruby:2.7.5 | ||
FROM ruby:3.2.2 | ||
|
||
WORKDIR /srv/app/datagovuk_publish | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
|
||
set -eux | ||
|
||
build () { | ||
if [ "${ARCH}" = "amd64" ]; then | ||
docker build . -t "ghcr.io/alphagov/${APP}:${1}" -f "docker/Dockerfile" | ||
else | ||
docker buildx build --platform "linux/${ARCH}" . -t "ghcr.io/alphagov/${APP}:${1}" -f "docker/Dockerfile" | ||
fi | ||
} | ||
|
||
DOCKER_TAG="${GITHUB_SHA}" | ||
|
||
build "${DOCKER_TAG}" | ||
|
||
if [[ -n ${DRY_RUN:-} ]]; then | ||
echo "Dry run; not pushing to registry" | ||
else | ||
docker push "ghcr.io/alphagov/${APP}:${DOCKER_TAG}" | ||
fi |