Skip to content

Commit e4a7146

Browse files
committed
fix: streamline Kaniko build process and update image tag handling
1 parent f3e7199 commit e4a7146

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

.github/workflows/build-kaniko-docker.yaml

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,66 +22,67 @@ concurrency:
2222

2323
jobs:
2424
build-to-ghcr:
25-
runs-on: fetch-repos-bot-runner-k8s-kaniko
26-
25+
runs-on: fetch-repos-bot-runner-k8s-kaniko # self-hosted label
2726
container:
2827
image: gcr.io/kaniko-project/executor:v1.23.2-debug
29-
28+
options: --privileged # lets Kaniko access /proc/…
3029
permissions:
3130
contents: read
32-
packages: write # push to GHCR
31+
packages: write # push to GHCR
3332

3433
steps:
3534

3635
- name: Checkout repository
3736
uses: actions/[email protected]
38-
- name: Build and Push Image to GHCR with kaniko
37+
- name: Build & push with Kaniko
3938
env:
4039
GIT_USERNAME: ${{ github.actor }}
4140
GIT_PASSWORD: ${{ secrets.CR_PAT }}
4241
run: |
42+
set -euo pipefail
4343
REPO_OWNER_LC=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
44-
IMAGE_BASE=ghcr.io/$REPO_OWNER_LC/fetch-repos-bot-runner
45-
CACHE_IMG=ghcr.io/$REPO_OWNER_LC/fetch-repos-bot-runner-cache:latest
46-
cat <<EOF > /kaniko/.docker/config.json
47-
{
48-
"auths": {
49-
"ghcr.io": {
50-
"auth": "$(echo -n "$GIT_USERNAME:$GIT_PASSWORD" | base64 -w0)"
51-
}
52-
}
53-
}
44+
45+
IMAGE_BASE="ghcr.io/${REPO_OWNER_LC}/fetch-repos-bot-runner"
46+
CACHE_IMG="ghcr.io/${REPO_OWNER_LC}/fetch-repos-bot-runner-cache"
47+
48+
# ↓ auth for Kaniko
49+
mkdir -p /kaniko/.docker
50+
cat >/kaniko/.docker/config.json <<EOF
51+
{ "auths": { "ghcr.io": { "auth": "$(echo -n "$GIT_USERNAME:$GIT_PASSWORD" | base64 -w0)" } } }
5452
EOF
5553
56-
/kaniko/executor --dockerfile="repos/fetch-repos/Dockerfile" \
54+
SHORT_SHA=$(echo $GITHUB_SHA | head -c7)
55+
56+
/kaniko/executor \
57+
--dockerfile="repos/fetch-repos/Dockerfile" \
5758
--context="${{ github.repositoryUrl }}#${{ github.ref }}#${{ github.sha }}" \
58-
--destination="$IMAGE_BASE:$(echo $GITHUB_SHA | head -c7)" \
59-
$KANIKO_CACHE_ARGS \
60-
--cache-repo="$CACHE_IMG" \
59+
--destination="${IMAGE_BASE}:${SHORT_SHA}" \
60+
${KANIKO_CACHE_ARGS} \
61+
--cache-repo="${CACHE_IMG}" \
6162
--push-retry 5
6263
64+
echo "IMAGE_BASE=${IMAGE_BASE}" >> $GITHUB_ENV
65+
echo "SHORT_SHA=${SHORT_SHA}" >> $GITHUB_ENV
66+
6367
- name: Set NEW_TAG output
6468
id: set_tag
65-
run: |
66-
NEW_TAG="$IMAGE_BASE:$(echo $GITHUB_SHA | head -c7)"
67-
echo "NEW_TAG=$NEW_TAG" >> $GITHUB_OUTPUT
69+
run: echo "NEW_TAG=${IMAGE_BASE}:${SHORT_SHA}" >>"$GITHUB_OUTPUT"
6870

69-
- name: Update image tag in values.yaml only
71+
- name: Update values.yaml
7072
env:
7173
NEW_TAG: ${{ steps.set_tag.outputs.NEW_TAG }}
7274
uses: mikefarah/[email protected]
7375
with:
7476
cmd: |
75-
echo "Updating repos/fetch-repos/values.yaml to use tag $NEW_TAG"
77+
echo "Updating repos/fetch-repos/values.yaml $NEW_TAG"
7678
yq -i '.template.spec.containers[0].image = strenv(NEW_TAG)' repos/fetch-repos/values.yaml
7779
7880
- name: Create or update tag-bump PR
79-
uses: peter-evans/create-pull-request@v7.0.8
81+
uses: peter-evans/create-pull-request@v7
8082
with:
8183
token: ${{ secrets.GITHUB_TOKEN }}
8284
branch: chore/update-runner-image
83-
commit-message: |
84-
chore: update runner image tag to ${{ steps.set_tag.outputs.NEW_TAG }}
85+
commit-message: "chore: update runner image tag to ${{ steps.set_tag.outputs.NEW_TAG }}"
8586
title: "chore: bump runner image → ${{ steps.set_tag.outputs.NEW_TAG }}"
8687
body: |
8788
Automated build updated:

0 commit comments

Comments
 (0)