Last active
January 30, 2025 17:37
-
-
Save lbussell/e54483958fe6f1ccb8a44b0a07c296f5 to your computer and use it in GitHub Desktop.
Install additional slices on Ubuntu Chisel base image
This file contains hidden or 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
| ARG CHISEL_VERSION=1.1.0 | |
| ARG DOTNET_DOCKER_COMMIT=cb2823a1d974bd0d1d0c513e8f7ace29b2b0d22c | |
| ARG TARGETARCH | |
| # chisel uses chisel to create a new base image | |
| FROM amd64/buildpack-deps:noble-curl AS chisel | |
| ARG CHISEL_VERSION | |
| RUN apt-get update && apt-get install -y file | |
| RUN chisel_url=https://github.com/canonical/chisel/releases/download/v${CHISEL_VERSION}/chisel_v${CHISEL_VERSION}_linux_amd64.tar.gz \ | |
| && curl -fSLOJ ${chisel_url} \ | |
| && curl -fSL ${chisel_url}.sha384 | sha384sum -c - \ | |
| && tar -xzf chisel_v${CHISEL_VERSION}_linux_amd64.tar.gz -C /usr/bin/ chisel \ | |
| && curl -fSL --output /usr/bin/chisel-wrapper https://raw.githubusercontent.com/canonical/rocks-toolbox/v1.1.2/chisel-wrapper \ | |
| && chmod 755 /usr/bin/chisel-wrapper | |
| # construct the new base image with additional packages | |
| COPY --from=mcr.microsoft.com/dotnet/nightly/runtime-deps:10.0-preview-noble-chiseled / /rootfs/ | |
| # install ICU and tzdata | |
| RUN chisel-wrapper --generate-dpkg-status /new-dpkg-status -- \ | |
| --release ubuntu-24.04 --root /rootfs/ \ | |
| libicu74_libs \ | |
| tzdata-legacy_zoneinfo \ | |
| tzdata_zoneinfo \ | |
| && cat /new-dpkg-status >> /rootfs/var/lib/dpkg/status | |
| # build creates and builds a sample .NET app | |
| FROM mcr.microsoft.com/dotnet/nightly/sdk:10.0-preview-noble AS build | |
| ARG TARGETARCH | |
| ARG DOTNET_DOCKER_COMMIT | |
| # set up a sample app that will test globalization functionality | |
| RUN dotnet new console -n App -f net10.0 -o /src --no-restore \ | |
| && curl -fSL --output /src/Program.cs https://raw.githubusercontent.com/dotnet/dotnet-docker/${DOTNET_DOCKER_COMMIT}/tests/Microsoft.DotNet.Docker.Tests/TestAppArtifacts/GlobalizationTest.cs \ | |
| && curl -fSL --output /src/NuGet.config https://raw.githubusercontent.com/dotnet/dotnet-docker/${DOTNET_DOCKER_COMMIT}/tests/Microsoft.DotNet.Docker.Tests/TestAppArtifacts/NuGet.config.nightly | |
| WORKDIR /src | |
| RUN dotnet publish -r linux-$TARGETARCH --self-contained=true -o /app | |
| # final contains the app | |
| FROM scratch AS final | |
| # unset the DOTNET_SYSTEM_GLOBALIZATION_INVARIANT environment variable to enable globalization | |
| ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT= | |
| # copy the base image | |
| COPY --from=chisel /rootfs / | |
| COPY --from=build /app /app/ | |
| ENTRYPOINT ["/app/App"] |
This file contains hidden or 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 method is less efficient, but just serves as a demonstration that it's possible. | |
| # Chisel could do better to de-duplicate or not overwrite files when performing a second installation on the same filesystem. | |
| ARG CHISEL_VERSION=1.1.0 | |
| ARG DOTNET_DOCKER_COMMIT=cb2823a1d974bd0d1d0c513e8f7ace29b2b0d22c | |
| ARG TARGETARCH | |
| # chisel uses chisel to create a new base image | |
| FROM amd64/buildpack-deps:noble-curl AS chisel | |
| ARG CHISEL_VERSION | |
| RUN apt-get update && apt-get install -y file | |
| RUN chisel_url=https://github.com/canonical/chisel/releases/download/v${CHISEL_VERSION}/chisel_v${CHISEL_VERSION}_linux_amd64.tar.gz \ | |
| && curl -fSLOJ ${chisel_url} \ | |
| && curl -fSL ${chisel_url}.sha384 | sha384sum -c - \ | |
| && tar -xzf chisel_v${CHISEL_VERSION}_linux_amd64.tar.gz -C /usr/bin/ chisel | |
| # build creates and builds a sample .NET app | |
| FROM mcr.microsoft.com/dotnet/nightly/sdk:10.0-preview-noble AS build | |
| ARG TARGETARCH | |
| ARG DOTNET_DOCKER_COMMIT | |
| # set up a sample app that will test globalization functionality | |
| RUN dotnet new console -n App -f net10.0 -o /src --no-restore \ | |
| && curl -fSL --output /src/Program.cs https://raw.githubusercontent.com/dotnet/dotnet-docker/${DOTNET_DOCKER_COMMIT}/tests/Microsoft.DotNet.Docker.Tests/TestAppArtifacts/GlobalizationTest.cs \ | |
| && curl -fSL --output /src/NuGet.config https://raw.githubusercontent.com/dotnet/dotnet-docker/${DOTNET_DOCKER_COMMIT}/tests/Microsoft.DotNet.Docker.Tests/TestAppArtifacts/NuGet.config.nightly | |
| WORKDIR /src | |
| RUN dotnet publish -r linux-$TARGETARCH --self-contained=true -o /app | |
| # final contains the app | |
| FROM mcr.microsoft.com/dotnet/nightly/runtime-deps:10.0-preview-noble-chiseled AS final | |
| # install ICU and tzdata | |
| USER root | |
| RUN --mount=type=bind,from=chisel,source=/usr/bin/chisel,target=/usr/bin/chisel \ | |
| [ "/usr/bin/chisel", "cut", "--release", "ubuntu-24.04", "--root", "/", \ | |
| "libicu74_libs", \ | |
| "tzdata-legacy_zoneinfo", \ | |
| "tzdata_zoneinfo" ] | |
| USER $APP_UID | |
| # unset the DOTNET_SYSTEM_GLOBALIZATION_INVARIANT environment variable to enable globalization | |
| ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT= | |
| COPY --from=build /app /app/ | |
| ENTRYPOINT ["/app/App"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment