Skip to content

Commit f73d9aa

Browse files
committed
👷 Push images to quay
1 parent db0d540 commit f73d9aa

File tree

2 files changed

+60
-16
lines changed

2 files changed

+60
-16
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ defaults:
1919
run:
2020
shell: bash
2121

22-
env:
23-
CI: true
24-
DOCKER_BUILDKIT: 1
25-
2622
jobs:
2723
build:
2824
runs-on: ubuntu-latest
2925
env:
30-
BUILDKIT_INLINE_CACHE: 1
26+
CACHE_IMAGE: "ghcr.io/ibm/text-gen-router:build-cache"
27+
CACHE_REGISTRY: "ghcr.io"
28+
QUAY_REPOSITORY: "quay.io/wxpe/text-gen-router"
29+
3130
permissions:
3231
packages: write
3332
contents: read
@@ -46,9 +45,44 @@ jobs:
4645
username: ${{ github.actor }}
4746
password: ${{ secrets.GITHUB_TOKEN }}
4847

49-
- name: "Docker build"
50-
run: make build-router
48+
- name: "Log in to quay"
49+
uses: docker/login-action@v3
50+
with:
51+
registry: quay.io
52+
username: wxpe+github_pusher_bot
53+
password: ${{ secrets.WXPE_QUAY_TOKEN }}
5154

52-
- name: "Docker push"
53-
if: github.ref == 'refs/heads/main'
54-
run: make push-router-image
55+
- name: "Set build cache target"
56+
run: |
57+
# For push to `main` (PR merged), push a new cache image with all layers (cache-mode=max).
58+
# For PR builds, use GitHub action cache which isolates cached layers by PR/branch.
59+
# to optimize builds for subsequent pushes to the same PR/branch.
60+
# Do not set a cache-to image for PR builds to not overwrite the `main` cache image and
61+
# to not ping-pong cache images for two or more different PRs.
62+
# Do not push cache images for each PR or multiple branches to not exceed GitHub package
63+
# usage and traffic limitations.
64+
# UPDATE 2024/02/26: GHA cache appears to have issues, cannot use `cache-to: gha,mode=min`
65+
# if `cache-from: reg...,mode=max` but `cache-to: gha,mode=max` takes longer than uncached
66+
# build and exhausts GHA cache size limits, so use cache `type=inline` (no external cache).
67+
if [ "${{ github.event_name }}" == "pull_request" ]
68+
then
69+
#CACHE_TO="type=gha,mode=min"
70+
CACHE_TO="type=inline"
71+
else
72+
CACHE_TO="type=registry,ref=${{ env.CACHE_IMAGE }},mode=max"
73+
fi
74+
echo "CACHE_TO=$CACHE_TO" >> $GITHUB_ENV
75+
76+
- name: "push tags"
77+
run: echo "PUSH_TAGS=$(scripts/get_image_tags.sh ${QUAY_REPOSITORY} | tr -s '[:blank:]' ',')" >> $GITHUB_ENV
78+
79+
- name: "Build and push"
80+
uses: docker/build-push-action@v5
81+
with:
82+
context: .
83+
target: router-release
84+
tags: ${{ env.PUSH_TAGS }}
85+
cache-from: type=registry,ref=${{ env.CACHE_IMAGE }}
86+
cache-to: ${{ env.CACHE_TO }}
87+
push: ${{ github.event_name != 'pull_request' }}
88+
platforms: linux/amd64

scripts/get_image_tags.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,36 @@
22

33
# Returns a space separated list of container image tags to be pushed to the
44
# registry
5+
# If a repository is supplied as the first arg, (e.g. quay.io/foo/bar") then the tags will be fully qualified
56

67
tags_to_push=""
78

9+
if [[ -n $1 ]]; then
10+
repo_bit="${1}:"
11+
else
12+
repo_bit=""
13+
fi
14+
815
# if running locally, i.e. CI is unset
916
if [[ -z "${CI+x}" ]];
1017
then
1118
commit="$(git rev-parse --short HEAD)"
1219
branch="$(git rev-parse --abbrev-ref HEAD)"
1320

14-
tags_to_push+="${commit}"
15-
tags_to_push+=" ${branch}"
16-
tags_to_push+=" ${branch}.${commit}"
21+
tags_to_push+="${repo_bit}${commit}"
22+
tags_to_push+=" ${repo_bit}${branch}"
23+
tags_to_push+=" ${repo_bit}${branch}.${commit}"
1724
else
1825
# In CI, pull info from github env vars
1926
commit="${GITHUB_SHA:0:7}"
2027
build_ref="${GITHUB_REF_NAME}"
2128

22-
tags_to_push+="${commit}"
23-
tags_to_push+=" ${build_ref}"
24-
tags_to_push+=" ${build_ref}.${commit}"
29+
tags_to_push+="${repo_bit}${commit}"
30+
if [[ ! ${build_ref} =~ "merge" ]];
31+
then
32+
tags_to_push+=" ${repo_bit}${build_ref}"
33+
tags_to_push+=" ${repo_bit}${build_ref}.${commit}"
34+
fi
2535
fi
2636

2737
echo "${tags_to_push}"

0 commit comments

Comments
 (0)