Skip to content
This repository was archived by the owner on Jun 5, 2025. It is now read-only.

Commit 4ca1480

Browse files
Avoid caching FE code at docker build
The release URL gets cached if we `curl` for the latest release at the `Dockerfile`. To avoid docker caching we need to pass the URL as a build argument everytime we want to build. Which means executing this command and passing the result as a build argument ``` curl -s "https://api.github.com/repos/stacklok/codegate-ui/releases/latest" -H "Authorization: Bearer ***" | grep '"zipball_url":' | cut -d '"' -f 4 ```
1 parent 768ae40 commit 4ca1480

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

.github/workflows/image-build.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
- name: Fetch latest FE commit SHA
2424
id: fetch_commit_fe_sha
2525
run: |
26-
echo "LATEST_COMMIT_SHA=$(curl -LSsk 'https://api.github.com/repos/stacklok/codegate-ui/commits?per_page=1' -H 'Authorization: Bearer ${{ secrets.GH_CI_TOKEN }}' | jq -r '.[0].sha')" >> $GITHUB_ENV
26+
echo "LATEST_RELEASE=$(curl -s "https://api.github.com/repos/stacklok/codegate-ui/releases/latest" -H "Authorization: Bearer ${{ secrets.GH_CI_TOKEN }}" | grep '"zipball_url":' | cut -d '"' -f 4)" >> $GITHUB_ENV
27+
echo "Fetched LATEST_RELEASE: $LATEST_RELEASE"
2728
- name: Test build on x86
2829
id: docker_build
2930
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 # v5
@@ -38,4 +39,4 @@ jobs:
3839
secrets: |
3940
gh_token=${{ secrets.GH_CI_TOKEN }}
4041
build-args: |
41-
LATEST_COMMIT_SHA=${{ env.LATEST_COMMIT_SHA }}
42+
LATEST_RELEASE=${{ env.LATEST_RELEASE }}

.github/workflows/image-publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ jobs:
6666
- name: Fetch latest FE commit SHA
6767
id: fetch_commit_fe_sha
6868
run: |
69-
echo "LATEST_COMMIT_SHA=$(curl -LSsk 'https://api.github.com/repos/stacklok/codegate-ui/commits?per_page=1' -H 'Authorization: Bearer ${{ secrets.GH_CI_TOKEN }}' | jq -r '.[0].sha')" >> $GITHUB_ENV
70-
echo "Fetched LATEST_COMMIT_SHA: $LATEST_COMMIT_SHA"
69+
echo "LATEST_RELEASE=$(curl -s "https://api.github.com/repos/stacklok/codegate-ui/releases/latest" -H "Authorization: Bearer ${{ secrets.GH_CI_TOKEN }}" | grep '"zipball_url":' | cut -d '"' -f 4)" >> $GITHUB_ENV
70+
echo "Fetched LATEST_RELEASE: $LATEST_RELEASE"
7171
- name: Rename to accommodate to image
7272
run: mv ./backup_weaviate ./weaviate_backup
7373
- name: Download git lfs dependencies
@@ -88,7 +88,7 @@ jobs:
8888
secrets: |
8989
gh_token=${{ secrets.GH_CI_TOKEN }}
9090
build-args: |
91-
LATEST_COMMIT_SHA=${{ env.LATEST_COMMIT_SHA }}
91+
LATEST_RELEASE=${{ env.LATEST_RELEASE }}
9292
- name: Capture Image Digest
9393
id: image-digest
9494
run: |

Dockerfile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
3232

3333
WORKDIR /usr/src/
3434

35+
# To ensure we always download the latest release of the webapp, we use a build argument.
36+
# This prevents the curl command from being cached by Docker.
37+
ARG LATEST_RELEASE=LATEST
38+
RUN echo "Latest FE release: $LATEST_RELEASE"
3539
RUN --mount=type=secret,id=gh_token \
36-
curl -s -H "Authorization: Bearer $(cat /run/secrets/gh_token)" https://api.github.com/repos/stacklok/codegate-ui/releases/latest \
37-
| grep '"zipball_url":' \
38-
| cut -d '"' -f 4 \
39-
| xargs -n 1 -I {} curl -L -H "Authorization: Bearer $(cat /run/secrets/gh_token)" -o main.zip {}
40+
LATEST_RELEASE=${LATEST_RELEASE} \
41+
curl -L -H "Authorization: Bearer $(cat /run/secrets/gh_token)" -o main.zip ${LATEST_RELEASE}
4042

4143
# Extract the downloaded zip file
4244
RUN unzip main.zip

0 commit comments

Comments
 (0)