Skip to content

Commit fadb2c2

Browse files
authored
fix(ci): keep fork image builds off the shared Quay repos (#5290)
* fix(ci): keep fork image builds off the shared Quay repos Forks must set QUAY_RHDH_IMAGE_REPO / QUAY_E2E_RUNNER_IMAGE_REPO to their own namespace; unconfigured scheduled and push runs are skipped. * fix(ci): fail fork Quay guard before checkout Reject any rhdh-community/* destination and skip the clone on rejected runs.
1 parent e784d01 commit fadb2c2

3 files changed

Lines changed: 53 additions & 3 deletions

File tree

.github/workflows/next-build-image.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ concurrency:
3737

3838
env:
3939
REGISTRY: quay.io
40-
REGISTRY_IMAGE: rhdh-community/rhdh
40+
# Forks: set repo variable QUAY_RHDH_IMAGE_REPO to your own Quay repo (namespace/repo)
41+
# and secrets QUAY_USERNAME/QUAY_TOKEN scoped to that namespace (not rhdh-community).
42+
# See CONTRIBUTING.md ("Testing image builds from a fork").
43+
REGISTRY_IMAGE: ${{ vars.QUAY_RHDH_IMAGE_REPO || 'rhdh-community/rhdh' }}
4144

4245
jobs:
4346
build-image:
4447
name: Build Image
48+
if: github.repository == 'redhat-developer/rhdh' || vars.QUAY_RHDH_IMAGE_REPO != '' || github.event_name == 'workflow_dispatch'
4549
env:
4650
HAS_QUAY_AUTH: ${{ secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
4751
strategy:
@@ -56,6 +60,12 @@ jobs:
5660
contents: read
5761
packages: write
5862
steps:
63+
- name: Guard against pushing to shared repo from a fork
64+
if: github.repository != 'redhat-developer/rhdh' && startsWith(env.REGISTRY_IMAGE, 'rhdh-community/')
65+
run: |
66+
echo "::error::Forks must set repository variable QUAY_RHDH_IMAGE_REPO to a Quay repo outside the rhdh-community namespace."
67+
exit 1
68+
5969
- name: Checkout
6070
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
6171
with:
@@ -165,6 +175,7 @@ jobs:
165175
retention-days: 1
166176

167177
merge:
178+
if: github.repository == 'redhat-developer/rhdh' || vars.QUAY_RHDH_IMAGE_REPO != '' || github.event_name == 'workflow_dispatch'
168179
runs-on: ubuntu-latest
169180
needs:
170181
- build-image
@@ -175,6 +186,12 @@ jobs:
175186
env:
176187
HAS_QUAY_AUTH: ${{ secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
177188
steps:
189+
- name: Guard against pushing to shared repo from a fork
190+
if: github.repository != 'redhat-developer/rhdh' && startsWith(env.REGISTRY_IMAGE, 'rhdh-community/')
191+
run: |
192+
echo "::error::Forks must set repository variable QUAY_RHDH_IMAGE_REPO to a Quay repo outside the rhdh-community namespace."
193+
exit 1
194+
178195
- name: Login to Quay
179196
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
180197
with:

.github/workflows/push-e2e-runner.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@ concurrency:
2525

2626
env:
2727
REGISTRY: quay.io
28-
REGISTRY_IMAGE: rhdh-community/rhdh-e2e-runner
28+
# Forks: set repo variable QUAY_E2E_RUNNER_IMAGE_REPO to your own Quay repo (namespace/repo)
29+
# and secrets QUAY_USERNAME/QUAY_TOKEN scoped to that namespace (not rhdh-community).
30+
# See CONTRIBUTING.md ("Testing image builds from a fork").
31+
REGISTRY_IMAGE: ${{ vars.QUAY_E2E_RUNNER_IMAGE_REPO || 'rhdh-community/rhdh-e2e-runner' }}
2932

3033
jobs:
3134
build-image:
3235
name: Build e2e-runner (${{ matrix.os }})
36+
if: github.event_name == 'pull_request' || github.repository == 'redhat-developer/rhdh' || vars.QUAY_E2E_RUNNER_IMAGE_REPO != '' || github.event_name == 'workflow_dispatch'
3337
env:
3438
HAS_QUAY_AUTH: ${{ secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
3539
strategy:
@@ -45,6 +49,12 @@ jobs:
4549
packages: write
4650

4751
steps:
52+
- name: Guard against pushing to shared repo from a fork
53+
if: github.event_name != 'pull_request' && github.repository != 'redhat-developer/rhdh' && startsWith(env.REGISTRY_IMAGE, 'rhdh-community/')
54+
run: |
55+
echo "::error::Forks must set repository variable QUAY_E2E_RUNNER_IMAGE_REPO to a Quay repo outside the rhdh-community namespace."
56+
exit 1
57+
4858
- name: Checkout Repository
4959
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
5060
with:
@@ -131,7 +141,7 @@ jobs:
131141

132142
merge:
133143
name: Create multi-arch manifest
134-
if: github.event_name != 'pull_request'
144+
if: github.event_name != 'pull_request' && (github.repository == 'redhat-developer/rhdh' || vars.QUAY_E2E_RUNNER_IMAGE_REPO != '' || github.event_name == 'workflow_dispatch')
135145
runs-on: ubuntu-24.04
136146
timeout-minutes: 20
137147
needs: build-image
@@ -140,6 +150,12 @@ jobs:
140150
packages: write
141151

142152
steps:
153+
- name: Guard against pushing to shared repo from a fork
154+
if: github.repository != 'redhat-developer/rhdh' && startsWith(env.REGISTRY_IMAGE, 'rhdh-community/')
155+
run: |
156+
echo "::error::Forks must set repository variable QUAY_E2E_RUNNER_IMAGE_REPO to a Quay repo outside the rhdh-community namespace."
157+
exit 1
158+
143159
- name: Checkout Repository
144160
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
145161
with:

CONTRIBUTING.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,23 @@ If you want to submit code changes to the project, here are some guidelines:
148148
149149
Go to the original repository and click on **New Pull Request**. Provide a clear description of your changes, including any issues your PR fixes, acceptance criteria, and any special notes to the reviewers.
150150
151+
### Testing image builds from a fork
152+
153+
The image-push workflows default to `quay.io/rhdh-community/rhdh` and `quay.io/rhdh-community/rhdh-e2e-runner`. Forks that set `QUAY_USERNAME`/`QUAY_TOKEN` without retargeting those repos can overwrite shared tags such as `:next`.
154+
155+
To test image builds from a fork:
156+
157+
1. Create a Quay repository in **your** namespace (not `rhdh-community`).
158+
2. Set a repository variable (Settings → Secrets and variables → Actions → Variables):
159+
- `QUAY_RHDH_IMAGE_REPO` = `<your-namespace>/<repo>` for [next-build-image.yaml](.github/workflows/next-build-image.yaml)
160+
- `QUAY_E2E_RUNNER_IMAGE_REPO` = `<your-namespace>/<repo>` for [push-e2e-runner.yaml](.github/workflows/push-e2e-runner.yaml)
161+
162+
Do not set either variable under the `rhdh-community/` namespace. Forks that do so are rejected.
163+
3. Set secrets `QUAY_USERNAME` and `QUAY_TOKEN` for a robot account scoped to **that** namespace only.
164+
4. Run the workflow via **Actions → Run workflow** (`workflow_dispatch`), or push/schedule once the variable is set.
165+
166+
Without `QUAY_RHDH_IMAGE_REPO` / `QUAY_E2E_RUNNER_IMAGE_REPO`, scheduled and push runs on a fork are skipped. A manual run without the variable fails with an error rather than pushing to the shared production image.
167+
151168
## Commit Messages
152169
153170
Follow the [Conventional Commits](https://www.conventionalcommits.org/) specification:

0 commit comments

Comments
 (0)