From 072a8c468c227b8b8621fb22485ac79da77759b1 Mon Sep 17 00:00:00 2001 From: Amir Zarrinkafsh Date: Sat, 11 Jan 2020 13:35:54 +1100 Subject: [PATCH] Reduce number of Docker layers --- Dockerfile | 13 ++++++------- Dockerfile.CI | 3 +-- Dockerfile.arm32v7 | 12 ++++++------ Dockerfile.arm64v8 | 12 ++++++------ 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index ad573f809..12c67e5fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,8 +11,7 @@ RUN apk --no-cache add gcc musl-dev WORKDIR /go/src/app -COPY go.mod go.mod -COPY go.sum go.sum +COPY go.mod go.sum ./ RUN go mod download @@ -27,9 +26,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts - +RUN cd cmd/authelia && \ +GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && \ +cd ../authelia-scripts && \ +GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts # ======================================== # ===== Build image for the frontend ===== @@ -51,8 +51,7 @@ RUN apk --no-cache add ca-certificates tzdata WORKDIR /usr/app -COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia -COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts +COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./ COPY --from=builder-frontend /node/src/app/build public_html EXPOSE 9091 diff --git a/Dockerfile.CI b/Dockerfile.CI index ec780af50..ac5580e0c 100644 --- a/Dockerfile.CI +++ b/Dockerfile.CI @@ -7,8 +7,7 @@ RUN apk --no-cache add ca-certificates tzdata WORKDIR /usr/app -COPY /dist/authelia authelia -COPY /dist/public_html public_html +COPY dist ./ EXPOSE 9091 diff --git a/Dockerfile.arm32v7 b/Dockerfile.arm32v7 index 7f15f3df2..5d901127b 100644 --- a/Dockerfile.arm32v7 +++ b/Dockerfile.arm32v7 @@ -14,8 +14,7 @@ RUN apk --no-cache add curl && \ WORKDIR /go/src/app -COPY go.mod go.mod -COPY go.sum go.sum +COPY go.mod go.sum ./ RUN go mod download @@ -30,8 +29,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-musleabihf-gcc go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-musleabihf-gcc go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts +RUN cd cmd/authelia && \ +GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-musleabihf-gcc go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && \ +cd ../authelia-scripts && \ +GOOS=linux GOARCH=arm CGO_ENABLED=1 CC=arm-linux-musleabihf-gcc go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts # ======================================== @@ -57,8 +58,7 @@ RUN apk --no-cache add ca-certificates tzdata && \ WORKDIR /usr/app -COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia -COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts +COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./ COPY --from=builder-frontend /node/src/app/build public_html EXPOSE 9091 diff --git a/Dockerfile.arm64v8 b/Dockerfile.arm64v8 index c383e2c6a..2f7ea06b7 100644 --- a/Dockerfile.arm64v8 +++ b/Dockerfile.arm64v8 @@ -14,8 +14,7 @@ RUN apk --no-cache add curl && \ WORKDIR /go/src/app -COPY go.mod go.mod -COPY go.sum go.sum +COPY go.mod go.sum ./ RUN go mod download @@ -30,8 +29,10 @@ RUN echo "Write tag ${BUILD_TAG} and commit ${BUILD_COMMIT} in binary." && \ sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go # CGO_ENABLED=1 is mandatory for building go-sqlite3 -RUN cd cmd/authelia && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && cd ../../ -RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts +RUN cd cmd/authelia && \ +GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc go build -tags netgo -ldflags '-w -linkmode external -extldflags -static' -o authelia && \ +cd ../authelia-scripts && \ +GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-musl-gcc go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts # ======================================== @@ -57,8 +58,7 @@ RUN apk --no-cache add ca-certificates tzdata && \ WORKDIR /usr/app -COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia -COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts +COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./ COPY --from=builder-frontend /node/src/app/build public_html EXPOSE 9091