Skip to content

Commit

Permalink
Sample project showing using a custom base image (#14)
Browse files Browse the repository at this point in the history
* sample project showing using a custom base image

* fix TFMs for latest stable release

* fix working directory

* Don't forget the actual code!

* Add skia demo to sample

* use the new image to prove it works

* use writable dir

* fix warnings
  • Loading branch information
baronfel authored May 8, 2024
1 parent 69329b5 commit 9ed3f8b
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/aot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get the code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: build the app AOT-style
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/containerize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -40,7 +40,7 @@ jobs:

environment: production
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:

environment: production
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
name: GitHub Package Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -134,7 +134,7 @@ jobs:
env:
SDK_CONTAINER_REGISTRY_CHUNKED_UPLOAD: true
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -151,7 +151,7 @@ jobs:
name: AWS ECR (Private)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -177,7 +177,7 @@ jobs:
name: AWS ECR (Private) with Docker Credential Helper
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -206,7 +206,7 @@ jobs:
name: AWS ECR (Public)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
name: GitLab Container Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -254,7 +254,7 @@ jobs:
name: Google Cloud Artifact Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -276,7 +276,7 @@ jobs:
name: Local Docker Daemon
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -295,7 +295,7 @@ jobs:
name: Local Docker Daemon, Chiseled Ubuntu container
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -316,7 +316,7 @@ jobs:
name: Local Podman installation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -335,7 +335,7 @@ jobs:
name: Push to Docker hub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -355,7 +355,7 @@ jobs:
name: Push to Quay.io
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -377,7 +377,7 @@ jobs:
# harbor is disabled because we don't have a persistent account/location to push to
if: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET SDK
uses: actions/setup-dotnet@v2
Expand All @@ -397,7 +397,7 @@ jobs:
name: Build Dockerfile as a comparison
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: publish self-contained
uses: docker/build-push-action@v4
Expand All @@ -417,7 +417,7 @@ jobs:
name: Publish an image to a local archive and read it in
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v3
- name: Publish container to an archive
Expand Down
82 changes: 82 additions & 0 deletions .github/workflows/custom-base-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Custom Base Image Example

on:
push:
workflow_dispatch:

env:
GITHUB_USERNAME: baronfel
BASE_IMAGE: "ghcr.io/baronfel/dotnet-runtime-skia-base-image:8.0"
IMAGE_NAME: baronfel/skia-app
IMAGE_TAG: "8.0"

jobs:
create-base-image:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get the code
uses: actions/checkout@v4

- name: Build the base image
working-directory: src/custom-base-image
run: |
docker build -t ${{ env.BASE_IMAGE }} -f Dockerfile .
docker push ${{ env.BASE_IMAGE }}
use-base-image:
needs: create-base-image
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get .NET
uses: actions/setup-dotnet@v4

- name: Get the code
uses: actions/checkout@v4

- name: Build and publish the app
working-directory: src/custom-base-image
run: |
dotnet publish -t:PublishContainer \
-p ContainerBaseImage="${{ env.BASE_IMAGE }}" \
-p ContainerRepository="${{ env.IMAGE_NAME}}" \
-p ContainerImageTag="${{ env.IMAGE_TAG }}" \
-p ContainerRegistry=ghcr.io
run-the-image:
needs: use-base-image
permissions:
contents: read
packages: write
runs-on: ubuntu-latest

steps:
- name: Login to ghcr.io
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Execute the container
run: |
docker run --pull missing --rm ghcr.io/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
2 changes: 1 addition & 1 deletion .github/workflows/msbuild-versioning-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get .NET
uses: actions/setup-dotnet@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/multi-arch-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get .NET
uses: actions/setup-dotnet@v4
Expand Down
6 changes: 0 additions & 6 deletions global.json

This file was deleted.

Binary file removed pkg/Microsoft.NET.Build.Containers.8.0.100-dev.nupkg
Binary file not shown.
7 changes: 7 additions & 0 deletions sdk-container-demo.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "multi-arch-sample", "src\mu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "msbuild-versioning-sample", "src\msbuild-versioning-sample\msbuild-versioning-sample.csproj", "{70CED231-4FA2-4F47-8069-5C091C2895E9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "custom-base-image", "src\custom-base-image\custom-base-image.csproj", "{F3CB2379-3249-460B-911A-70BEF33840FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -38,11 +40,16 @@ Global
{70CED231-4FA2-4F47-8069-5C091C2895E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{70CED231-4FA2-4F47-8069-5C091C2895E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{70CED231-4FA2-4F47-8069-5C091C2895E9}.Release|Any CPU.Build.0 = Release|Any CPU
{F3CB2379-3249-460B-911A-70BEF33840FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F3CB2379-3249-460B-911A-70BEF33840FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F3CB2379-3249-460B-911A-70BEF33840FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F3CB2379-3249-460B-911A-70BEF33840FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2D5E802C-0E59-4027-B4AD-B6BB9B2DDCA9} = {0F9FBE5F-DFCF-4AD3-B33E-62F676243120}
{D8C6E9FD-F698-42D1-B1D7-7CCECF45A66D} = {0F9FBE5F-DFCF-4AD3-B33E-62F676243120}
{618B480D-55B9-4550-BE86-8B83D5298C9F} = {0F9FBE5F-DFCF-4AD3-B33E-62F676243120}
{70CED231-4FA2-4F47-8069-5C091C2895E9} = {0F9FBE5F-DFCF-4AD3-B33E-62F676243120}
{F3CB2379-3249-460B-911A-70BEF33840FD} = {0F9FBE5F-DFCF-4AD3-B33E-62F676243120}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions src/custom-base-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM mcr.microsoft.com/dotnet/runtime:8.0 as base

RUN apt-get update && apt-get install -y \
libfreetype6 \
libfontconfig1 \
&& rm -rf /var/lib/apt/lists/*
Loading

0 comments on commit 9ed3f8b

Please sign in to comment.