-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
47 lines (33 loc) · 949 Bytes
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
ARG NAME=go-sample
ARG VERSION
FROM golang:1.22-alpine3.19 AS build-env
# Declare build arguments
ARG NAME
ARG VERSION
ARG GIT_COMMIT_SHA
ARG GIT_BRANCH
# Set environment variables
ENV NAME=${NAME}
ENV VERSION=${VERSION}
ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
ENV GIT_BRANCH=${GIT_BRANCH}
# Set working directory
WORKDIR /go/src/${NAME}
# Add build dependencies
RUN set -eux; apk update; apk add --no-cache git openssh make ca-certificates tzdata go-task
# Copy source code
COPY . .
# Install dependencies
RUN go mod download -x
# Build the application
RUN go-task build
# Put everything together in a clean image
FROM alpine:3.20
ARG NAME
# Add ca-certificates
COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# COPY tzdata
COPY --from=build-env /usr/share/zoneinfo /usr/share/zoneinfo
# Copy binary into PATH
COPY --from=build-env /go/src/${NAME}/bin/${NAME} /service
ENTRYPOINT ["/service"]