Skip to content

Commit 4030405

Browse files
committed
updated docker flows
1 parent 8e7d05b commit 4030405

File tree

10 files changed

+404
-9
lines changed

10 files changed

+404
-9
lines changed

.github/workflows/build-preview.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ jobs:
2222
distribution: "oracle"
2323
cache: "maven"
2424

25+
- name: Extract version from pom.xml
26+
id: extract-version
27+
run: |
28+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
29+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
30+
echo "version=$VERSION" >> $GITHUB_OUTPUT
31+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
32+
echo "Detected version: $VERSION"
33+
echo "Docker version: $DOCKER_VERSION"
34+
2535
- name: Build application
2636
run: |
2737
echo "Building WrongSecrets application..."
@@ -33,8 +43,8 @@ jobs:
3343
3444
- name: Build Docker image
3545
run: |
36-
echo "Building Docker image..."
37-
docker build -t wrongsecrets-preview .
46+
echo "Building Docker image with version ${{ steps.extract-version.outputs.docker_version }}..."
47+
docker build --build-arg argBasedVersion="${{ steps.extract-version.outputs.docker_version }}" -t wrongsecrets-preview .
3848
echo "Docker image built successfully"
3949
docker save wrongsecrets-preview > wrongsecrets-preview.tar
4050

.github/workflows/pr-preview.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ jobs:
3535
- name: Build application
3636
run: ./mvnw --no-transfer-progress clean package -DskipTests
3737

38+
- name: Extract version from pom.xml
39+
id: extract-version
40+
run: |
41+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
42+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
45+
echo "Detected version: $VERSION"
46+
echo "Docker version: $DOCKER_VERSION"
47+
3848
- name: Set up Docker Buildx
3949
uses: docker/setup-buildx-action@v3
4050

@@ -62,6 +72,8 @@ jobs:
6272
push: true
6373
tags: ${{ steps.meta.outputs.tags }}
6474
labels: ${{ steps.meta.outputs.labels }}
75+
build-args: |
76+
argBasedVersion=${{ steps.extract-version.outputs.docker_version }}
6577
cache-from: type=gha
6678
cache-to: type=gha,mode=max
6779

@@ -149,11 +161,25 @@ jobs:
149161
distribution: "oracle"
150162
cache: "maven"
151163

164+
- name: Extract PR version
165+
id: extract-pr-version
166+
working-directory: pr-code
167+
run: |
168+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
169+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
170+
echo "version=$VERSION" >> $GITHUB_OUTPUT
171+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
172+
echo "PR version: $VERSION"
173+
echo "PR Docker version: $DOCKER_VERSION"
174+
152175
- name: Build PR version
153176
working-directory: pr-code
154177
run: |
178+
echo "Building PR version..."
155179
./mvnw --no-transfer-progress clean package -DskipTests
156-
docker build -t wrongsecrets-pr .
180+
echo "PR JAR built successfully"
181+
docker build --build-arg argBasedVersion="${{ steps.extract-pr-version.outputs.docker_version }}" -t wrongsecrets-pr .
182+
echo "PR Docker image built successfully"
157183
158184
- name: Set up JDK 23 for main
159185
uses: actions/setup-java@v4
@@ -162,11 +188,25 @@ jobs:
162188
distribution: "oracle"
163189
cache: "maven"
164190

