-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
50 lines (34 loc) · 1.16 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
# Start from golang base image
FROM golang:1.19ß-alpine as builder
# Set the current working directory inside the container
WORKDIR /app
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git make
# add user
RUN adduser -D gouser && chown -R gouser /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed
RUN go mod download
# Copy the source from the current directory to the working Directory inside the container
COPY . .
# Build the Go app
RUN BINARY=main make build-docker
# Start a new stage from scratch
FROM scratch
# Add Maintainer info
LABEL maintainer="Maksim Shcherbo <[email protected]>"
WORKDIR /root/
# copy ca certs
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# copy users from builder
COPY --from=builder /etc/passwd /etc/passwd
# Copy the Pre-built binary file from the previous stage.
COPY --from=builder /app/bin/main .
# set user as as the owner of the app
USER gouser
# Expose port to the outside world
EXPOSE 8000
#Command to run the executable
CMD [ "./main" ]