-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dockerfile
51 lines (37 loc) · 1.39 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
############################
# STEP 1 build executable binary
############################
FROM golang:alpine AS builder
ARG TAG_VERSION
# Enable this if you want to have private repositories to be collected
# ARG GITHUB_USER
# ARG GITHUB_TOKEN
# Install git.
# Git is required for fetching the dependencies.
RUN apk update && apk add --no-cache git
# Adding the CA certificates
RUN apk --no-cache add ca-certificates
# Adding the sed tool for versioning
RUN apk add sed
# Enable this if you want to have private repositories to be collected
# RUN git config --global url."https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/"
WORKDIR /go/src/cjlapao/go-template
COPY . .
WORKDIR /go/src/cjlapao/go-template/src
# Updating the main variable.
RUN sed -i "s/^var ver = \"[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+\"/var ver = \"${TAG_VERSION}\"/g" main.go
# Using go get.
RUN go get -d -v
# Build the binary.
RUN GIT_TERMINAL_PROMPT=1 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/go-template
############################
# STEP 2 build a small image
############################
FROM scratch
# Copy SSL Certificates
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# Copy our static executable.
COPY --from=builder /go/bin/go-template /go/bin/go-template
# Run the project binary.
EXPOSE 80
ENTRYPOINT ["/go/bin/go-template"]