Reduce number of Docker layers

This commit is contained in:
Amir Zarrinkafsh 2020-01-11 13:35:54 +11:00
parent 242386e279
commit 072a8c468c
4 changed files with 19 additions and 21 deletions

View File

@ -11,8 +11,7 @@ RUN apk --no-cache add gcc musl-dev
WORKDIR /go/src/app WORKDIR /go/src/app
COPY go.mod go.mod COPY go.mod go.sum ./
COPY go.sum go.sum
RUN go mod download 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 sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go
# CGO_ENABLED=1 is mandatory for building go-sqlite3 # 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 && \
RUN cd cmd/authelia-scripts && GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -ldflags '-w -linkmode external -extldflags -static' -o authelia-scripts 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 ===== # ===== Build image for the frontend =====
@ -51,8 +51,7 @@ RUN apk --no-cache add ca-certificates tzdata
WORKDIR /usr/app WORKDIR /usr/app
COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./
COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts
COPY --from=builder-frontend /node/src/app/build public_html COPY --from=builder-frontend /node/src/app/build public_html
EXPOSE 9091 EXPOSE 9091

View File

@ -7,8 +7,7 @@ RUN apk --no-cache add ca-certificates tzdata
WORKDIR /usr/app WORKDIR /usr/app
COPY /dist/authelia authelia COPY dist ./
COPY /dist/public_html public_html
EXPOSE 9091 EXPOSE 9091

View File

@ -14,8 +14,7 @@ RUN apk --no-cache add curl && \
WORKDIR /go/src/app WORKDIR /go/src/app
COPY go.mod go.mod COPY go.mod go.sum ./
COPY go.sum go.sum
RUN go mod download 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 sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go
# CGO_ENABLED=1 is mandatory for building go-sqlite3 # 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 && \
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 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 WORKDIR /usr/app
COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./
COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts
COPY --from=builder-frontend /node/src/app/build public_html COPY --from=builder-frontend /node/src/app/build public_html
EXPOSE 9091 EXPOSE 9091

View File

@ -14,8 +14,7 @@ RUN apk --no-cache add curl && \
WORKDIR /go/src/app WORKDIR /go/src/app
COPY go.mod go.mod COPY go.mod go.sum ./
COPY go.sum go.sum
RUN go mod download 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 sed -i "s/__BUILD_TIME__/${BUILD_TIME}/" cmd/authelia/constants.go
# CGO_ENABLED=1 is mandatory for building go-sqlite3 # 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 && \
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 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 WORKDIR /usr/app
COPY --from=builder-backend /go/src/app/cmd/authelia/authelia authelia COPY --from=builder-backend /go/src/app/cmd/authelia/authelia /go/src/app/cmd/authelia-scripts/authelia-scripts ./
COPY --from=builder-backend /go/src/app/cmd/authelia-scripts/authelia-scripts authelia-scripts
COPY --from=builder-frontend /node/src/app/build public_html COPY --from=builder-frontend /node/src/app/build public_html
EXPOSE 9091 EXPOSE 9091