-
Notifications
You must be signed in to change notification settings - Fork 191
.NET 10: further align the runtime image with Microsoft images. #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,24 @@ ARG DOTNET_SDK_VERSION=10.0 | |
| ARG IS_CI | ||
| ARG DOTNET_TARBALL | ||
|
|
||
| ENV PATH=/opt/app-root/src/.local/bin:/opt/app-root/src/bin:/opt/app-root/.dotnet/tools:${PATH} \ | ||
| # Expose the port in case the SDK image is used as a base image through s2i. | ||
| EXPOSE 8080 | ||
|
|
||
| ENV \ | ||
| # Add s2i bin dirs and .NET tools dir to PATH | ||
| PATH=/opt/app-root/.dotnet/tools:/opt/app-root/src/.local/bin:/opt/app-root/src/bin:/opt/app-root/bin:${PATH} \ | ||
| # S2I | ||
| STI_SCRIPTS_PATH=/usr/libexec/s2i \ | ||
| DOTNET_APP_PATH=/opt/app-root/app \ | ||
| DOTNET_DEFAULT_CMD=default-cmd.sh \ | ||
| # Don't generate a developer certificate | ||
| DOTNET_GENERATE_ASPNET_CERTIFICATE=false \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Microsoft images also set DOTNET_ROLL_FORWARD.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems they do it in the SDK image because PowerShell (which is part of the MS SDK image) didn't roll forward. I think we can continue to leave it out. |
||
| # Don't download/extract docs for nuget packages | ||
| NUGET_XMLDOC_MODE=skip \ | ||
| # This skips the first time running text | ||
| DOTNET_NOLOGO=true \ | ||
| # Needed for the `dotnet watch` to detect changes in a container | ||
| DOTNET_USE_POLLING_FILE_WATCHER=true \ | ||
| # Like Microsoft images, provide the SDK version | ||
| DOTNET_SDK_VERSION=$DOTNET_SDK_VERSION | ||
|
|
||
|
|
@@ -31,26 +44,28 @@ LABEL name="ubi9/dotnet-100" \ | |
|
|
||
| # Switch to root for package installs | ||
| USER 0 | ||
| # Don't let root clutter the app user's HOME | ||
| ENV HOME= | ||
|
|
||
| # Each language image can have 'contrib' a directory with extra files needed to | ||
| # run and build the applications. | ||
| COPY ./contrib/ /opt/app-root | ||
| # Helper scripts the user can call | ||
| COPY ./root/usr/bin /usr/bin | ||
|
|
||
| # Copy the S2I scripts from the specific language image to $STI_SCRIPTS_PATH. | ||
| COPY ./s2i/bin/ /usr/libexec/s2i | ||
|
|
||
| # Install packages: | ||
| # - dotnet-sdk--*: provides the .NET SDK. | ||
| # - procps-ng: provides 'pidof' which is needed by the 'odo' Devfile to find the running 'dotnet' process. | ||
| # - findutils: provides 'find' which is used by the 'fix-permissions' script. | ||
| RUN [ -n "${DOTNET_TARBALL}" ] || ( \ | ||
| INSTALL_PKGS="dotnet-sdk-10.0 procps-ng" && \ | ||
| INSTALL_PKGS="dotnet-sdk-10.0 procps-ng findutils" && \ | ||
| microdnf install -y --setopt=tsflags=nodocs --setopt=install_weak_deps=0 $INSTALL_PKGS && \ | ||
| microdnf clean all -y && \ | ||
| # yum cache files may still exist (and quite large in size) | ||
| rm -rf /var/cache/yum/* ) | ||
| # Tarball install (in the runtime base image) | ||
| RUN [ -z "${DOTNET_TARBALL}" ] || ( \ | ||
| INSTALL_PKGS="procps-ng" && \ | ||
| INSTALL_PKGS="procps-ng findutils" && \ | ||
| microdnf install -y --setopt=tsflags=nodocs --setopt=install_weak_deps=0 $INSTALL_PKGS && \ | ||
| microdnf clean all -y && \ | ||
| # yum cache files may still exist (and quite large in size) | ||
|
|
@@ -64,24 +79,22 @@ RUN [ "$IS_CI" == "true" ] || ( \ | |
| printf "Checking SDK version ${DOTNET_SDK_VERSION} against:\n$(dotnet --list-sdks)" && \ | ||
| dotnet --list-sdks | grep "^${DOTNET_SDK_VERSION} " ) | ||
|
|
||
| # Directory with the sources is set as the working directory. | ||
| RUN mkdir /opt/app-root/src | ||
| WORKDIR /opt/app-root/src | ||
|
|
||
| # Build the container tool. | ||
| RUN /usr/libexec/s2i/container-tool build-tool | ||
|
|
||
| # Since $HOME is set to /opt/app-root, the yum install may have created config | ||
| # directories (such as ~/.pki/nssdb) there. These will be owned by root and can | ||
| # cause actions that work on all of /opt/app-root to fail. So we need to fix | ||
| # the permissions on those too. | ||
| RUN chown -R $APP_UID:0 /opt/app-root && fix-permissions /opt/app-root | ||
| # Run as the s2i assemble user | ||
| USER $APP_UID | ||
| # Set HOME for the random uid that runs the s2i app on OpenShift | ||
| ENV HOME=/opt/app-root | ||
|
|
||
| # Needed for the `dotnet watch` to detect changes in a container | ||
| ENV DOTNET_USE_POLLING_FILE_WATCHER=true | ||
| # Create s2i directories used for sources and published app | ||
| RUN mkdir -p /opt/app-root/src ${DOTNET_APP_PATH} | ||
|
|
||
| # Run container rootless. | ||
| USER $APP_UID | ||
| # Trigger first run to create .NET SDK dirs and config files under $HOME. | ||
| RUN dotnet help | ||
|
|
||
| # Fix permissions on HOME for the random uid that runs the s2i app on OpenShift | ||
| RUN fix-permissions /opt/app-root | ||
|
|
||
| # Set the default CMD to start a shell. | ||
| CMD /bin/bash | ||
| # Use the s2i dir for sources as the working dir | ||
| WORKDIR /opt/app-root/src | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,19 +5,9 @@ ARG DOTNET_VERSION=10.0 | |
| ARG IS_CI | ||
| ARG DOTNET_TARBALL | ||
|
|
||
| # This image provides a .NET 10.0 environment you can use to run your .NET | ||
| # applications. | ||
| EXPOSE 8080 | ||
|
|
||
| ENV HOME=/opt/app-root \ | ||
| PATH=/opt/app-root/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ | ||
| DOTNET_APP_PATH=/opt/app-root/app \ | ||
| DOTNET_DATA_PATH=/opt/app-root/data \ | ||
| DOTNET_DEFAULT_CMD=default-cmd.sh \ | ||
| ENV \ | ||
| # Microsoft's images set this to enable detecting when an app is running in a container. | ||
| DOTNET_RUNNING_IN_CONTAINER=true \ | ||
| # Don't download/extract docs for nuget packages | ||
| NUGET_XMLDOC_MODE=skip \ | ||
| # Configure ASP.NET Core to use the exposed port | ||
| ASPNETCORE_URLS=http://*:8080 \ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we drop ASPNETCORE_URLS too?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, maybe set ASPNETCORE_HTTP_PORTS like the Microsoft image does?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We adopted and reverted it for .NET 8: #474. I'm ok with changing to ASPNETCORE_HTTP_PORTS for .NET 10.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for that context. Given the regression and that we reverted it, I am okay with leaving it as it is. Up to you what you prefer here.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to merge this without changing ASPNETCORE_HTTP_PORTS. As time permits, I'll take a closer look into making this change for .NET 10 or not. |
||
| # Like Microsoft images, set APP_UID to the UID of the non-root user. | ||
|
|
@@ -39,13 +29,11 @@ LABEL name="ubi9/dotnet-100-runtime" \ | |
| dotnet_version_major_minor="10.0" \ | ||
| dotnet_version="$DOTNET_VERSION" | ||
|
|
||
| COPY ./root/usr/bin /usr/bin | ||
|
|
||
| # Install packages: | ||
| # - dotnet-runtime-*: provides the .NET shared framework. | ||
| # - findutils: provides 'find' which is used by the 'fix-permissions' script. | ||
| # - tar, gzip: enable installing vsdbg into the image for debugging. | ||
| RUN [ -n "${DOTNET_TARBALL}" ] || ( \ | ||
| INSTALL_PKGS="dotnet-runtime-10.0 findutils shadow-utils tar gzip" && \ | ||
| INSTALL_PKGS="dotnet-runtime-10.0 tar gzip" && \ | ||
| microdnf install -y --setopt=tsflags=nodocs --setopt=install_weak_deps=0 $INSTALL_PKGS && \ | ||
| # ubi-minimal doesn't include timezones, restore them. | ||
| ( microdnf reinstall tzdata -y || microdnf update tzdata -y ) && \ | ||
|
|
@@ -54,7 +42,7 @@ RUN [ -n "${DOTNET_TARBALL}" ] || ( \ | |
| rm -rf /var/cache/yum/* ) | ||
| # Add .NET from a tarball for CI/development. | ||
| RUN [ -z "${DOTNET_TARBALL}" ] || ( \ | ||
| microdnf install -y tar gzip unzip shadow-utils libicu && \ | ||
| microdnf install -y tar gzip unzip libicu && \ | ||
| ( microdnf reinstall tzdata -y || microdnf update tzdata -y ) && \ | ||
| curl "${DOTNET_TARBALL}" -o /tmp/dotnet.tar.gz && \ | ||
| mkdir /opt/dotnet && \ | ||
|
|
@@ -69,18 +57,10 @@ RUN [ "$IS_CI" == "true" ] || ( \ | |
| dotnet --list-runtimes | grep "Microsoft.NETCore.App ${DOTNET_VERSION} " ) | ||
|
|
||
| # Add default user | ||
| RUN mkdir -p ${DOTNET_APP_PATH} ${DOTNET_DATA_PATH} && \ | ||
| useradd -u $APP_UID -r -g 0 -d ${HOME} -s /sbin/nologin \ | ||
| -c "Default Application User" default | ||
|
|
||
| WORKDIR ${DOTNET_APP_PATH} | ||
| COPY default-cmd.sh ${DOTNET_DEFAULT_CMD} | ||
| CMD "./${DOTNET_DEFAULT_CMD}" | ||
|
|
||
| # In order to drop the root user, we have to make some directories world | ||
| # writable as OpenShift default security model is to run the container under | ||
| # random UID. | ||
| RUN chown -R $APP_UID:0 /opt/app-root && fix-permissions /opt/app-root | ||
| RUN useradd -u $APP_UID -r -g 0 -d /opt/app-root -s /sbin/nologin -c "Default Application User" default && \ | ||
| install -d -m 0775 -o $APP_UID -g 0 /opt/app-root | ||
|
|
||
| # Run container rootless. | ||
| USER $APP_UID | ||
| # Set HOME for the random uid that runs the s2i app on OpenShift | ||
| ENV HOME=/opt/app-root | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer this over letting root mess in the app user's HOME and then having to fix permissions for those files.
This way, we separate between the root and app user's HOME.