Skip to content

Commit

Permalink
Merge pull request #1442 from alphagov/fix-create_pr-add-build-image-…
Browse files Browse the repository at this point in the history
…tags

Fix create pr add build image tags
  • Loading branch information
kentsanggds authored Aug 8, 2023
2 parents f4bdc9a + bb5aa31 commit de8ea04
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 5 deletions.
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
7 changes: 4 additions & 3 deletions docker/create-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ 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 +30,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

0 comments on commit de8ea04

Please sign in to comment.