forked from gbeletti/service-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (29 loc) · 963 Bytes
/
Dockerfile
File metadata and controls
36 lines (29 loc) · 963 Bytes
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
# --- Stage 1:
FROM golang:1.19-alpine as builder
# Args & ENVs
ENV BUILD_PATH=/go/src/github.com/gbeletti/service-golang
RUN apk update && apk add --no-cache curl gcc git libc-dev
# COPY local files
WORKDIR ${BUILD_PATH}
COPY . .
# Get go dependencies
RUN go mod download
# revive (go lint successor)
RUN go install github.com/mgechev/revive@latest && \
revive ./...
# gosec - Golang Security Checker
RUN curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b ${GOPATH}/bin latest && \
gosec ./...
# Build dynamically linked Go binary
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 \
go build -o service
RUN cp ${BUILD_PATH}/service /bin/service
# --- Stage 2:
FROM alpine:3
# Install dependencies
RUN apk update && apk add --no-cache ca-certificates tzdata libc6-compat
# Copy binary from builder
COPY --from=builder /bin/service /service
# Run the application on container startup.
CMD ["/service"]
EXPOSE 8000