Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions .github/workflows/internal-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
name: Internal image

on:
pull_request:
branches: [internal/main]
paths: [.github/workflows/internal-image.yml]
push:
tags: ['internal-v*']

permissions:
contents: read

concurrency:
group: internal-image-${{ github.ref }}
cancel-in-progress: false

env:
IMAGE: ghcr.io/profiling/git-cache-proxy

jobs:
prepare:
name: Validate release
if: github.repository == 'profiling/git-cache-proxy'
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.version.outputs.tag }}
chart: ${{ steps.version.outputs.chart }}
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
persist-credentials: false
- name: Check release version and ancestry
id: version
env:
EVENT: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
version=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -1)
tag=internal-v${version}-1
if [ "$EVENT" = push ]; then
tag=$REF_NAME
[[ $tag =~ ^internal-v([0-9]+\.[0-9]+\.[0-9]+)-([1-9][0-9]*)$ ]]
test "${BASH_REMATCH[1]}" = "$version"
revision=${BASH_REMATCH[2]}
git fetch --no-tags origin internal/main
git merge-base --is-ancestor "$GITHUB_SHA" origin/internal/main
# A published version is immutable; retries must use a new version.
releases=$(gh api --paginate "repos/$GITHUB_REPOSITORY/releases" --jq '.[].tag_name')
if grep -Fxq "$tag" <<< "$releases"; then
echo 'Release already exists' >&2
exit 1
fi
else
revision=1
fi
echo "tag=$tag" >> "$GITHUB_OUTPUT"
echo "chart=$version-internal.$revision" >> "$GITHUB_OUTPUT"
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy, rustfmt
- uses: Swatinem/rust-cache@v2
- name: Validate source
run: |
python3 .github/scripts/test_sync_upstream.py
cargo fmt --all --check
cargo clippy --all-targets --all-features --locked -- -D warnings
cargo test --all-features --locked
- uses: azure/setup-helm@v5
- name: Validate chart
run: helm lint chart

build:
name: Build image (${{ matrix.platform }})
needs: prepare
runs-on: ${{ matrix.runner }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: docker/setup-buildx-action@v4
- name: Build test image
uses: docker/build-push-action@v7
with:
context: .
platforms: ${{ matrix.platform }}
load: true
push: false
tags: git-cache-proxy:ci
cache-from: type=gha,scope=internal-${{ matrix.arch }}
cache-to: type=gha,mode=max,scope=internal-${{ matrix.arch }}
- name: Test image
shell: bash
run: |
set -euo pipefail
test "$(docker run --rm --entrypoint id git-cache-proxy:ci -u)" = 10001
docker run -d --name smoke -p 127.0.0.1:8080:8080 git-cache-proxy:ci --upstream https://example.invalid
trap 'docker logs smoke; docker rm -fv smoke' EXIT
ready=false
for _ in $(seq 1 30); do
if curl -fsS localhost:8080/readyz; then ready=true; break; fi
sleep 1
done
test "$ready" = true
docker exec smoke sh -c 'sleep 1 & exit'
sleep 3
if docker exec smoke ps -o stat | grep -q '^Z'; then exit 1; fi
- uses: docker/login-action@v4
if: github.event_name == 'push'
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Push tested image by digest
if: github.event_name == 'push'
id: push
shell: bash
run: |
set -euo pipefail
# Unique staging tags keep version tags untouched until both arches pass.
docker tag git-cache-proxy:ci "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}"
docker push "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}"
digest=$(docker image inspect "$IMAGE:build-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT-${{ matrix.arch }}" --format '{{index .RepoDigests 0}}')
mkdir -p digests
printf '%s\n' "$digest" > digests/${{ matrix.arch }}
- uses: actions/upload-artifact@v7
if: github.event_name == 'push'
with:
name: internal-digest-${{ matrix.arch }}
path: digests/*
if-no-files-found: error

publish:
name: Publish internal release
needs: [prepare, build]
if: github.event_name == 'push'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
env:
TAG: ${{ needs.prepare.outputs.tag }}
CHART_VERSION: ${{ needs.prepare.outputs.chart }}
GH_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v7
with:
persist-credentials: false
- uses: actions/download-artifact@v8
with:
pattern: internal-digest-*
path: digests
merge-multiple: true
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: azure/setup-helm@v5
- name: Publish image and chart
shell: bash
run: |
set -euo pipefail
token=$(curl -fsS --retry 3 -u "$GITHUB_ACTOR:$GH_TOKEN" "https://ghcr.io/token?service=ghcr.io&scope=repository:profiling/git-cache-proxy:pull" | jq -er .token)
status=$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $token" "https://ghcr.io/v2/profiling/git-cache-proxy/manifests/$TAG")
test "$status" = 404 || { echo "Image tag exists or registry check failed: $status" >&2; exit 1; }
echo "$GH_TOKEN" | helm registry login ghcr.io -u "$GITHUB_ACTOR" --password-stdin
token=$(curl -fsS --retry 3 -u "$GITHUB_ACTOR:$GH_TOKEN" "https://ghcr.io/token?service=ghcr.io&scope=repository:profiling/charts/git-cache-proxy:pull" | jq -er .token)
status=$(curl -sS -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $token" "https://ghcr.io/v2/profiling/charts/git-cache-proxy/manifests/$CHART_VERSION")
test "$status" = 404 || { echo "Chart version exists or registry check failed: $status" >&2; exit 1; }
docker buildx imagetools create -t "$IMAGE:$TAG" $(<digests/amd64) $(<digests/arm64)
docker buildx imagetools inspect "$IMAGE:$TAG" | tee image-manifest.txt
# Only the packaged chart changes; the upstream source stays untouched.
cp -R chart packaged-chart
sed -i 's|repository: ghcr.io/rolandjitsu/git-cache-proxy|repository: ghcr.io/profiling/git-cache-proxy|' packaged-chart/values.yaml
grep -q 'repository: ghcr.io/profiling/git-cache-proxy' packaged-chart/values.yaml
helm package packaged-chart -d dist --version "$CHART_VERSION" --app-version "$TAG"
helm lint "dist/git-cache-proxy-$CHART_VERSION.tgz"
helm template release "dist/git-cache-proxy-$CHART_VERSION.tgz" | grep -F "$IMAGE:$TAG"
helm push "dist/git-cache-proxy-$CHART_VERSION.tgz" oci://ghcr.io/profiling/charts
- name: Create release notes
shell: bash
run: |
{
printf 'Source: `%s`\n\nImage: `%s:%s`\n\nChart: `oci://ghcr.io/profiling/charts/git-cache-proxy`, version `%s`\n\n' "$GITHUB_SHA" "$IMAGE" "$TAG" "$CHART_VERSION"
printf 'Platforms: linux/amd64, linux/arm64. No crate published. No deployment performed.\n\n'
printf '```text\n'; cat image-manifest.txt; printf '```\n\n'
printf 'Validation: %s/%s/actions/runs/%s\n' "$GITHUB_SERVER_URL" "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID"
} > notes.md
cat notes.md >> "$GITHUB_STEP_SUMMARY"
gh release create "$TAG" "dist/git-cache-proxy-$CHART_VERSION.tgz" image-manifest.txt --verify-tag --title "$TAG" --notes-file notes.md
Loading