-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
44 lines (29 loc) · 772 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
FROM golang:1.22.3 AS base
## ---------- ARGS
ARG TARGET_API
ARG API_PORT
## ---------- ENVS
ENV TARGET_API=${TARGET_API}
ENV API_PORT=${API_PORT}
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
## ---------- BUILD
## Stage 1 - Build the binary
FROM base AS builder
WORKDIR /build
COPY . .
RUN go build ${TARGET_API}/cmd/app/main.go && \
chmod +x main
# Stage 2: Compress the binary using UPX
FROM alpine AS upx
RUN apk add --no-cache upx
COPY --from=builder /build/main /upx/main
RUN upx --best --lzma /upx/main -o /upx/main_compressed
## ---------- MAIN
FROM scratch AS main
WORKDIR /app
COPY --from=upx /upx/main_compressed /app/main
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT [ "./main" ]
EXPOSE ${API_PORT}