From 70ca9f82ad415758d8d7347ff0b8362fee5b8b52 Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Tue, 12 Dec 2023 00:06:13 +0900 Subject: [PATCH 1/3] make image based on distroless --- .hadolint.yaml | 1 + Dockerfile | 20 +++++++++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.hadolint.yaml b/.hadolint.yaml index 0464523a4..95a718466 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -1,2 +1,3 @@ ignored: - DL3018 + - DL3007 diff --git a/Dockerfile b/Dockerfile index d1a19b546..e9693ad9c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ -FROM --platform=$BUILDPLATFORM golang:1.21.5-alpine AS build +FROM golang:1.21.5 AS build +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +RUN mkdir /storage + WORKDIR /go/src/github.com/traPtitech/traQ COPY ./go.* ./ RUN --mount=type=cache,target=/go/pkg/mod go mod download -COPY . . - ENV GOCACHE=/tmp/go/cache ENV CGO_ENABLED=0 ARG TRAQ_VERSION=dev @@ -16,19 +18,19 @@ ARG TARGETARCH ENV GOOS=$TARGETOS ENV GOARCH=$TARGETARCH +COPY . . RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/tmp/go/cache \ go build -o /traQ -ldflags "-s -w -X main.version=$TRAQ_VERSION -X main.revision=$TRAQ_REVISION" -FROM alpine:3.19.0 +FROM gcr.io/distroless/base:latest WORKDIR /app +EXPOSE 3000 -RUN apk add --no-cache --update ca-certificates && update-ca-certificates +COPY --from=build /storage/ /app/storage/ +VOLUME /app/storage COPY --from=build /traQ ./ -VOLUME /app/storage -EXPOSE 3000 - -HEALTHCHECK CMD ./traQ healthcheck || exit 1 +HEALTHCHECK CMD ["./traQ", "healthcheck", "||", "exit", "1"] ENTRYPOINT ["./traQ"] CMD ["serve"] From ee7ada0e06576434e71e9742ab218c3ab615858d Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Tue, 12 Dec 2023 00:16:15 +0900 Subject: [PATCH 2/3] add platform statement --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index e9693ad9c..af8521744 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.21.5 AS build +FROM --platform=$BUILDPLATFORM golang:1.21.5 AS build SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN mkdir /storage From d1e6572b3720d534e9b79899021da627563a158c Mon Sep 17 00:00:00 2001 From: logica0419 <84759675+logica0419@users.noreply.github.com> Date: Tue, 12 Dec 2023 01:20:31 +0900 Subject: [PATCH 3/3] removed redundant statement & setting --- .hadolint.yaml | 1 - Dockerfile | 1 - 2 files changed, 2 deletions(-) diff --git a/.hadolint.yaml b/.hadolint.yaml index 95a718466..cece24b6b 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -1,3 +1,2 @@ ignored: - - DL3018 - DL3007 diff --git a/Dockerfile b/Dockerfile index af8521744..12fc2783b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,4 @@ FROM --platform=$BUILDPLATFORM golang:1.21.5 AS build -SHELL ["/bin/bash", "-o", "pipefail", "-c"] RUN mkdir /storage