Skip to content

Commit 858943d

Browse files
authored
Merge pull request #14 from agenixframework/feature/dry-run-container-builds
Refactor Dockerfiles for consistent structure, introduce dry-run cont…
2 parents 91ad3f3 + 5ecc075 commit 858943d

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

.github/workflows/dotnet-pr-check.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,60 @@ jobs:
208208
./artifacts/*.nupkg
209209
retention-days: 30
210210

211+
# ===== CONTAINERS DRY-RUN BUILD =====
212+
containers-dry-run:
213+
name: Container Build (dry run)
214+
runs-on: ubuntu-latest
215+
needs: build-and-test
216+
# Skip for merge commits to develop/main
217+
if: ${{ !(github.event_name == 'push' && contains(github.event.head_commit.message, 'Merge pull request')) || github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }}
218+
219+
steps:
220+
- name: Checkout code
221+
uses: actions/checkout@v4
222+
223+
- name: Set up Docker Buildx
224+
uses: docker/setup-buildx-action@v3
225+
226+
- name: Build hub image (dry run)
227+
uses: docker/build-push-action@v6
228+
with:
229+
context: .
230+
file: ./hub/Dockerfile
231+
push: false
232+
load: true
233+
platforms: linux/amd64
234+
tags: |
235+
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-hub:dryrun-${{ github.sha }}
236+
cache-from: type=gha,scope=hub
237+
cache-to: type=gha,scope=hub,mode=max
238+
239+
- name: Build worker image (dry run)
240+
uses: docker/build-push-action@v6
241+
with:
242+
context: .
243+
file: ./worker/Dockerfile
244+
push: false
245+
load: true
246+
platforms: linux/amd64
247+
tags: |
248+
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-worker:dryrun-${{ github.sha }}
249+
cache-from: type=gha,scope=worker
250+
cache-to: type=gha,scope=worker,mode=max
251+
252+
- name: Build dashboard image (dry run)
253+
uses: docker/build-push-action@v6
254+
with:
255+
context: .
256+
file: ./dashboard/Dockerfile
257+
push: false
258+
load: true
259+
platforms: linux/amd64
260+
tags: |
261+
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}-dashboard:dryrun-${{ github.sha }}
262+
cache-from: type=gha,scope=dashboard
263+
cache-to: type=gha,scope=dashboard,mode=max
264+
211265
# ===== DOCUMENTATION (Only for direct pushes to main) =====
212266
documentation:
213267
name: 📚 Documentation
@@ -284,7 +338,7 @@ jobs:
284338
summary:
285339
name: 📊 Build Summary
286340
runs-on: ubuntu-latest
287-
needs: [code-formatting, security-scan, build-and-test] # 🔧 Updated dependencies
341+
needs: [code-formatting, security-scan, build-and-test, containers-dry-run] # 🔧 Updated dependencies
288342
if: always() && (needs.code-formatting.result != 'skipped' || needs.security-scan.result != 'skipped' || needs.build-and-test.result != 'skipped')
289343

290344
steps:
@@ -297,6 +351,7 @@ jobs:
297351
echo "| Code Formatting | ${{ needs.code-formatting.result == 'success' && '✅ Passed' || needs.code-formatting.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
298352
echo "| Security Scan | ${{ needs.security-scan.result == 'success' && '✅ Passed' || needs.security-scan.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
299353
echo "| Build & Test | ${{ needs.build-and-test.result == 'success' && '✅ Passed' || needs.build-and-test.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
354+
echo "| Container Dry-Run | ${{ needs.containers-dry-run.result == 'success' && '✅ Passed' || needs.containers-dry-run.result == 'skipped' && '⏭️ Skipped' || '❌ Failed' }} |" >> $GITHUB_STEP_SUMMARY
300355
echo "" >> $GITHUB_STEP_SUMMARY
301356
echo "### 📈 Key Metrics" >> $GITHUB_STEP_SUMMARY
302357
echo "- **Branch**: \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY

.github/workflows/publish-nuget-and-containers.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ jobs:
295295
- name: Build & push hub
296296
uses: docker/build-push-action@v6
297297
with:
298-
context: ./hub
298+
context: .
299299
file: ./hub/Dockerfile
300300
push: true
301301
platforms: linux/amd64,linux/arm64
@@ -308,7 +308,7 @@ jobs:
308308
- name: Build & push worker
309309
uses: docker/build-push-action@v6
310310
with:
311-
context: ./worker
311+
context: .
312312
file: ./worker/Dockerfile
313313
push: true
314314
platforms: linux/amd64,linux/arm64
@@ -321,7 +321,7 @@ jobs:
321321
- name: Build & push dashboard
322322
uses: docker/build-push-action@v6
323323
with:
324-
context: ./dashboard
324+
context: .
325325
file: ./dashboard/Dockerfile
326326
push: true
327327
platforms: linux/amd64,linux/arm64

dashboard/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ WORKDIR /src
55

66
# Copy source
77
COPY . .
8-
# Restore
9-
RUN dotnet restore dashboard/Dashboard.csproj
10-
# Publish
11-
RUN dotnet publish dashboard/Dashboard.csproj -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
8+
# Restore and publish using robust path detection to support different build contexts
9+
WORKDIR /src
10+
RUN if [ -f "Dashboard.csproj" ]; then dotnet restore Dashboard.csproj; else dotnet restore dashboard/Dashboard.csproj; fi
11+
RUN if [ -f "Dashboard.csproj" ]; then dotnet publish Dashboard.csproj -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false; else dotnet publish dashboard/Dashboard.csproj -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false; fi
1212

1313
# Runtime stage
1414
FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim AS final

hub/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
33
WORKDIR /src
44
# Copy source
55
COPY . .
6-
# Restore using the hub project
7-
RUN dotnet restore hub/PlaywrightHub.csproj
8-
# Publish the hub project
9-
RUN dotnet publish hub/PlaywrightHub.csproj -c Release -o /app/publish
6+
# Restore and publish using robust path detection to support different build contexts
7+
WORKDIR /src
8+
RUN if [ -f "PlaywrightHub.csproj" ]; then dotnet restore PlaywrightHub.csproj; else dotnet restore hub/PlaywrightHub.csproj; fi
9+
RUN if [ -f "PlaywrightHub.csproj" ]; then dotnet publish PlaywrightHub.csproj -c Release -o /app/publish; else dotnet publish hub/PlaywrightHub.csproj -c Release -o /app/publish; fi
1010

1111
# Runtime stage
1212
FROM mcr.microsoft.com/dotnet/aspnet:8.0

worker/Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ WORKDIR /src
44

55
# Copy source
66
COPY . .
7-
# Restore
8-
RUN dotnet restore worker/WorkerService.csproj
9-
# Publish
10-
RUN dotnet publish worker/WorkerService.csproj -c Release -o /app/publish
7+
# Restore and publish using robust path detection to support different build contexts
8+
WORKDIR /src
9+
RUN if [ -f "WorkerService.csproj" ]; then dotnet restore WorkerService.csproj; else dotnet restore worker/WorkerService.csproj; fi
10+
RUN if [ -f "WorkerService.csproj" ]; then dotnet publish WorkerService.csproj -c Release -o /app/publish; else dotnet publish worker/WorkerService.csproj -c Release -o /app/publish; fi
1111

1212

1313
# ---------- Runtime stage ----------

0 commit comments

Comments
 (0)