Skip to content

Commit 8aa9e76

Browse files
authored
Update main.yml, split into 2 jobs - first build and deploy to github container registry, then use by downstream project
1 parent f1fe3e7 commit 8aa9e76

File tree

1 file changed

+65
-81
lines changed

1 file changed

+65
-81
lines changed

.github/workflows/main.yml

Lines changed: 65 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,79 @@
11
name: NanoServer MSVC
22

33
on:
4-
push:
5-
branches:
6-
- docker-backwards
7-
schedule:
8-
- cron: '0 0 * * *'
94
workflow_dispatch:
105

6+
env:
7+
VS_BOOTSTRAP_VERSION: 17.13.6
8+
119
jobs:
12-
run-nanoserver-msvc-winsdk-x64-build:
13-
runs-on: windows-latest
14-
steps:
15-
- name: Checkout Repository
16-
uses: actions/checkout@v4
10+
build-and-push:
11+
runs-on: windows-2022
1712

18-
- name: Setup environment
19-
shell: pwsh
20-
run: |
21-
set-mppreference -ExclusionPath c:\
22-
set-mppreference -ExclusionExtension *.*
23-
set-mppreference -RemediationScheduleDay 8
24-
Set-MpPreference -DisableRealtimeMonitoring $true
25-
Set-MpPreference -DisableRemovableDriveScanning $true
26-
Set-MpPreference -DisableArchiveScanning $true
27-
Set-MpPreference -DisableScanningMappedNetworkDrivesForFullScan $true
28-
29-
- name: Restore Cached Image TAR
30-
uses: actions/cache@v4
31-
with:
32-
path: cache-image.tar
33-
key: docker-image-${{ runner.os }}-${{ github.sha }}
34-
restore-keys: |
35-
docker-image-${{ runner.os }}-
36-
37-
- name: Load Cached Image
38-
shell: pwsh
39-
id: load_cache
40-
run: |
41-
if (Test-Path cache-image.tar) {
42-
docker load -i cache-image.tar
43-
echo "CACHE_HIT=true" >> $env:GITHUB_ENV
44-
}
45-
46-
- name: Build Image
47-
if: env.CACHE_HIT != 'true'
48-
shell: pwsh
49-
run: |
50-
docker build --isolation process --build-arg "IMPL_COMPRESSION_OPTIONS=-T0 --ultra" --build-arg "IMPL_COMPRESSION_LEVEL=22" -t app:latest .
51-
52-
- name: Save Docker Image to TAR
53-
if: env.CACHE_HIT != 'true'
54-
shell: pwsh
55-
run: |
56-
docker save -o cache-image.tar app:latest
57-
58-
- name: Cache Image TAR
59-
if: env.CACHE_HIT != 'true'
60-
uses: actions/cache@v4
61-
with:
62-
path: cache-image.tar
63-
key: docker-image-${{ runner.os }}-${{ github.sha }}
64-
restore-keys: |
65-
docker-image-${{ runner.os }}-
66-
67-
- name: Run Nano Container
68-
shell: pwsh
69-
run: |
70-
docker run --isolation process -di --name orphan app:latest
13+
outputs:
14+
image_tagged: ${{ steps.vars.outputs.image_tagged }}
7115

72-
- name: Inspect Nano Container
16+
defaults:
17+
run:
7318
shell: pwsh
74-
run: |
75-
docker inspect orphan
7619

77-
- name: Nano Container - Unpack Artifacts
78-
shell: pwsh
79-
run: |
80-
docker exec orphan pwsh -c "C:\unpack.ps1"
20+
steps:
21+
- name: Checkout Repository
22+
uses: actions/checkout@v4
8123

82-
- name: Nano Container - Configure CMake Project
83-
shell: pwsh
84-
run: |
85-
docker exec orphan cmake --preset configure-msvc-winsdk
24+
- name: Set image tag
25+
id: vars
26+
run: |
27+
$repo = $env:GITHUB_REPOSITORY.ToLower()
28+
$imageBase = "ghcr.io/$repo"
29+
$taggedImage = "${imageBase}:${env:VS_BOOTSTRAP_VERSION}"
30+
"image_tagged=$taggedImage" >> $env:GITHUB_OUTPUT
8631
87-
- name: Nano Container - Build the Project
88-
shell: pwsh
89-
run: |
90-
docker exec orphan cmake --build --preset build-msvc-winsdk --config Release -- -j 14
32+
- name: Log in to GHCR
33+
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u $env:GITHUB_ACTOR --password-stdin
34+
35+
- name: Build Image
36+
run: |
37+
docker build `
38+
--isolation process `
39+
--build-arg "IMPL_COMPRESSION_OPTIONS=-T0 --ultra" `
40+
--build-arg "IMPL_COMPRESSION_LEVEL=22" `
41+
--build-arg "VS_BOOTSTRAP_VERSION=$env:VS_BOOTSTRAP_VERSION" `
42+
-t "${{ steps.vars.outputs.image_tagged }}" .
9143
92-
- name: Nano Container - Test the Project
44+
- name: Push Image
45+
run: |
46+
docker push "${{ steps.vars.outputs.image_tagged }}"
47+
48+
run-nano-container:
49+
needs: build-and-push
50+
runs-on: windows-2022
51+
52+
defaults:
53+
run:
9354
shell: pwsh
94-
run: |
95-
docker exec -w "C:\sample\tests\build-ct\src" orphan ctest -C Release --stop-on-failure --verbose
55+
56+
steps:
57+
- name: Log in to GHCR
58+
run: echo "${{ secrets.CR_PAT }}" | docker login ghcr.io -u $env:GITHUB_ACTOR --password-stdin
59+
60+
- name: Pull Image
61+
run: docker pull "${{ needs.build-and-push.outputs.image_tagged }}"
62+
63+
- name: Run Nano Container
64+
run: docker run --isolation process -di --name orphan "${{ needs.build-and-push.outputs.image_tagged }}"
65+
66+
- name: Inspect Nano Container
67+
run: docker inspect orphan
68+
69+
- name: Nano Container - Unpack Artifacts
70+
run: docker exec orphan pwsh -c "C:\unpack.ps1"
71+
72+
- name: Nano Container - Configure CMake Project
73+
run: docker exec orphan cmake --preset configure-msvc-winsdk
74+
75+
- name: Nano Container - Build the Project
76+
run: docker exec orphan cmake --build --preset build-msvc-winsdk --config Release -- -j 14
77+
78+
- name: Nano Container - Test the Project
79+
run: docker exec -w "C:\sample\tests\build-ct\src" orphan ctest -C Release --stop-on-failure --verbose

0 commit comments

Comments
 (0)