diff --git a/.gitignore b/.gitignore index 08c76a1..0c2ff7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -.vscode .task +.vscode diff --git a/Dockerfile b/Dockerfile index bcad529..db6d700 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,30 @@ -FROM golang:1.23.3-alpine as builder - -RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates - -RUN mkdir /app +FROM golang:1.23.3-alpine AS builder +ENV CGO_ENABLED=0 \ + GOARCH=amd64 \ + GOOS=linux \ + PROJECT_NAME=mcvs-integrationtest-services WORKDIR /app - -COPY go.mod go.sum ./ - -RUN go mod download COPY . . - -ARG APPLICATION=mcvs-integrationtest-services -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main ./cmd/$APPLICATION +RUN apk update && \ + apk add \ + --no-cache \ + ca-certificates=~20240705-r0 \ + git=~2 \ + tzdata=~2024 && \ + update-ca-certificates && \ + go mod download && \ + go build \ + -a \ + -installsuffix cgo \ + -o main \ + ./cmd/${PROJECT_NAME} && \ + adduser -D -u 1000 ${PROJECT_NAME} FROM scratch +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /etc/group /etc/group COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /app/main ./main -CMD ["./main"] +COPY --from=builder /app/main /app/main +USER mcvs-integrationtest-services +ENTRYPOINT ["/app/main"]