Skip to content

Commit 8ea6dba

Browse files
committed
ci: allow forks to override published container image namespace
The publish workflows hardcoded ghcr.io/triggerdotdev/... as the image destination, so a fork building on push-to-main would attempt to push to (and attest) the upstream packages. Derive the webapp image repo from github.repository (overridable via the WEBAPP_IMAGE_REPO variable) and read the worker namespace from the IMAGE_REGISTRY variable, both defaulting to the current values so upstream behaviour is unchanged.
1 parent f261ff2 commit 8ea6dba

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

.github/workflows/publish-webapp.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ on:
2121
short_sha:
2222
description: Short commit SHA of the published build
2323
value: ${{ jobs.publish.outputs.short_sha }}
24+
image_repo:
25+
description: The image repository the build was published to (without tag)
26+
value: ${{ jobs.publish.outputs.image_repo }}
2427
secrets:
2528
SENTRY_AUTH_TOKEN:
2629
required: false
@@ -33,6 +36,7 @@ jobs:
3336
outputs:
3437
version: ${{ steps.get_tag.outputs.tag }}
3538
short_sha: ${{ steps.get_commit.outputs.sha_short }}
39+
image_repo: ${{ steps.set_tags.outputs.image_repo }}
3640
steps:
3741
- name: 🏭 Setup Depot CLI
3842
uses: depot/setup-action@15c09a5f77a0840ad4bce955686522a257853461 # v1.7.1
@@ -57,17 +61,22 @@ jobs:
5761
- name: 📛 Set the tags
5862
id: set_tags
5963
run: |
60-
ref_without_tag=ghcr.io/triggerdotdev/trigger.dev
61-
image_tags=$ref_without_tag:${STEPS_GET_TAG_OUTPUTS_TAG}
64+
# The image repo defaults to ghcr.io/<owner>/<repo>, so a fork publishes
65+
# to its own package automatically with no extra config. Set the
66+
# WEBAPP_IMAGE_REPO repository variable to override it with any
67+
# registry/path.
68+
image_tags=$REF_WITHOUT_TAG:${STEPS_GET_TAG_OUTPUTS_TAG}
6269
6370
# when pushing the mutable main tag, also push an immutable-by-convention
6471
# full-commit-sha tag so a commit can be resolved to a specific digest
6572
if [[ "${STEPS_GET_TAG_OUTPUTS_TAG}" == "main" ]]; then
66-
image_tags=$image_tags,$ref_without_tag:${GITHUB_SHA}
73+
image_tags=$image_tags,$REF_WITHOUT_TAG:${GITHUB_SHA}
6774
fi
6875
6976
echo "image_tags=${image_tags}" >> "$GITHUB_OUTPUT"
77+
echo "image_repo=${REF_WITHOUT_TAG}" >> "$GITHUB_OUTPUT"
7078
env:
79+
REF_WITHOUT_TAG: ${{ vars.WEBAPP_IMAGE_REPO || format('ghcr.io/{0}', github.repository) }}
7180
STEPS_GET_TAG_OUTPUTS_TAG: ${{ steps.get_tag.outputs.tag }}
7281
STEPS_GET_TAG_OUTPUTS_IS_SEMVER: ${{ steps.get_tag.outputs.is_semver }}
7382

@@ -122,6 +131,6 @@ jobs:
122131
continue-on-error: true
123132
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
124133
with:
125-
subject-name: ghcr.io/triggerdotdev/trigger.dev
134+
subject-name: ${{ steps.set_tags.outputs.image_repo }}
126135
subject-digest: ${{ steps.build_push.outputs.digest }}
127136
push-to-registry: true

.github/workflows/publish-worker-v4.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ jobs:
6565
- name: 📛 Set tags to push
6666
id: set_tags
6767
run: |
68-
ref_without_tag=ghcr.io/triggerdotdev/${STEPS_GET_REPOSITORY_OUTPUTS_REPO}
68+
# Defaults to the public namespace. Set the IMAGE_REGISTRY repository
69+
# variable to publish under a different namespace (e.g. in a fork)
70+
# instead of the default packages.
71+
ref_without_tag=${IMAGE_REGISTRY}/${STEPS_GET_REPOSITORY_OUTPUTS_REPO}
6972
image_tags=$ref_without_tag:${STEPS_GET_TAG_OUTPUTS_TAG}
7073
7174
echo "image_tags=${image_tags}" >> "$GITHUB_OUTPUT"
7275
env:
76+
IMAGE_REGISTRY: ${{ vars.IMAGE_REGISTRY || 'ghcr.io/triggerdotdev' }}
7377
STEPS_GET_REPOSITORY_OUTPUTS_REPO: ${{ steps.get_repository.outputs.repo }}
7478
STEPS_GET_TAG_OUTPUTS_TAG: ${{ steps.get_tag.outputs.tag }}
7579
STEPS_GET_TAG_OUTPUTS_IS_SEMVER: ${{ steps.get_tag.outputs.is_semver }}

.github/workflows/publish-worker.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ jobs:
8383
docker tag infra_image "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
8484
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
8585
env:
86-
REGISTRY: ghcr.io/triggerdotdev
86+
# Defaults to the public namespace. Set the IMAGE_REGISTRY repository
87+
# variable to publish worker images under a different namespace (e.g.
88+
# in a fork) instead of the default packages.
89+
REGISTRY: ${{ vars.IMAGE_REGISTRY || 'ghcr.io/triggerdotdev' }}
8790
REPOSITORY: ${{ steps.get_repository.outputs.repo }}
8891
IMAGE_TAG: ${{ steps.get_tag.outputs.tag }}
8992

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ jobs:
106106
packages: read # pull the just-published image from GHCR
107107
uses: ./.github/workflows/trivy-image-webapp.yml
108108
with:
109-
image-ref: ghcr.io/triggerdotdev/trigger.dev:${{ needs.publish-webapp.outputs.version }}
109+
image-ref: ${{ needs.publish-webapp.outputs.image_repo }}:${{ needs.publish-webapp.outputs.version }}

0 commit comments

Comments
 (0)