From 90af7140dcf96bd75a091d953b81b403f5a9c67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Gerrit=20G=C3=B6bel?= <86782124+jggoebel@users.noreply.github.com> Date: Thu, 14 Mar 2024 09:58:24 +0100 Subject: [PATCH] Improve dockerfiles (#185) --- Dockerfile | 4 +++- v3/services/accesscodesvc/Dockerfile | 12 +++++++----- v3/services/authnsvc/Dockerfile | 12 +++++++----- v3/services/authrsvc/Dockerfile | 12 +++++++----- v3/services/conversionsvc/Dockerfile | 12 +++++++----- v3/services/rbacsvc/Dockerfile | 12 +++++++----- v3/services/settingsvc/Dockerfile | 12 +++++++----- v3/services/usersvc/Dockerfile | 12 +++++++----- 8 files changed, 52 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e3838445..482fa9afd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,13 @@ FROM golang:1.21.1 AS sdk WORKDIR /app -COPY . . +COPY go.mod . # Change to the directory of the service. RUN go mod download -x +COPY . . + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -v -o /tmp/app diff --git a/v3/services/accesscodesvc/Dockerfile b/v3/services/accesscodesvc/Dockerfile index 09e8b7ee3..3013e4948 100644 --- a/v3/services/accesscodesvc/Dockerfile +++ b/v3/services/accesscodesvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/accesscodesvc + +COPY /v3/services/accesscodesvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/authnsvc/Dockerfile b/v3/services/authnsvc/Dockerfile index 47c0a1c68..0eb86192b 100644 --- a/v3/services/authnsvc/Dockerfile +++ b/v3/services/authnsvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/authnsvc + +COPY /v3/services/authnsvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/authrsvc/Dockerfile b/v3/services/authrsvc/Dockerfile index 90c3c76eb..a5085a99b 100644 --- a/v3/services/authrsvc/Dockerfile +++ b/v3/services/authrsvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/authrsvc + +COPY /v3/services/authrsvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/conversionsvc/Dockerfile b/v3/services/conversionsvc/Dockerfile index ab74b2faf..31402e933 100644 --- a/v3/services/conversionsvc/Dockerfile +++ b/v3/services/conversionsvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/conversionsvc + +COPY /v3/services/conversionsvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/rbacsvc/Dockerfile b/v3/services/rbacsvc/Dockerfile index 7abb4d699..4da93de6b 100644 --- a/v3/services/rbacsvc/Dockerfile +++ b/v3/services/rbacsvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/rbacsvc + +COPY /v3/services/rbacsvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/settingsvc/Dockerfile b/v3/services/settingsvc/Dockerfile index a425aaa58..ea7c4deef 100644 --- a/v3/services/settingsvc/Dockerfile +++ b/v3/services/settingsvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/settingsvc + +COPY /v3/services/settingsvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app diff --git a/v3/services/usersvc/Dockerfile b/v3/services/usersvc/Dockerfile index 3afd5d581..85facb619 100644 --- a/v3/services/usersvc/Dockerfile +++ b/v3/services/usersvc/Dockerfile @@ -1,15 +1,17 @@ ##### sdk image ##### FROM golang:1.21.1 AS sdk -WORKDIR /app - -# Copy everything, respecting .dockerignore. -COPY . . - # Change to the directory of the service. WORKDIR /app/v3/services/usersvc + +COPY /v3/services/usersvc/go.mod . +COPY /v3/go.mod /app/v3 + RUN go mod download +# Copy everything, respecting .dockerignore. +COPY . /app + # Build the service. The output binary is named "app". RUN CGO_ENABLED=0 GOOS=linux go build -o /tmp/app