-
Notifications
You must be signed in to change notification settings - Fork 21
197 lines (165 loc) · 6.78 KB
/
main_build-aspnetcore.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# This example has two container build & publish examples
# [Option A] DOCKER FILE BUILD - publishes the image to Docker Hub
# [Option B] .NET SDK CONTAINER BUILD - publishes the image to ghcr.io (GitHub container registry)
name: ASP.NET Core (with Reporting)
on:
workflow_dispatch:
push:
branches:
- main
- "aspnetcore/*"
paths:
- 'src/AspNetCore/**/*'
- '.github/workflows/main_build-aspnetcore.yml'
env:
CONTAINER_BASE_IMAGE: "mcr.microsoft.com/dotnet/aspnet:9.0"
WORKING_DIRECTORY: "src/AspNetCore/MyAspNetCoreApp"
DOTNET_VERSION: "9.0.x"
jobs:
##############################################
######## [Option A] DOCKER FILE BUILD ########
##############################################
# => Publishes to registry.hub.docker.com <= #
# A job that containerizes an ASP.NET Core web app with Relerik Reporting REST service and publish to Docker Hub
build_aspnetcore:
runs-on: ubuntu-22.04
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Getting all my secrets from AKeyless is a personal choice, you can use GitHub Actions secrets instead.
- name: Fetch secrets from AKeyless
id: akeyless
uses: LanceMcCarthy/akeyless-action@v3
with:
access-id: ${{secrets.AKEYLESS_JWT_ID}}
static-secrets: '{"/personal-keys/mccarthy/TELERIK_NUGET_KEY":"TELERIK_NUGET_KEY", "/personal-keys/mccarthy/DOCKER_HUB_USERNAME":"DOCKER_HUB_USERNAME", "/personal-keys/mccarthy/DOCKER_HUB_PAT":"DOCKER_HUB_PAT"}'
export-secrets-to-outputs: true
export-secrets-to-environment: false
- name: Create Kendo license file in the appropriate project directory
run: |
cd src/AspNetCore/MyAspNetCoreApp/wwwroot/js
echo ${{steps.akeyless.outputs.KENDO_LICENSE_FILE}} > kendo-ui-license.js
- name: Verify tag output
run: echo ${{steps.tag-creator.outputs.DOCKER_HUB_TAG}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Get package metadata from Docker Hub
id: meta
uses: docker/metadata-action@v5
with:
images: lancemccarthy/myaspnetcoreapp
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{steps.akeyless.outputs.DOCKER_HUB_USERNAME}}
password: ${{steps.akeyless.outputs.DOCKER_HUB_PAT}}
- name: Build and push to Docker Hub
uses: docker/build-push-action@v5
with:
context: ${{env.WORKING_DIRECTORY}}
platforms: linux/arm64,linux/amd64
push: true
secrets: |
telerik_key=${{steps.akeyless.outputs.TELERIK_NUGET_KEY}}
tags: |
lancemccarthy/myaspnetcoreapp:latest
##########################################################
######### [Option B] .NET SDK CONTAINER BUILD ############
##########################################################
# => Publishes to ghcr.io (GitHub container registry) <= #
build_x64:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
outputs:
build_tag: ${{steps.build.outputs.build_tag}}
env:
target_arch: "x64"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{env.DOTNET_VERSION}}
- name: Login to GitHub Container Registry
run: docker login ghcr.io -u ${{github.actor}} -p ${{secrets.GITHUB_TOKEN}}
- name: Restore NuGet Packages
working-directory: ${{env.WORKING_DIRECTORY}}
run: dotnet restore -r "linux-${{env.target_arch}}" --configfile "../../NuGet.Config"
env:
TELERIK_USERNAME: ${{secrets.MyTelerikAccountUsername}}
TELERIK_PASSWORD: ${{secrets.MyTelerikAccountPassword}}
- name: build the x64 image
id: build
working-directory: ${{env.WORKING_DIRECTORY}}
run: |
TAG="latest-${{env.target_arch}}"
# Build and publish arch-specific container
dotnet publish -t:PublishContainer -p PublishProfile=DefaultContainer --arch ${{env.target_arch}} -p ContainerImageTag="$TAG" -p ContainerRepository="lancemccarthy/myaspnetcoreapp" -p ContainerRegistry="ghcr.io" -p ContainerBaseImage=${{env.CONTAINER_BASE_IMAGE}} --no-restore
# Job output the arch-specific container name so we can publish a multi-arch image later
echo "build_tag=$TAG" >> $GITHUB_OUTPUT
build_arm64:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write
outputs:
build_tag: ${{steps.build.outputs.build_tag}}
env:
target_arch: "arm64"
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{env.DOTNET_VERSION}}
- name: Login to GitHub Container Registry
run: docker login ghcr.io -u ${{github.actor}} -p ${{secrets.GITHUB_TOKEN}}
- name: Restore NuGet Packages
working-directory: ${{env.WORKING_DIRECTORY}}
run: dotnet restore -r "linux-${{env.target_arch}}" --configfile "../../NuGet.Config"
env:
TELERIK_USERNAME: ${{secrets.MyTelerikAccountUsername}}
TELERIK_PASSWORD: ${{secrets.MyTelerikAccountPassword}}
- name: build the arm64 image
id: build
working-directory: ${{env.WORKING_DIRECTORY}}
run: |
TAG="latest-${{env.target_arch}}"
# Build and publish arch-specific container
dotnet publish -t:PublishContainer -p PublishProfile=DefaultContainer --arch ${{env.target_arch}} -p ContainerImageTag="$TAG" -p ContainerRepository="lancemccarthy/myaspnetcoreapp" -p ContainerRegistry="ghcr.io" -p ContainerBaseImage=${{env.CONTAINER_BASE_IMAGE}} --no-restore
# Job output the arch-specific container name so we can publish a multi-arch image later
echo "build_tag=$TAG" >> $GITHUB_OUTPUT
publish_combined_manifest:
runs-on: ubuntu-22.04
needs: [build_x64, build_arm64]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Login to GitHub Container Registry
run: docker login ghcr.io -u ${{github.actor}} -p ${{secrets.GITHUB_TOKEN}}
- name: create the multi-image manifest
run: |
docker manifest create "ghcr.io/lancemccarthy/myaspnetcoreapp:latest" \
"ghcr.io/lancemccarthy/myaspnetcoreapp:$X86_TAG" \
"ghcr.io/lancemccarthy/myaspnetcoreapp:$ARM64_TAG"
docker manifest push "ghcr.io/lancemccarthy/myaspnetcoreapp:latest"
env:
X86_TAG: ${{needs.build_x64.outputs.build_tag}}
ARM64_TAG: ${{needs.build_arm64.outputs.build_tag}}