191+
- name: Extract main version
192+
id: extract-main-version
193+
working-directory: main-code
194+
run: |
195+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
196+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
197+
echo "version=$VERSION" >> $GITHUB_OUTPUT
198+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
199+
echo "Main version: $VERSION"
200+
echo "Main Docker version: $DOCKER_VERSION"
201+
165202
- name: Build main version
166203
working-directory: main-code
167204
run: |
205+
echo "Building main version..."
168206
./mvnw --no-transfer-progress clean package -DskipTests
169-
docker build -t wrongsecrets-main .
207+
echo "Main JAR built successfully"
208+
docker build --build-arg argBasedVersion="${{ steps.extract-main-version.outputs.docker_version }}" -t wrongsecrets-main .
209+
echo "Main Docker image built successfully"
170210
171211
# Alternative approach: Pull the PR image from registry
172212
# - name: Log in to GitHub Container Registry
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Version Sync Check
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'pom.xml'
7+
- 'Dockerfile'
8+
- 'Dockerfile.web'
9+
push:
10+
branches: [master, main]
11+
12+
jobs:
13+
version-check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Set up JDK 23
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: "23"
23+
distribution: "oracle"
24+
cache: "maven"
25+
26+
- name: Validate version consistency
27+
run: |
28+
chmod +x ./scripts/validate-versions.sh
29+
./scripts/validate-versions.sh
30+
31+
- name: Comment on PR if versions are out of sync
32+
if: failure() && github.event_name == 'pull_request'
33+
uses: actions/github-script@v7
34+
with:
35+
script: |
36+
const comment = `🚨 **Version Sync Issue Detected**
37+
38+
The versions in your Dockerfiles don't match the version in \`pom.xml\`.
39+
40+
**🔧 To fix this automatically:**
41+
\`\`\`bash
42+
./scripts/sync-versions.sh
43+
git add Dockerfile Dockerfile.web
44+
git commit -m "Sync versions with pom.xml"
45+
\`\`\`
46+
47+
**📋 Current status:**
48+
- The \`validate-versions.sh\` script found mismatched versions
49+
- Please ensure all Docker build arguments match the Maven project version
50+
- This helps maintain consistency across all deployment methods
51+
52+
---
53+
<sub>Automated version check by GitHub Actions</sub>`;
54+
55+
github.rest.issues.createComment({
56+
issue_number: context.issue.number,
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
body: comment
60+
});

.github/workflows/visual-diff.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ jobs:
2828
distribution: "oracle"
2929
cache: "maven"
3030

31+
- name: Extract PR version
32+
id: extract-pr-version
33+
working-directory: pr-code
34+
run: |
35+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
36+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
37+
echo "version=$VERSION" >> $GITHUB_OUTPUT
38+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
39+
echo "PR version: $VERSION"
40+
3141
- name: Build PR version
3242
working-directory: pr-code
3343
run: |
3444
echo "Building PR version..."
3545
./mvnw --no-transfer-progress clean package -DskipTests
3646
echo "PR JAR built successfully"
37-
docker build -t wrongsecrets-pr .
47+
docker build --build-arg argBasedVersion="${{ steps.extract-pr-version.outputs.docker_version }}" -t wrongsecrets-pr .
3848
echo "PR Docker image built successfully"
3949
4050
- name: Set up JDK 23 for main build
@@ -44,13 +54,23 @@ jobs:
4454
distribution: "oracle"
4555
cache: "maven"
4656

57+
- name: Extract main version
58+
id: extract-main-version
59+
working-directory: main-code
60+
run: |
61+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
62+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
63+
echo "version=$VERSION" >> $GITHUB_OUTPUT
64+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
65+
echo "Main version: $VERSION"
66+
4767
- name: Build main version
4868
working-directory: main-code
4969
run: |
5070
echo "Building main version..."
5171
./mvnw --no-transfer-progress clean package -DskipTests
5272
echo "Main JAR built successfully"
53-
docker build -t wrongsecrets-main .
73+
docker build --build-arg argBasedVersion="${{ steps.extract-main-version.outputs.docker_version }}" -t wrongsecrets-main .
5474
echo "Main Docker image built successfully"
5575
docker build -t wrongsecrets-main .
5676

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM bellsoft/liberica-openjre-debian:23.0.2-9-cds AS builder
22
WORKDIR /builder
33

4-
ARG argBasedVersion="1.12.1"
4+
ARG argBasedVersion="1.12.3B2"
55

66
COPY --chown=wrongsecrets target/wrongsecrets-${argBasedVersion}-SNAPSHOT.jar application.jar
77
RUN java -Djarmode=tools -jar application.jar extract --layers --destination extracted

Dockerfile.web

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM jeroenwillemsen/wrongsecrets:1.12.2A-no-vault
2-
ARG argBasedVersion="1.12.2A-no-vault"
1+
FROM jeroenwillemsen/wrongsecrets:1.12.3B2-no-vault
2+
ARG argBasedVersion="1.12.3B2-no-vault"
33
ARG CANARY_URLS="http://canarytokens.com/terms/about/s7cfbdakys13246ewd8ivuvku/post.jsp,http://canarytokens.com/terms/about/y0all60b627gzp19ahqh7rl6j/post.jsp"
44
ARG CTF_ENABLED=false
55
ARG HINTS_ENABLED=true

