Skip to content

Commit 2c186cf

Browse files
authored
Merge pull request #987 from OWASP/copilot/fix-ee85dc5a-1b70-4d54-aa0f-112ff05a74d6
Fix preview deployment workflow for variable expansion and fork PRs
2 parents 7ddcfe1 + 9561044 commit 2c186cf

File tree

1 file changed

+90
-24
lines changed

1 file changed

+90
-24
lines changed

.github/workflows/preview.yml

Lines changed: 90 additions & 24 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
@@ -116,65 +118,128 @@ jobs:
116118
117119
- name: Create deployment instructions
118120
id: instructions
121+
env:
122+
IMAGE_PREFIX: ${{ env.IMAGE_PREFIX }}
123+
TAG: ${{ needs.set-tag.outputs.tag }}
124+
PR_NUMBER: ${{ github.event.number }}
125+
REPO_OWNER: ${{ github.repository_owner }}
126+
VALUES_CONTENT: ${{ steps.values.outputs.values }}
127+
IS_FORK: ${{ github.event.pull_request.head.repo.full_name != github.repository }}
119128
run: |
120129
# yamllint disable rule:line-length
121-
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
122187
## 🚀 Preview Deployment Ready!
123188
124189
Your pull request has been built and is ready for preview deployment.
125190
Here's how to test your changes:
126191
127192
### Container Images Built
128193
129-
- **Balancer**: `${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer:${{ needs.set-tag.outputs.tag }}`
130-
- **Cleaner**: `${{ env.IMAGE_PREFIX }}/cleaner:${{ needs.set-tag.outputs.tag }}`
194+
- **Balancer**: \`${IMAGE_PREFIX}/wrongsecrets-balancer:${TAG}\`
195+
- **Cleaner**: \`${IMAGE_PREFIX}/cleaner:${TAG}\`
131196
132197
### Quick Deploy with Helm
133198
134-
```bash
199+
\`\`\`bash
135200
# Add the wrongsecrets helm repository
136201
helm repo add wrongsecrets https://owasp.org/wrongsecrets-ctf-party
137202
helm repo update
138203
139204
# Deploy with preview images
140-
helm install my-preview wrongsecrets/wrongsecrets-ctf-party \
141-
--set balancer.repository=${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer \
142-
--set balancer.tag=${{ needs.set-tag.outputs.tag }} \
143-
--set wrongsecretsCleanup.repository=${{ env.IMAGE_PREFIX }}/cleaner \
144-
--set wrongsecretsCleanup.tag=${{ needs.set-tag.outputs.tag }} \
205+
helm install my-preview wrongsecrets/wrongsecrets-ctf-party \\
206+
--set balancer.repository=${IMAGE_PREFIX}/wrongsecrets-balancer \\
207+
--set balancer.tag=${TAG} \\
208+
--set wrongsecretsCleanup.repository=${IMAGE_PREFIX}/cleaner \\
209+
--set wrongsecretsCleanup.tag=${TAG} \\
145210
--set imagePullPolicy=Always
146211
147212
# Port forward to access locally
148213
kubectl port-forward service/wrongsecrets-balancer 3000:3000
149-
```
214+
\`\`\`
150215
151216
### Deploy with Custom Values
152217
153218
<details>
154219
<summary>Click to see preview-values.yaml</summary>
155220
156-
```yaml
157-
${{ steps.values.outputs.values }}
158-
```
221+
\`\`\`yaml
222+
${VALUES_CONTENT}
223+
\`\`\`
159224
160225
</details>
161226
162-
```bash
227+
\`\`\`bash
163228
# Save the above values to preview-values.yaml, then:
164-
helm install my-preview wrongsecrets/wrongsecrets-ctf-party \
229+
helm install my-preview wrongsecrets/wrongsecrets-ctf-party \\
165230
-f preview-values.yaml
166-
```
231+
\`\`\`
167232
168233
### Deploy with Local Build Scripts
169234
170-
```bash
235+
\`\`\`bash
171236
# Clone this PR
172-
git fetch origin pull/${{ github.event.number }}/head:pr-${{ github.event.number }}
173-
git checkout pr-${{ github.event.number }}
237+
git fetch origin pull/${PR_NUMBER}/head:pr-${PR_NUMBER}
238+
git checkout pr-${PR_NUMBER}
174239
175240
# Use the existing deployment script with custom images
176241
./build-and-deploy.sh
177-
```
242+
\`\`\`
178243
179244
### Test the Changes
180245
@@ -185,13 +250,14 @@ jobs:
185250
### Container Registry
186251
187252
The preview images are available at:
188-
- https://github.com/${{ github.repository_owner }}/wrongsecrets-ctf-party/pkgs/container/wrongsecrets-balancer
189-
- https://github.com/${{ github.repository_owner }}/wrongsecrets-ctf-party/pkgs/container/cleaner
253+
- https://github.com/${REPO_OWNER}/wrongsecrets-ctf-party/pkgs/container/wrongsecrets-balancer
254+
- https://github.com/${REPO_OWNER}/wrongsecrets-ctf-party/pkgs/container/cleaner
190255
191256
---
192257
193-
*This preview was automatically generated for PR #${{ github.event.number }}*
258+
*This preview was automatically generated for PR #${PR_NUMBER}*
194259
EOF
260+
fi
195261
# yamllint enable rule:line-length
196262
197263
echo "content<<EOF" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)