Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the branch name to create and the directory updating the image tags #1440

Closed
wants to merge 12 commits into from
42 changes: 42 additions & 0 deletions .github/workflows/build-image-on-tags.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and push images

on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
build_and_push:
name: ${{ matrix.app.name }} (${{ matrix.arch }})
runs-on: ubuntu-latest
strategy:
matrix:
app:
- name: ckan
version: 2.9.9
- name: pycsw
version: 2.6.1
- name: postgis
version: 13-3.1
- name: solr
version: 8
arch: [ amd64 ]
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@v3
with:
ref: ${{ inputs.gitRef }}
- name: Build and push images
env:
APP: ${{ matrix.app.name }}
VERSION: ${{ matrix.app.version }}
ARCH: ${{ matrix.arch }}
GH_REF: ${{ github.ref_name }}
run: ./docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ on:
jobs:
build_and_push:
name: ${{ matrix.app.name }} (${{ matrix.arch }})
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
strategy:
matrix:
app:
Expand Down
6 changes: 5 additions & 1 deletion docker/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ if [[ ${BUILD_BASE:-} = "true" ]]; then
DOCKER_TAG="${VERSION}"
fi
else
DOCKER_TAG="${GITHUB_SHA}"
if [[ -n ${GH)REF:-} ]]; then
DOCKER_TAG="${GH_REF}"
else
DOCKER_TAG="${GITHUB_SHA}"
fi
fi

if [[ -n ${DOCKER_TAG:-} ]]; then
Expand Down
11 changes: 8 additions & 3 deletions docker/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@

set -eux

GH_REF=test-2
ENVS=staging,production
IS_TAG=true

if [[ ${IS_TAG:-} = "true" ]]; then
export IMAGE_TAG="${GH_REF}"
export SOURCE_BRANCH="main"
else
export IMAGE_TAG=$(gh api repos/alphagov/ckanext-datagovuk/branches/${GH_REF} | jq .commit.sha -r)
export SOURCE_BRANCH=${GH_REF}
fi
BRANCH="ci/${IMAGE_TAG}"

git config --global user.email "[email protected]"
git config --global user.name "govuk-ci"

git clone https://${GH_TOKEN}@github.com/alphagov/govuk-ckan-charts.git charts

cd charts/charts/ckan/images
git checkout -b ${BRANCH}

for ENV in $(echo $ENVS | tr "," " "); do
(
BRANCH="ci/${IMAGE_TAG}-${ENV}"
git checkout -b ${BRANCH}

cd "${ENV}"
for APP in ckan pycsw solr; do
yq -i '.tag = env(IMAGE_TAG)' "${APP}.yaml"
Expand All @@ -29,6 +34,6 @@ for ENV in $(echo $ENVS | tr "," " "); do
done
git commit -m "Update image tags for ${ENV} to ${IMAGE_TAG}"
git push --set-upstream origin "${BRANCH}"
gh pr create --title "Update image tags for ${ENV} (${IMAGE_TAG})" --base main --head "${BRANCH}-${ENV}" --fill
gh pr create --title "Update image tags for ${ENV} (${IMAGE_TAG})" --base main --head "${BRANCH}" --fill
)
done
Loading