NET8 updates part 2 #35
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
# For build guidance only, this workflow does not publish to Dockerhub. | |
# See workflows/main_build-aspnetcore.yml for an example that builds and publishes an image to Docker Hub | |
name: Build Blazor Application | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
- "blazor/*" | |
paths: | |
- 'src/Blazor/**/*' | |
- '.github/workflows/main_build-blazor.yml' | |
jobs: | |
############################## | |
####### WINDOWS BUILD ######## | |
############################## | |
build_windows: | |
runs-on: windows-2022 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Restore NuGet Packages | |
run: | | |
# In this special case, we're using the nested nuget.config file (instead of src/nuget.config) | |
dotnet restore src\Blazor\MyBlazorApp\MyBlazorApp.csproj --configfile src\Blazor\MyBlazorApp\NuGet.Config --runtime win-x64 | |
dotnet restore src\Blazor\MyBlazorApp.Tests\MyBlazorApp.Tests.csproj --configfile src\Blazor\MyBlazorApp\NuGet.Config --runtime win-x64 | |
env: | |
TELERIK_USERNAME: ${{ secrets.MyTelerikAccountUsername }} | |
TELERIK_PASSWORD: ${{ secrets.MyTelerikAccountPassword }} | |
- name: Build Test Project | |
run: dotnet build src\Blazor\MyBlazorApp.Tests\MyBlazorApp.Tests.csproj --no-restore --configuration Release --runtime win-x64 | |
- name: Run Tests | |
run: dotnet test src\Blazor\MyBlazorApp.Tests\MyBlazorApp.Tests.csproj --runtime win-x64 | |
######################################### | |
####### .NET CONTAINER SDK BUILD ######## | |
######################################### | |
build_dotnet_container: | |
runs-on: windows-2022 | |
# For 'akeyless' step | |
permissions: | |
id-token: write | |
contents: read | |
env: | |
RID: linux-x64 | |
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 | |
IMAGE_NAME: "lancemccarthy/myblazorapp" | |
IMAGE_REGISTRY: "registry.hub.docker.com" | |
IMAGE_TAG: "latest" | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup .NET Core SDK | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: '8.0.x' | |
- name: Restore NuGet Packages | |
run: | | |
# In this special case, we're using the nested nuget.config file (instead of src/nuget.config) | |
dotnet restore ${{ env.BLAZOR_PROJ_PATH }}-configfile ${{ env.NUGET_CONFIG_PATH }} --runtime ${{ env.RID }} | |
dotnet restore ${{ env.TEST_PROJ_PATH }} --configfile ${{ env.NUGET_CONFIG_PATH }} --runtime ${{ env.RID }} | |
env: | |
TELERIK_USERNAME: ${{ secrets.MyTelerikAccountUsername }} | |
TELERIK_PASSWORD: ${{ secrets.MyTelerikAccountPassword }} | |
- name: Build Test Project | |
run: dotnet build ${{ env.TEST_PROJ_PATH }} --no-restore --configuration ${{ env.CONFIGURATION }} --runtime ${{ 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.IMAGE_REGISTRY }} -u ${{ steps.akeyless.outputs.DOCKER_HUB_USERNAME }} -p ${{ steps.akeyless.outputs.DOCKER_HUB_PAT }} | |
# Nice new feature of .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 }} --os linux --arch x64 -p PublishProfile=DefaultContainer -p ContainerRegistry=${{ env.IMAGE_REGISTRY }} -p ContainerImageName=${{ env.IMAGE_NAME }} -p ContainerImageTag=${{ env.IMAGE_BASE }} --no-build | |
################################### | |
####### DOCKER FILE BUILD ######### | |
################################### | |
build_docker_file: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Using GitHub Actions secrets, we can pass in the Telerik NuGet key to be mounted in the Dockerfile's commands | |
# NOTE: this demo does not push to Dockerhub. | |
# For a real world exapmple, see the ASP.NET Core Workflow at ~/.github/workflows/main_build-aspnetcore.yml | |
- name: Build Docker | |
uses: docker/build-push-action@v3 | |
with: | |
context: src/Blazor/MyBlazorApp | |
push: false | |
secrets: | | |
telerik_username=${{ secrets.MyTelerikAccountUsername }} | |
telerik_password=${{ secrets.MyTelerikAccountPassword }} | |
tags: | | |
lancemccarthy/myblazorapp:latest |