Skip to content

Commit 9561044

Browse files
Copilotcommjoen
andcommitted
Skip pushing images for PRs from forks to prevent permission errors
Co-authored-by: commjoen <[email protected]>
1 parent 50883c7 commit 9561044

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

.github/workflows/preview.yml

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ jobs:
6868
with:
6969
context: ./${{ matrix.component }}
7070
file: ./${{ matrix.component }}/Dockerfile
71-
push: true
71+
# Only push if it's a push to main OR a PR from the same repo (not a fork)
72+
# External contributors from forks can't write to the org's container registry
73+
push: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository }}
7274
tags: ${{ steps.meta.outputs.tags }}
7375
labels: ${{ steps.meta.outputs.labels }}
7476
platforms: linux/amd64,linux/arm64
@@ -122,9 +124,66 @@ jobs:
122124
PR_NUMBER: ${{ github.event.number }}
123125
REPO_OWNER: ${{ github.repository_owner }}
124126
VALUES_CONTENT: ${{ steps.values.outputs.values }}
127+
IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
125128
run: |
126129
# yamllint disable rule:line-length
127-
cat > instructions.md << EOF
130+
if [ "${IS_FORK}" = "true" ]; then
131+
cat > instructions.md << EOF
132+
## 🚀 Preview Build Complete!
133+
134+
Your pull request has been built successfully. However, since this is from a fork, preview images cannot be pushed to the organization's container registry.
135+
136+
### Testing Your Changes
137+
138+
To test your changes, you can build and deploy locally:
139+
140+
\`\`\`bash
141+
# Clone this PR
142+
git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER}
143+
git checkout pr-${PR_NUMBER}
144+
145+
# Build and deploy locally
146+
./build-and-deploy.sh
147+
148+
# Or for minikube
149+
./build-and-deploy-minikube.sh
150+
151+
# Port forward to access locally
152+
kubectl port-forward service/wrongsecrets-balancer 3000:3000
153+
\`\`\`
154+
155+
### Alternative: Manual Build
156+
157+
\`\`\`bash
158+
# Build images locally
159+
cd wrongsecrets-balancer
160+
docker build -t my-wrongsecrets-balancer:test .
161+
cd ../cleaner
162+
docker build -t my-cleaner:test .
163+
164+
# Deploy with custom images using Helm
165+
helm repo add wrongsecrets https://owasp.org/wrongsecrets-ctf-party
166+
helm repo update
167+
168+
helm install my-preview wrongsecrets/wrongsecrets-ctf-party \\
169+
--set balancer.repository=my-wrongsecrets-balancer \\
170+
--set balancer.tag=test \\
171+
--set wrongsecretsCleanup.repository=my-cleaner \\
172+
--set wrongsecretsCleanup.tag=test \\
173+
--set balancer.imagePullPolicy=Never \\
174+
--set wrongsecretsCleanup.imagePullPolicy=Never
175+
\`\`\`
176+
177+
### Why Can't Images Be Pushed?
178+
179+
External contributors don't have write permissions to the organization's GitHub Container Registry. This is a security measure to protect the organization's packages.
180+
181+
---
182+
183+
*This preview was automatically generated for PR #${PR_NUMBER}*
184+
EOF
185+
else
186+
cat > instructions.md << EOF
128187
## 🚀 Preview Deployment Ready!
129188
130189
Your pull request has been built and is ready for preview deployment.
@@ -198,6 +257,7 @@ jobs:
198257
199258
*This preview was automatically generated for PR #${PR_NUMBER}*
200259
EOF
260+
fi
201261
# yamllint enable rule:line-length
202262
203263
echo "content<<EOF" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)