Skip to content
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

PeopleService (.NET): decrease container size and improve security posture #251

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions people-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/dotnet/.devcontainer/base.Dockerfile
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-noble AS build
ARG TARGETARCH
WORKDIR /source
COPY PeopleService.WebApi/PeopleService.WebApi.csproj PeopleService.WebApi/
COPY PeopleService.Core/PeopleService.Core.csproj PeopleService.Core/
RUN dotnet restore PeopleService.WebApi/PeopleService.WebApi.csproj -a $TARGETARCH
COPY PeopleService.WebApi/ PeopleService.WebApi/
COPY PeopleService.Core/ PeopleService.Core/

# [Choice] .NET version: 8.0 /8.0-bookworm, 8.0-jammy, 7.0 /7.0-bookworm, 7.0-bullseye, 7.0-jammy, 6.0 /6.0-bookworm, 6.0-bullseye, 6.0-jammy, 6.0-focal
ARG VARIANT="8.0"
FROM mcr.microsoft.com/vscode/devcontainers/dotnet:${VARIANT}

WORKDIR /people-service
COPY . .
FROM build AS publish
WORKDIR /source/PeopleService.WebApi
RUN dotnet publish PeopleService.WebApi.csproj -p:PublishSingleFile=true -a $TARGETARCH --self-contained true -c release -o /app

FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-noble-chiseled
WORKDIR /app
COPY --from=publish /app .
EXPOSE 18089

# [Choice] Node.js version: none, lts/*, 18, 16, 14
ARG NODE_VERSION="18"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1
ENTRYPOINT cd PeopleService.WebApi && dotnet run
ENV ASPNETCORE_HTTP_PORTS=18089
ENV ASPNETCORE_ENVIRONMENT=Development
ENTRYPOINT ["./PeopleService.WebApi"]
2 changes: 1 addition & 1 deletion people-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Visit the forwarded port `/swagger` to open the SwaggerUI.

Example URL:

`/People/GetPerson?LoginId=user01`
`/People/GetPerson?LogonId=user01`