1+ ---
12name : " Preview Deployment"
23
34on :
1617 IMAGE_PREFIX : ghcr.io/${{ github.repository_owner }}
1718
1819jobs :
20+ set-tag :
21+ name : " Determine Tag"
22+ runs-on : ubuntu-latest
23+ outputs :
24+ tag : ${{ steps.set-tag.outputs.tag }}
25+ steps :
26+ - name : Set output tag
27+ id : set-tag
28+ run : |
29+ if [ "${{ github.event_name }}" == "pull_request" ]; then
30+ echo "tag=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
31+ else
32+ echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
33+ fi
34+
1935 build-and-publish :
2036 name : " Build and Publish Preview Images"
2137 runs-on : ubuntu-latest
38+ needs : set-tag
2239 strategy :
2340 matrix :
2441 component :
2542 - wrongsecrets-balancer
2643 - cleaner
27- outputs :
28- tag : ${{ steps.set-tag.outputs.tag }}
2944 steps :
3045 - name : Checkout
3146 uses : actions/checkout@v5
@@ -40,24 +55,13 @@ jobs:
4055 username : ${{ github.actor }}
4156 password : ${{ secrets.GITHUB_TOKEN }}
4257
43- - name : Set output tag
44- id : set-tag
45- run : |
46- if [ "${{ github.event_name }}" == "pull_request" ]; then
47- echo "tag=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
48- else
49- echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
50- fi
51-
5258 - name : Generate metadata
5359 id : meta
5460 uses : docker/metadata-action@v5
5561 with :
5662 images : ${{ env.IMAGE_PREFIX }}/${{ matrix.component }}
5763 tags : |
58- type=ref,event=branch
59- type=ref,event=pr
60- type=sha,prefix={{branch}}-
64+ type=raw,value=${{ needs.set-tag.outputs.tag }}
6165
6266 - name : Build and push
6367 uses : docker/build-push-action@v6
7276 generate-preview-instructions :
7377 name : " Generate Preview Instructions"
7478 runs-on : ubuntu-latest
75- needs : build-and-publish
79+ needs : [set-tag, build-and-publish]
7680 if : github.event_name == 'pull_request'
7781 steps :
7882 - name : Checkout
@@ -82,37 +86,29 @@ jobs:
8286 run : |
8387 sudo snap install yq
8488
85- - name : Determine image tag
86- id : tag
87- run : |
88- if [ "${{ github.event_name }}" == "pull_request" ]; then
89- echo "tag=pr-${{ github.event.number }}" >> $GITHUB_OUTPUT
90- else
91- echo "tag=${{ github.ref_name }}" >> $GITHUB_OUTPUT
92- fi
93-
9489 - name : Generate preview values
9590 id : values
9691 run : |
9792 # Create a preview values file
9893 cat > preview-values.yaml << EOF
9994 balancer:
10095 repository: ${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer
101- tag: ${{ steps. tag.outputs.tag }}
102-
96+ tag: ${{ needs.set- tag.outputs.tag }}
97+
10398 wrongsecretsCleanup:
10499 repository: ${{ env.IMAGE_PREFIX }}/cleaner
105- tag: ${{ steps. tag.outputs.tag }}
106-
100+ tag: ${{ needs.set- tag.outputs.tag }}
101+
107102 # Preview configuration
108103 ingress:
109104 enabled: true
110105 hosts:
111- - host: preview-${{ steps.tag.outputs.tag }}.wrongsecrets.local
106+ - host: >-
107+ preview-${{ needs.set-tag.outputs.tag }}.wrongsecrets.local
112108 paths:
113109 - "/"
114110 EOF
115-
111+
116112 # Output the content for use in the comment
117113 echo "values<<EOF" >> $GITHUB_OUTPUT
118114 cat preview-values.yaml >> $GITHUB_OUTPUT
@@ -123,77 +119,79 @@ jobs:
123119 run : |
124120 cat > instructions.md << 'EOF'
125121 ## 🚀 Preview Deployment Ready!
126-
127- Your pull request has been built and is ready for preview deployment. Here's how to test your changes:
128-
122+
123+ Your pull request has been built and is ready for preview deployment.
124+ Here's how to test your changes:
125+
129126 ### Container Images Built
130-
131- - **Balancer**: `${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer:${{ steps. tag.outputs.tag }}`
132- - **Cleaner**: `${{ env.IMAGE_PREFIX }}/cleaner:${{ steps. tag.outputs.tag }}`
133-
127+
128+ - **Balancer**: `${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer:${{ needs.set- tag.outputs.tag }}`
129+ - **Cleaner**: `${{ env.IMAGE_PREFIX }}/cleaner:${{ needs.set- tag.outputs.tag }}`
130+
134131 ### Quick Deploy with Helm
135-
132+
136133 ```bash
137134 # Add the wrongsecrets helm repository
138135 helm repo add wrongsecrets https://owasp.org/wrongsecrets-ctf-party
139136 helm repo update
140-
137+
141138 # Deploy with preview images
142139 helm install my-preview wrongsecrets/wrongsecrets-ctf-party \
143140 --set balancer.repository=${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer \
144- --set balancer.tag=${{ steps. tag.outputs.tag }} \
141+ --set balancer.tag=${{ needs.set- tag.outputs.tag }} \
145142 --set wrongsecretsCleanup.repository=${{ env.IMAGE_PREFIX }}/cleaner \
146- --set wrongsecretsCleanup.tag=${{ steps. tag.outputs.tag }} \
143+ --set wrongsecretsCleanup.tag=${{ needs.set- tag.outputs.tag }} \
147144 --set imagePullPolicy=Always
148-
145+
149146 # Port forward to access locally
150147 kubectl port-forward service/wrongsecrets-balancer 3000:3000
151148 ```
152-
149+
153150 ### Deploy with Custom Values
154-
151+
155152 <details>
156153 <summary>Click to see preview-values.yaml</summary>
157-
154+
158155 ```yaml
159156 ${{ steps.values.outputs.values }}
160157 ```
161-
158+
162159 </details>
163-
160+
164161 ```bash
165162 # Save the above values to preview-values.yaml, then:
166- helm install my-preview wrongsecrets/wrongsecrets-ctf-party -f preview-values.yaml
163+ helm install my-preview wrongsecrets/wrongsecrets-ctf-party \
164+ -f preview-values.yaml
167165 ```
168-
166+
169167 ### Deploy with Local Build Scripts
170-
168+
171169 ```bash
172170 # Clone this PR
173171 git fetch origin pull/${{ github.event.number }}/head:pr-${{ github.event.number }}
174172 git checkout pr-${{ github.event.number }}
175-
173+
176174 # Use the existing deployment script with custom images
177175 ./build-and-deploy.sh
178176 ```
179-
177+
180178 ### Test the Changes
181-
179+
182180 1. Access the application at http://localhost:3000
183181 2. Create a team and verify functionality
184182 3. Test any new features or bug fixes
185-
183+
186184 ### Container Registry
187-
185+
188186 The preview images are available at:
189187 - https://github.com/${{ github.repository_owner }}/wrongsecrets-ctf-party/pkgs/container/wrongsecrets-balancer
190188 - https://github.com/${{ github.repository_owner }}/wrongsecrets-ctf-party/pkgs/container/cleaner
191-
189+
192190 ---
193-
191+
194192 *This preview was automatically generated for PR #${{ github.event.number }}*
195193 EOF
196-
194+
197195 echo "content<<EOF" >> $GITHUB_OUTPUT
198196 cat instructions.md >> $GITHUB_OUTPUT
199197 echo "EOF" >> $GITHUB_OUTPUT
@@ -204,21 +202,21 @@ jobs:
204202 script : |
205203 const { owner, repo } = context.repo;
206204 const issue_number = context.issue.number;
207-
205+
208206 // Find existing preview comment
209207 const comments = await github.rest.issues.listComments({
210208 owner,
211209 repo,
212210 issue_number,
213211 });
214-
215- const existingComment = comments.data.find(comment =>
216- comment.user.login === 'github-actions[bot]' &&
212+
213+ const existingComment = comments.data.find(comment =>
214+ comment.user.login === 'github-actions[bot]' &&
217215 comment.body.includes('🚀 Preview Deployment Ready!')
218216 );
219-
217+
220218 const body = `${{ steps.instructions.outputs.content }}`;
221-
219+
222220 if (existingComment) {
223221 // Update existing comment
224222 await github.rest.issues.updateComment({
@@ -240,21 +238,16 @@ jobs:
240238 notify-main-branch :
241239 name : " Notify Main Branch Build"
242240 runs-on : ubuntu-latest
243- needs : build-and-publish
241+ needs : [set-tag, build-and-publish]
244242 if : github.event_name == 'push' && github.ref == 'refs/heads/main'
245243 steps :
246- - name : Determine image tag
247- id : tag
248- run : |
249- echo "tag=main" >> $GITHUB_OUTPUT
250-
251244 - name : Create main branch notification
252245 run : |
253246 echo "## 🚀 Main Branch Preview Images Updated!"
254247 echo ""
255248 echo "New preview images have been built for the main branch:"
256249 echo ""
257- echo "- **Balancer**: \`${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer:${{ steps. tag.outputs.tag }}\`"
258- echo "- **Cleaner**: \`${{ env.IMAGE_PREFIX }}/cleaner:${{ steps. tag.outputs.tag }}\`"
250+ echo "- **Balancer**: \`${{ env.IMAGE_PREFIX }}/wrongsecrets-balancer:${{ needs.set- tag.outputs.tag }}\`"
251+ echo "- **Cleaner**: \`${{ env.IMAGE_PREFIX }}/cleaner:${{ needs.set- tag.outputs.tag }}\`"
259252 echo ""
260- echo "These can be used for testing the latest main branch changes."
253+ echo "These can be used for testing the latest main branch changes."
0 commit comments