From 4f59e092bd4c5aaf316db7b79392c39d80485339 Mon Sep 17 00:00:00 2001 From: Paul Yuknewicz Date: Wed, 24 Jul 2024 11:18:38 -0700 Subject: [PATCH] Updating dockerfiles used in Tutorial make build (C#,Python,Node,ReactClient) (#1062) * Updating gitignore to exclude out/ from dotnet publish Signed-off-by: Paul Yuknewicz * Fixing build.yaml github action workflow with modern dockerfiles. go for dist calculator already fixed by #1058 Signed-off-by: Paul Yuknewicz * Updating csharp dockerfile with correct entry point, and do not explicitly expose port Signed-off-by: Paul Yuknewicz --------- Signed-off-by: Paul Yuknewicz --- .gitignore | 1 + .../distributed-calculator/csharp/Dockerfile | 21 ++++++++++++++---- .../distributed-calculator/node/Dockerfile | 2 +- .../distributed-calculator/python/Dockerfile | 2 +- .../react-calculator/Dockerfile | 2 +- tutorials/hello-kubernetes/node/Dockerfile | 2 +- tutorials/hello-kubernetes/python/Dockerfile | 2 +- tutorials/observability/python/Dockerfile | 2 +- .../pub-sub/csharp-subscriber/Dockerfile | 22 ++++++++++++++++--- tutorials/pub-sub/node-subscriber/Dockerfile | 2 +- .../pub-sub/python-subscriber/Dockerfile | 2 +- tutorials/pub-sub/react-form/Dockerfile | 2 +- 12 files changed, 46 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index ba20e26a3..bd0345434 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ Debug/ .settings/ .metadata .project +out/ # Package Files # *.jar diff --git a/tutorials/distributed-calculator/csharp/Dockerfile b/tutorials/distributed-calculator/csharp/Dockerfile index 1089c13de..4a8cd4334 100644 --- a/tutorials/distributed-calculator/csharp/Dockerfile +++ b/tutorials/distributed-calculator/csharp/Dockerfile @@ -1,7 +1,20 @@ -# Note: we cannot do a staged dotnet docker build here for arm/arm64. +# Use the official .NET 7 SDK image to build the application +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build +WORKDIR /app + +# Copy the project file and restore dependencies +COPY *.csproj ./ +RUN dotnet clean +RUN dotnet restore --disable-parallel -# Build runtime image -FROM mcr.microsoft.com/dotnet/aspnet:7.0 +# Copy the rest of the application code and build the application +COPY . ./ +RUN dotnet publish -c Release -o out + +# Use the official .NET 7 runtime image to run the application +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/aspnet:7.0 AS runtime WORKDIR /app -COPY /out . +COPY --from=build /app/out . + +# Run the application ENTRYPOINT ["dotnet", "Subtract.dll"] diff --git a/tutorials/distributed-calculator/node/Dockerfile b/tutorials/distributed-calculator/node/Dockerfile index 0c7ab850e..074f773a7 100644 --- a/tutorials/distributed-calculator/node/Dockerfile +++ b/tutorials/distributed-calculator/node/Dockerfile @@ -1,4 +1,4 @@ -FROM node:17-alpine +FROM node:20-alpine WORKDIR /usr/src/app COPY . . RUN npm install diff --git a/tutorials/distributed-calculator/python/Dockerfile b/tutorials/distributed-calculator/python/Dockerfile index fa0d808f5..bb944d8ca 100644 --- a/tutorials/distributed-calculator/python/Dockerfile +++ b/tutorials/distributed-calculator/python/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.12-alpine COPY . /app WORKDIR /app RUN pip install flask flask_cors diff --git a/tutorials/distributed-calculator/react-calculator/Dockerfile b/tutorials/distributed-calculator/react-calculator/Dockerfile index 945cad5e0..d20b79bd2 100644 --- a/tutorials/distributed-calculator/react-calculator/Dockerfile +++ b/tutorials/distributed-calculator/react-calculator/Dockerfile @@ -1,4 +1,4 @@ -FROM node:17-alpine +FROM node:20-alpine WORKDIR /usr/src/app COPY . . RUN npm install diff --git a/tutorials/hello-kubernetes/node/Dockerfile b/tutorials/hello-kubernetes/node/Dockerfile index 5c3326ea3..68d185a37 100644 --- a/tutorials/hello-kubernetes/node/Dockerfile +++ b/tutorials/hello-kubernetes/node/Dockerfile @@ -1,4 +1,4 @@ -FROM node:17-alpine +FROM node:20-alpine WORKDIR /app COPY . . RUN npm install diff --git a/tutorials/hello-kubernetes/python/Dockerfile b/tutorials/hello-kubernetes/python/Dockerfile index 50e053797..438867fdf 100644 --- a/tutorials/hello-kubernetes/python/Dockerfile +++ b/tutorials/hello-kubernetes/python/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.12-alpine WORKDIR /app COPY . . RUN pip install requests diff --git a/tutorials/observability/python/Dockerfile b/tutorials/observability/python/Dockerfile index fa0d808f5..bb944d8ca 100644 --- a/tutorials/observability/python/Dockerfile +++ b/tutorials/observability/python/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.12-alpine COPY . /app WORKDIR /app RUN pip install flask flask_cors diff --git a/tutorials/pub-sub/csharp-subscriber/Dockerfile b/tutorials/pub-sub/csharp-subscriber/Dockerfile index e7c0c2a1b..636084fd8 100644 --- a/tutorials/pub-sub/csharp-subscriber/Dockerfile +++ b/tutorials/pub-sub/csharp-subscriber/Dockerfile @@ -1,6 +1,22 @@ -# Note: we cannot do a staged dotnet docker build here for arm/arm64. +# Use the official .NET 8 SDK image to build the application +FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/sdk:8.0 AS build +WORKDIR /app + +# Copy the project file and restore dependencies +COPY *.csproj ./ +RUN dotnet restore --disable-parallel + +# Copy the rest of the application code and build the application +COPY . ./ +RUN dotnet publish -c Release -o out -FROM mcr.microsoft.com/dotnet/aspnet:8.0 +# Use the official .NET 8 runtime image to run the application +FROM --platform=linux/arm64 mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime WORKDIR /app -COPY /out . +COPY --from=build /app/out . + +# Expose the port the application runs on +EXPOSE 80 + +# Run the application ENTRYPOINT ["dotnet", "csharp-subscriber.dll"] diff --git a/tutorials/pub-sub/node-subscriber/Dockerfile b/tutorials/pub-sub/node-subscriber/Dockerfile index 939caefb5..40bf18590 100644 --- a/tutorials/pub-sub/node-subscriber/Dockerfile +++ b/tutorials/pub-sub/node-subscriber/Dockerfile @@ -1,4 +1,4 @@ -FROM node:17-alpine +FROM node:20-alpine WORKDIR /usr/src/app COPY . . RUN npm install diff --git a/tutorials/pub-sub/python-subscriber/Dockerfile b/tutorials/pub-sub/python-subscriber/Dockerfile index f45330cf3..dd388c0bb 100644 --- a/tutorials/pub-sub/python-subscriber/Dockerfile +++ b/tutorials/pub-sub/python-subscriber/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.7-alpine +FROM python:3.12-alpine COPY . /app WORKDIR /app RUN pip install flask flask_cors diff --git a/tutorials/pub-sub/react-form/Dockerfile b/tutorials/pub-sub/react-form/Dockerfile index 8d909224b..11b2d2171 100644 --- a/tutorials/pub-sub/react-form/Dockerfile +++ b/tutorials/pub-sub/react-form/Dockerfile @@ -1,4 +1,4 @@ -FROM node:17-alpine +FROM node:20-alpine WORKDIR /usr/src/app COPY . . RUN npm run build