More Q3 2024 updates #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This example has two container build & publish examples | |
# The ".NET CONTAINER SDK BUILD" job publishes the container to registry.hub.docker.com | |
# The "DOCKER FILE BUILD" job publishes the container to ghcr.io (GitHub container registry) | |
name: Build Blazor Application | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- "blazor/*" | |
paths: | |
- 'src/Blazor/**/*' | |
- '.github/workflows/main_build-blazor.yml' | |
env: | |
CONFIGURATION: Release | |
BLAZOR_PROJ_PATH: src/Blazor/MyBlazorApp/MyBlazorApp.csproj | |
TEST_PROJ_PATH: src/Blazor/MyBlazorApp.Tests/MyBlazorApp.Tests.csproj | |
NUGET_CONFIG_PATH: src/Blazor/MyBlazorApp/NuGet.Config | |
jobs: | |
############################## | |
####### WINDOWS BUILD ######## | |
############################## | |
build_windows: | |
runs-on: windows-2022 | |
env: | |
RID: win-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: '8.0.x' | |
- name: Restore NuGet Packages | |
run: | | |
${{env.BLAZOR_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}} | |
dotnet restore ${{env.TEST_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}} | |
env: | |
TELERIK_USERNAME: ${{secrets.MyTelerikAccountUsername}} | |
TELERIK_PASSWORD: ${{secrets.MyTelerikAccountPassword}} | |
- name: Build Test Project | |
run: dotnet build ${{env.TEST_PROJ_PATH}} -c ${{env.CONFIGURATION}} -r ${{env.RID}} --no-restore | |
- name: Run Tests | |
run: dotnet test ${{env.TEST_PROJ_PATH}} -r ${{env.RID}} | |
############################################# | |
######## .NET CONTAINER SDK BUILD ########### | |
############################################# | |
# => Publishes to registry.hub.docker.com <= # | |
build_container_with_dotnet: | |
runs-on: ubuntu-22.04 | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
RID: linux-x64 | |
CONTAINER_BASE_IMAGE: "mcr.microsoft.com/dotnet/aspnet:8.0" | |
CONTAINER_IMAGE_NAME: "lancemccarthy/myblazorapp" | |
CONTAINER_IMAGE_REGISTRY: "registry.hub.docker.com" | |
CONTAINER_RID: "linux-x64" | |
CONTAINER_ARCH: "x64" | |
CONTAINER_OS: "linux" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Restore NuGet Packages | |
run: | | |
# In this special case, we're using the project's nested nuget.config file (instead of the global src/nuget.config) | |
dotnet restore ${{env.BLAZOR_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}} | |
dotnet restore ${{env.TEST_PROJ_PATH}} --configfile ${{env.NUGET_CONFIG_PATH}} -r ${{env.RID}} | |
env: | |
TELERIK_USERNAME: ${{secrets.MyTelerikAccountUsername}} | |
TELERIK_PASSWORD: ${{secrets.MyTelerikAccountPassword}} | |
- name: Build Unit Test Project | |
run: dotnet build ${{env.TEST_PROJ_PATH}} -c ${{env.CONFIGURATION}} -r ${{env.RID}} --no-restore | |
- name: Run Unit Tests | |
run: dotnet test ${{env.TEST_PROJ_PATH}} -r ${{env.RID}} | |
- name: Fetch secrets from AKeyless | |
id: akeyless | |
uses: LanceMcCarthy/akeyless-action@v3 | |
with: | |
access-id: ${{ secrets.AKEYLESS_JWT_ID }} | |
static-secrets: '{"/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: Login to Docker Hub | |
run: docker login ${{env.CONTAINER_IMAGE_REGISTRY}} -u ${{steps.akeyless.outputs.DOCKER_HUB_USERNAME}} -p ${{steps.akeyless.outputs.DOCKER_HUB_PAT}} | |
# Build and publish the Container build and publish with.NET https://learn.microsoft.com/en-us/dotnet/core/docker/publish-as-container | |
- name: Publish Blazor Project to Docker Hub | |
run: dotnet publish ${{env.BLAZOR_PROJ_PATH}} -c ${{env.CONFIGURATION}} --no-build --os ${{env.CONTAINER_OS}} --arch ${{env.CONTAINER_ARCH}} -p PublishProfile=DefaultContainer -p ContainerRuntimeIdentifier=${{env.CONTAINER_RID}} -p ContainerRegistry=${{env.CONTAINER_IMAGE_REGISTRY}} -p ContainerRepository=${{env.CONTAINER_IMAGE_NAME}} -p ContainerImageTag="latest" -p ContainerBaseImage=${{env.CONTAINER_BASE_IMAGE}} | |
############################################## | |
############ DOCKER FILE BUILD ############### | |
############################################## | |
# => Publishes to ghcr.io (GitHub container registry) <= # | |
build_container_with_dockerfile: | |
runs-on: ubuntu-22.04 | |
permissions: | |
contents: read | |
packages: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate tag version | |
id: tag-creator | |
run: | | |
buildDay=`date +%Y.%m.%d` | |
tags="$buildDay.$GITHUB_RUN_NUMBER" | |
echo "VERSION_TAG=$tags" >> $GITHUB_OUTPUT | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to ghcr.io | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{github.actor}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- name: Build and Publish Container Images | |
uses: docker/build-push-action@v5 | |
with: | |
context: src/Blazor/MyBlazorApp | |
platforms: linux/arm64,linux/amd64,linux/arm | |
push: true | |
secrets: | | |
telerik_username=${{secrets.MyTelerikAccountUsername}} | |
telerik_password=${{secrets.MyTelerikAccountPassword}} | |
tags: | | |
"ghcr.io/lancemccarthy/myblazorapp:${{steps.tag-creator.outputs.VERSION_TAG}}" | |
"ghcr.io/lancemccarthy/myblazorapp:latest" |