@@ -14,61 +14,161 @@ jobs:
14
14
steps :
15
15
- name : Checkout Repository
16
16
uses : actions/checkout@v4
17
-
18
- - name : Restore Cached Image TAR
19
- uses : actions/cache@v4
20
17
with :
21
- path : cache-image.tar
22
- key : docker-image-${{ runner.os }}-${{ github.sha }}
23
- restore-keys : |
24
- docker-image-${{ runner.os }}-
25
-
26
- - name : Load Cached Image
27
- shell : pwsh
28
- id : load_cache
29
- run : |
30
- if (Test-Path cache-image.tar) {
31
- docker load -i cache-image.tar
32
- echo "CACHE_HIT=true" >> $env:GITHUB_ENV
33
- }
18
+ fetch-depth : 1
34
19
35
- - name : Build Image Without Cache
36
- if : env.CACHE_HIT != 'true'
20
+ - name : Setup environment
37
21
shell : pwsh
38
22
run : |
39
- docker build -t app:latest .
40
-
41
- - name : Save Docker Image to TAR
42
- if : env.CACHE_HIT != 'true'
43
- shell : pwsh
44
- run : |
45
- docker save -o cache-image.tar app:latest
46
-
47
- - name : Cache Image TAR
48
- if : env.CACHE_HIT != 'true'
49
- uses : actions/cache@v4
23
+ Set-MpPreference -DisableRealtimeMonitoring $true
24
+ - name : Restore BuildKit Cache
25
+ uses : actions/cache/restore@v4
26
+ id : restore-buildkit-cache
27
+ with :
28
+ path : |
29
+ buildkit
30
+ key : buildkit-${{ runner.os }}-
31
+ restore-keys : |
32
+ buildkit-${{ runner.os }}-
33
+ - name : Restore Daemon Cache
34
+ uses : actions/cache/restore@v4
35
+ id : restore-droot-cache
50
36
with :
51
- path : cache-image.tar
52
- key : docker-image-${{ runner.os }}-${{ github.sha }}
37
+ path : |
38
+ droot
39
+ key : droot-${{ runner.os }}-
53
40
restore-keys : |
54
- docker-image-${{ runner.os }}-
41
+ droot-${{ runner.os }}-
42
+ - name : Log in to Container Registry
43
+ uses : docker/login-action@v3
44
+ with :
45
+ registry : dr-private.devsh.eu
46
+ username : ${{ secrets.DOCKER_USERNAME }}
47
+ password : ${{ secrets.DOCKER_PASSWORD }}
55
48
56
- - name : Run Nano Container
49
+ - name : Setup buildkit
57
50
shell : pwsh
58
51
run : |
59
- docker run -di --name orphan -v "${{ github.workspace }}:C:\app" app:latest
60
-
61
- - name : Nano Container - Configure CMake Project
52
+ if (-Not (Test-Path "buildkit")) {
53
+ Write-Host "📂 'buildkit' directory not found. Downloading and extracting daemons..."
54
+ New-Item -ItemType Directory -Path "buildkit" -Force
55
+ Invoke-WebRequest -Uri "https://github.com/moby/buildkit/releases/download/v0.20.1/buildkit-v0.20.1.windows-amd64.tar.gz" -OutFile "buildkit.tar.gz"
56
+ tar -xf buildkit.tar.gz -C buildkit
57
+
58
+ Invoke-WebRequest -Uri "https://github.com/containerd/containerd/releases/download/v2.0.4/containerd-2.0.4-windows-amd64.tar.gz" -OutFile "containerd.tar.gz"
59
+ tar -xf containerd.tar.gz -C buildkit
60
+ } else {
61
+ Write-Host "✅ 'buildkit' directory already exists. Skipping download."
62
+ }
63
+ .\cni\setup-nat.ps1
64
+ New-Item -ItemType Directory -Path "buildkit/logs" -Force
65
+ $Bin = "${{ github.workspace }}\buildkit\bin"
66
+ echo "PATH=$Bin;$env:PATH" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
67
+ - name : Run daemons
62
68
shell : pwsh
69
+ run : |
70
+ function Wait-For {
71
+ param (
72
+ [string]$Command,
73
+ [int]$TickWait = 1,
74
+ [int]$TotalTicks = 5
75
+ )
76
+
77
+ Write-Host "⏳ Waiting for command.. (Max retries: $TotalTicks, Interval: ${TickWait}s)"
78
+
79
+ for ($i=1; $i -le $TotalTicks; $i++) {
80
+ Write-Host "⏳ [$i/$TotalTicks]: $Command"
81
+ if (Invoke-Expression $Command) {
82
+ Write-Host "✅ Success!"
83
+ return $true
84
+ }
85
+ Start-Sleep -Seconds $TickWait
86
+ }
87
+
88
+ Write-Error "❌ Timeout: $Command did not succeed!"
89
+ exit 1
90
+ }
91
+ $logs = "buildkit/logs"
92
+ $cni = "${{ github.workspace }}\buildkit\cni"
93
+ $droot = "${{ github.workspace }}\droot"
94
+ Start-Job -ScriptBlock {
95
+ param($logs, $droot)
96
+ Start-Process containerd.exe `
97
+ -ArgumentList @("--root=$droot\containerd") `
98
+ -RedirectStandardOutput "$logs/containerd.log" `
99
+ -RedirectStandardError "$logs/containerd_error.log" `
100
+ -NoNewWindow -PassThru
101
+ } -ArgumentList $logs, $droot
102
+ Wait-For "ctr --namespace buildkit image ls"
103
+ Start-Job -ScriptBlock {
104
+ param($logs, $cni, $droot)
105
+ Start-Process buildkitd.exe `
106
+ -ArgumentList @("--containerd-cni-config-path=$cni\0-containerd-nat.conf",
107
+ "--containerd-cni-binary-dir=$cni", `
108
+ "--root=$droot\buildkitd") `
109
+ -RedirectStandardOutput "$logs/buildkitd.log" `
110
+ -RedirectStandardError "$logs/buildkitd_error.log" `
111
+ -NoNewWindow -PassThru
112
+ } -ArgumentList $logs, $cni, $droot
113
+ Wait-For "buildctl du"
114
+ - name : Build base image
115
+ shell : cmd
63
116
run : |
64
- docker exec -w "C:\app\tests" -i orphan cmd /c cmake --preset configure-msvc-winsdk
65
-
66
- - name : Nano Container - Build the Project
117
+ buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. ^
118
+ --output=type=image,name=dr-private.devsh.eu/actions/cache/nano/base,push=true ^
119
+ --export-cache=type=inline ^
120
+ --import-cache=type=registry,ref=dr-private.devsh.eu/actions/cache/nano/base ^
121
+ --opt target=buildtools
122
+ - name : Prune images
67
123
shell : pwsh
68
124
run : |
69
- docker exec -w "C:\app\tests" -i orphan cmd /c cmake --build --preset build-msvc-winsdk --config Release
70
-
71
- - name : Nano Container - Test the Project
125
+ buildctl prune
126
+ - name : Stop daemons
72
127
shell : pwsh
73
128
run : |
74
- docker exec -w "C:\app\tests\build\src" -i orphan cmd /c ctest -C Release --stop-on-failure --verbose
129
+ Write-Host "🔴 Stopping background jobs..."
130
+ if (Get-Job) {
131
+ Get-Job | Stop-Job -Force
132
+ Get-Job | Remove-Job -Force
133
+ Write-Host "✅ Background jobs stopped!"
134
+ } else {
135
+ Write-Host "⚠️ No background jobs found."
136
+ }
137
+ Write-Host "🔴 Stopping containerd and buildkitd..."
138
+ if (Get-Process -Name "containerd" -ErrorAction SilentlyContinue) {
139
+ Stop-Process -Name "containerd" -Force
140
+ Write-Host "✅ containerd stopped!"
141
+ } else {
142
+ Write-Host "⚠️ containerd is not running."
143
+ }
144
+
145
+ if (Get-Process -Name "buildkitd" -ErrorAction SilentlyContinue) {
146
+ Stop-Process -Name "buildkitd" -Force
147
+ Write-Host "✅ buildkitd stopped!"
148
+ } else {
149
+ Write-Host "⚠️ buildkitd is not running."
150
+ }
151
+ # - name: Build app image
152
+ # shell: cmd
153
+ # run: |
154
+ # buildctl build --frontend=dockerfile.v0 --local context=. --local dockerfile=. ^
155
+ # --output type=image,name=nano/app,push=false ^
156
+ # --export-cache type=local,dest=buildkit/.cache,mode=max ^
157
+ # --import-cache type=local,src=buildkit/.cache ^
158
+ # --opt target=nano
159
+
160
+ - name : Save BuildKit Cache
161
+ id : save-buildkit-cache
162
+ uses : actions/cache/save@v4
163
+ with :
164
+ path : |
165
+ buildkit
166
+ key : buildkit-${{ runner.os }}-
167
+
168
+ - name : Save Daemon Cache
169
+ id : save-droot-cache
170
+ uses : actions/cache/save@v4
171
+ with :
172
+ path : |
173
+ droot
174
+ key : droot-${{ runner.os }}-
0 commit comments