From b14a5e0aa45e9b2b7a73e33c9e422b566c002754 Mon Sep 17 00:00:00 2001 From: Irina Spiridonova Date: Mon, 1 Apr 2024 16:06:20 -0700 Subject: [PATCH] Adding Dockerfile.cbl-mariner-x64 file and updating dockerfiles (#192) * Updated Dockerfile with 8.0-jammy-chiseled for runtime, updated Dockerfile.nanoserver-x64 and Dockerfile.ubuntu by changing workdir for dotnet restore and build to match Dockerfile, added Dockerfile.cbl-mariner-x64 file * Removed -r parameter for Run dotnet publish command * added Dockerfile.chiseled file * updated dockerfiles adding ARG ARCH with default values enabling user to build containers targeting different architecture * Removed -r parameter from RUN dotnet publish command due to conflict with -a parameter * --platform parameter is added to all linux flavor dockerfiles * minor fix in Dockerfile * Added argument TAG to Dockerfile.nanoserver for enabling to build different versions of Windows nanoserver --- Dockerfile | 2 +- Dockerfile.cbl-mariner | 26 +++++++++++++++++++ Dockerfile.chiseled | 26 +++++++++++++++++++ ...le.nanoserver-x64 => Dockerfile.nanoserver | 11 +++++--- Dockerfile.ubuntu-x64 => Dockerfile.ubuntu | 15 ++++++----- Garnet.sln | 6 +++-- 6 files changed, 73 insertions(+), 13 deletions(-) create mode 100644 Dockerfile.cbl-mariner create mode 100644 Dockerfile.chiseled rename Dockerfile.nanoserver-x64 => Dockerfile.nanoserver (74%) rename Dockerfile.ubuntu-x64 => Dockerfile.ubuntu (52%) diff --git a/Dockerfile b/Dockerfile index 65cddd3923..bd6238e15c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,4 +21,4 @@ COPY --from=build /app . EXPOSE 6379 # Run GarnetServer with an index size of 128MB -ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"] +ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"] \ No newline at end of file diff --git a/Dockerfile.cbl-mariner b/Dockerfile.cbl-mariner new file mode 100644 index 0000000000..830f64ac0c --- /dev/null +++ b/Dockerfile.cbl-mariner @@ -0,0 +1,26 @@ +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-cbl-mariner2.0 AS build +ARG TARGETARCH + +WORKDIR /source + +# Copy files +COPY . . +WORKDIR /source/main/GarnetServer + +RUN dotnet restore -a $TARGETARCH +RUN dotnet build -a $TARGETARCH -c Release + +# Copy and publish app and libraries +RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false --no-restore -f net8.0 + +# Final stage/image +FROM mcr.microsoft.com/dotnet/runtime:8.0-cbl-mariner2.0 AS runtime + +WORKDIR /app +COPY --from=build /app . + +# For inter-container communication. +EXPOSE 6379 + +# Run GarnetServer with an index size of 128MB +ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"] \ No newline at end of file diff --git a/Dockerfile.chiseled b/Dockerfile.chiseled new file mode 100644 index 0000000000..e60ad9f166 --- /dev/null +++ b/Dockerfile.chiseled @@ -0,0 +1,26 @@ +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-jammy AS build +ARG TARGETARCH + +WORKDIR /source + +# Copy files +COPY . . +WORKDIR /source/main/GarnetServer + +RUN dotnet restore -a $TARGETARCH +RUN dotnet build -a $TARGETARCH -c Release + +# Copy and publish app and libraries +RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false --no-restore -f net8.0 + +# Final stage/image +FROM mcr.microsoft.com/dotnet/runtime:8.0-jammy-chiseled AS runtime + +WORKDIR /app +COPY --from=build /app . + +# For inter-container communication. +EXPOSE 6379 + +# Run GarnetServer with an index size of 128MB +ENTRYPOINT ["/app/GarnetServer", "-i", "128m", "--port", "6379"] \ No newline at end of file diff --git a/Dockerfile.nanoserver-x64 b/Dockerfile.nanoserver similarity index 74% rename from Dockerfile.nanoserver-x64 rename to Dockerfile.nanoserver index 7adfb5f089..5ebb207273 100644 --- a/Dockerfile.nanoserver-x64 +++ b/Dockerfile.nanoserver @@ -1,17 +1,20 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-ltsc2022 AS build +ARG TAG=ltsc2022 +FROM mcr.microsoft.com/dotnet/sdk:8.0-nanoserver-$TAG AS build + WORKDIR /source # Copy files COPY . . +WORKDIR /source/main/GarnetServer + RUN dotnet restore RUN dotnet build -c Release # Copy and publish app and libraries -WORKDIR /source/main/GarnetServer RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false -f net8.0 # Final stage/image -FROM mcr.microsoft.com/dotnet/runtime:8.0-nanoserver-ltsc2022 AS runtime +FROM mcr.microsoft.com/dotnet/runtime:8.0-nanoserver-$TAG AS runtime WORKDIR /app COPY --from=build /app . @@ -19,4 +22,4 @@ COPY --from=build /app . EXPOSE 6379 # Run GarnetServer with an index size of 128MB -ENTRYPOINT ["/app/GarnetServer.exe", "-i", "128m", "--port", "6379"] +ENTRYPOINT ["/app/GarnetServer.exe", "-i", "128m", "--port", "6379"] \ No newline at end of file diff --git a/Dockerfile.ubuntu-x64 b/Dockerfile.ubuntu similarity index 52% rename from Dockerfile.ubuntu-x64 rename to Dockerfile.ubuntu index f968009e9a..c074ffea07 100644 --- a/Dockerfile.ubuntu-x64 +++ b/Dockerfile.ubuntu @@ -1,17 +1,20 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG TARGETARCH + WORKDIR /source # Copy files COPY . . -RUN dotnet restore -RUN dotnet build -c Release +WORKDIR /source/main/GarnetServer + +RUN dotnet restore -a $TARGETARCH +RUN dotnet build -a $TARGETARCH -c Release # Copy and publish app and libraries -WORKDIR /source/main/GarnetServer -RUN dotnet publish -c Release -o /app -r linux-x64 --self-contained false -f net8.0 +RUN dotnet publish -a $TARGETARCH -c Release -o /app --self-contained false -f net8.0 # Final stage/image -FROM mcr.microsoft.com/dotnet/runtime:8.0 +FROM mcr.microsoft.com/dotnet/runtime:8.0 AS runtime WORKDIR /app COPY --from=build /app . diff --git a/Garnet.sln b/Garnet.sln index 55e0006c53..675c0fc0dc 100644 --- a/Garnet.sln +++ b/Garnet.sln @@ -37,9 +37,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution docker-compose.yml = docker-compose.yml .github\workflows\docker.yml = .github\workflows\docker.yml Dockerfile = Dockerfile - Dockerfile.nanoserver-x64 = Dockerfile.nanoserver-x64 - Dockerfile.ubuntu-x64 = Dockerfile.ubuntu-x64 + Dockerfile.cbl-mariner = Dockerfile.cbl-mariner Garnet.nuspec = Garnet.nuspec + Dockerfile.chiseled = Dockerfile.chiseled + Dockerfile.nanoserver = Dockerfile.nanoserver + Dockerfile.ubuntu = Dockerfile.ubuntu EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bitmap", "playground\Bitmap\Bitmap.csproj", "{B9FA7D45-6DAE-4D56-AD7E-BB6C987A58C5}"