From 47b24263db52aff00d1d2e5936c2e8b10911e173 Mon Sep 17 00:00:00 2001 From: kentsanggds Date: Fri, 4 Aug 2023 18:55:06 +0100 Subject: [PATCH 1/2] Fix the branch name to create PR --- .github/workflows/create-pr-on-tags.yaml | 1 + docker/create-pr.sh | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/create-pr-on-tags.yaml b/.github/workflows/create-pr-on-tags.yaml index 930255de..ad23433d 100644 --- a/.github/workflows/create-pr-on-tags.yaml +++ b/.github/workflows/create-pr-on-tags.yaml @@ -1,6 +1,7 @@ name: Create charts PR on tags creation on: + workflow_dispatch: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' diff --git a/docker/create-pr.sh b/docker/create-pr.sh index bf412a7f..1ce2cdd6 100644 --- a/docker/create-pr.sh +++ b/docker/create-pr.sh @@ -9,7 +9,6 @@ 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 "govuk-ci@users.noreply.github.com" git config --global user.name "govuk-ci" @@ -17,10 +16,12 @@ 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" @@ -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 From bb5aa318038cb53570fee96d955508fbd8e9fa75 Mon Sep 17 00:00:00 2001 From: kentsanggds Date: Mon, 7 Aug 2023 11:32:59 +0100 Subject: [PATCH 2/2] Add build images with tags Also rename ghcr.yaml to build-image.yaml to make it clearer --- .github/workflows/build-image-on-tags.yaml | 42 +++++++++++++++++++ .../workflows/{ghcr.yaml => build-image.yaml} | 2 +- .github/workflows/create-pr-on-tags.yaml | 1 - docker/build-image.sh | 6 ++- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build-image-on-tags.yaml rename .github/workflows/{ghcr.yaml => build-image.yaml} (98%) diff --git a/.github/workflows/build-image-on-tags.yaml b/.github/workflows/build-image-on-tags.yaml new file mode 100644 index 00000000..db502ad3 --- /dev/null +++ b/.github/workflows/build-image-on-tags.yaml @@ -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 diff --git a/.github/workflows/ghcr.yaml b/.github/workflows/build-image.yaml similarity index 98% rename from .github/workflows/ghcr.yaml rename to .github/workflows/build-image.yaml index ce663170..5bdb8b08 100644 --- a/.github/workflows/ghcr.yaml +++ b/.github/workflows/build-image.yaml @@ -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: diff --git a/.github/workflows/create-pr-on-tags.yaml b/.github/workflows/create-pr-on-tags.yaml index ad23433d..930255de 100644 --- a/.github/workflows/create-pr-on-tags.yaml +++ b/.github/workflows/create-pr-on-tags.yaml @@ -1,7 +1,6 @@ name: Create charts PR on tags creation on: - workflow_dispatch: push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' diff --git a/docker/build-image.sh b/docker/build-image.sh index 65ed26ba..2ebac91f 100755 --- a/docker/build-image.sh +++ b/docker/build-image.sh @@ -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