From 939816c343c8d79a12dd16f486e67c32ddf32e38 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Mon, 8 Feb 2021 13:43:09 +1100 Subject: [PATCH] Modified Dockerfiles for different project as multistage containers --- c#/Dockerfile | 22 +++++++++++++++++++++- golang/Dockerfile | 13 +++++++++++-- nodejs/Dockerfile | 19 ++++++++++++++++++- python/Dockerfile | 19 +++++++++++++++++-- python/src/requirements.txt | 1 + 5 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 python/src/requirements.txt diff --git a/c#/Dockerfile b/c#/Dockerfile index 7fe44aa..a37d52a 100644 --- a/c#/Dockerfile +++ b/c#/Dockerfile @@ -1 +1,21 @@ -FROM mcr.microsoft.com/dotnet/sdk:2.1-focal \ No newline at end of file +FROM mcr.microsoft.com/dotnet/sdk:2.1-focal as dev + +RUN mkdir /app/ +WORKDIR /app/ + +COPY ./src/work.csproj /app/work.csproj +RUN dotnet restore + +COPY ./src/ /app/ +RUN mkdir /out/ +RUN dotnet publish --no-restore --output /out/ --configuration Release + +################# PRODUCTION IMAGE ################# + +FROM mcr.microsoft.com/dotnet/core/aspnet:2.1-stretch-slim as prod + +RUN mkdir /app/ +WORKDIR /app/ +COPY --from=dev /out/ /app/ +RUN chmod +x /app/ +CMD dotnet work.dll \ No newline at end of file diff --git a/golang/Dockerfile b/golang/Dockerfile index 6147cb5..1176a4d 100644 --- a/golang/Dockerfile +++ b/golang/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.12.5-alpine3.9 as builder +FROM golang:1.12.5-alpine3.9 as dev # installing git RUN apk update && apk upgrade && \ @@ -6,4 +6,13 @@ RUN apk update && apk upgrade && \ RUN go get github.com/sirupsen/logrus RUN go get github.com/buaazp/fasthttprouter -RUN go get github.com/valyala/fasthttp \ No newline at end of file +RUN go get github.com/valyala/fasthttp + +WORKDIR /work +COPY ./src /work/ +RUN go build -o app +###########START NEW IMAGE################### + +FROM alpine:3.9 as prod +COPY --from=dev /work/app / +CMD ./app diff --git a/nodejs/Dockerfile b/nodejs/Dockerfile index 56d9a22..1176a4d 100644 --- a/nodejs/Dockerfile +++ b/nodejs/Dockerfile @@ -1 +1,18 @@ -FROM node:12.4.0-alpine \ No newline at end of file +FROM golang:1.12.5-alpine3.9 as dev + +# installing git +RUN apk update && apk upgrade && \ + apk add --no-cache git + +RUN go get github.com/sirupsen/logrus +RUN go get github.com/buaazp/fasthttprouter +RUN go get github.com/valyala/fasthttp + +WORKDIR /work +COPY ./src /work/ +RUN go build -o app +###########START NEW IMAGE################### + +FROM alpine:3.9 as prod +COPY --from=dev /work/app / +CMD ./app diff --git a/python/Dockerfile b/python/Dockerfile index 6ac7319..9c5859d 100644 --- a/python/Dockerfile +++ b/python/Dockerfile @@ -1,3 +1,18 @@ -FROM python:3.7.3-alpine3.9 +FROM golang:1.12.5-alpine3.9 as dev -RUN pip install flask \ No newline at end of file +# installing git +RUN apk update && apk upgrade && \ + apk add --no-cache git + +RUN go get github.com/sirupsen/logrus +RUN go get github.com/buaazp/fasthttprouter +RUN go get github.com/valyala/fasthttp + +WORKDIR /work +COPY ./src /work/ +RUN go build -o app +###########START NEW IMAGE################### + +FROM alpine:3.9 as prod +COPY --from=dev /work/app / +CMD ./app \ No newline at end of file diff --git a/python/src/requirements.txt b/python/src/requirements.txt new file mode 100644 index 0000000..9614ae3 --- /dev/null +++ b/python/src/requirements.txt @@ -0,0 +1 @@ +Flask == 1.0.3 \ No newline at end of file