docs/VERSION_MANAGEMENT.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Version Management Guide
2+
3+
This document explains how version synchronization works across the WrongSecrets project.
4+
5+
## Overview
6+
7+
The project maintains version consistency between:
8+
- `pom.xml` (Maven project version)
9+
- `Dockerfile` (Docker build argument)
10+
- `Dockerfile.web` (Docker build argument and base image)
11+
12+
## Version Schema
13+
14+
```
15+
pom.xml version: 1.12.3B2-SNAPSHOT
16+
Dockerfile version: 1.12.3B2
17+
Dockerfile.web version: 1.12.3B2-no-vault
18+
```
19+
20+
## Automated Solutions
21+
22+
### 1. GitHub Actions Integration
23+
24+
All build workflows now automatically extract the version from `pom.xml`:
25+
26+
```yaml
27+
- name: Extract version from pom.xml
28+
id: extract-version
29+
run: |
30+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
31+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
32+
echo "docker_version=$DOCKER_VERSION" >> $GITHUB_OUTPUT
33+
34+
- name: Build Docker image
35+
run: |
36+
docker build --build-arg argBasedVersion="${{ steps.extract-version.outputs.docker_version }}" -t image .
37+
```
38+
39+
### 2. Version Sync Scripts
40+
41+
#### Validate Versions
42+
```bash
43+
./scripts/validate-versions.sh
44+
```
45+
Checks if all versions are consistent and reports mismatches.
46+
47+
#### Auto-Sync Versions
48+
```bash
49+
./scripts/sync-versions.sh
50+
```
51+
Automatically updates Dockerfiles to match `pom.xml` version.
52+
53+
#### Build with Version Sync
54+
```bash
55+
./scripts/build-with-version-sync.sh
56+
```
57+
Builds both Docker images with correct versions from `pom.xml`.
58+
59+
### 3. CI/CD Integration
60+
61+
The `version-sync-check.yml` workflow:
62+
- ✅ Runs on PR/push when version files change
63+
- ✅ Validates version consistency
64+
- ✅ Comments on PRs with fix instructions if mismatched
65+
- ✅ Prevents version drift
66+
67+
## Manual Process
68+
69+
### When Updating Versions
70+
71+
1. **Update pom.xml version**:
72+
```xml
73+
<version>1.13.0-SNAPSHOT</version>
74+
```
75+
76+
2. **Run sync script**:
77+
```bash
78+
./scripts/sync-versions.sh
79+
```
80+
81+
3. **Verify changes**:
82+
```bash
83+
./scripts/validate-versions.sh
84+
```
85+
86+
4. **Commit all changes**:
87+
```bash
88+
git add pom.xml Dockerfile Dockerfile.web
89+
git commit -m "Bump version to 1.13.0"
90+
```
91+
92+
## Workflow Integration
93+
94+
### All Build Workflows Include:
95+
96+
1. **Version Extraction**: Gets version from `pom.xml`
97+
2. **Dynamic Build Args**: Passes version to Docker build
98+
3. **Validation**: Ensures JAR file matches expected name
99+
4. **Logging**: Shows which versions are being used
100+
101+
### Benefits:
102+
103+
-**Single Source of Truth**: `pom.xml` is the authoritative version
104+
-**No Manual Updates**: Dockerfiles auto-sync with Maven version
105+
-**CI Validation**: Catches version mismatches early
106+
-**Consistent Builds**: Same version used across all environments
107+
108+
## Troubleshooting
109+
110+
### Common Issues:
111+
112+
1. **JAR Not Found**: Version mismatch between build arg and actual JAR name
113+
- **Solution**: Run `./scripts/sync-versions.sh`
114+
115+
2. **Docker Build Fails**: Hard-coded version in Dockerfile
116+
- **Solution**: Use `--build-arg argBasedVersion=...`
117+
118+
3. **CI Version Mismatch**: Manual updates to Dockerfiles
119+
- **Solution**: Let CI extract from `pom.xml` dynamically
120+
121+
### Debug Commands:
122+
123+
```bash
124+
# Check current versions
125+
mvn help:evaluate -Dexpression=project.version -q -DforceStdout
126+
grep "argBasedVersion" Dockerfile Dockerfile.web
127+
128+
# Test build with current version
129+
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
130+
DOCKER_VERSION=${VERSION%-SNAPSHOT}
131+
docker build --build-arg argBasedVersion="$DOCKER_VERSION" .
132+
```
133+
134+
## Best Practices
135+
136+
1. **Always use scripts** for version updates
137+
2. **Never hard-code versions** in CI workflows
138+
3. **Run validation** before committing changes
139+
4. **Update pom.xml first**, then sync other files
140+
5. **Test builds locally** before pushing
141+
142+
This system ensures version consistency and eliminates manual synchronization errors!

0 commit comments

Comments
 (0)