-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
51 lines (35 loc) · 1.13 KB
/
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
48
49
50
51
ARG APP_NAME=my-app
FROM golang:1.20-alpine as base
LABEL author="masb0ymas"
LABEL name="expresso"
FROM base as build_base
RUN apk add --no-cache git
# Set the Temp Working Directory inside the container
WORKDIR /temp-build
# We want to populate the module cache based on the go.{mod,sum} files.
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN cp .env.docker-production .env
# Build the Go app
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o ./dist/${APP_NAME} main.go
# Start fresh from a smaller image
FROM alpine:3.16 as runner
RUN apk add ca-certificates
# Set the Current Working Directory inside the container
WORKDIR /app
# Setup Timezone
RUN apk add tzdata
ENV TZ=Asia/Jakarta
# editor cli with nano
RUN apk add nano
COPY --from=build_base /temp-build/dist/${APP_NAME} ./${APP_NAME}
COPY --from=build_base /temp-build/bin ./bin
COPY --from=build_base /temp-build/public ./public
COPY --from=build_base /temp-build/.air.toml ./.air.toml
COPY --from=build_base /temp-build/.env ./.env
# This container exposes port 8000 to the outside world
EXPOSE 8000
# Run the binary program produced by `go install`
CMD ["./${APP_NAME}"]