-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
44 lines (33 loc) · 1 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
FROM golang:1.15-alpine AS builder
ARG VERSION=0.0.1
ARG TARGET_ARCH
ENV APP_NAME=khcheck-aws-iam-role
ENV APP_VERSION=$VERSION
# GO goods
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=$TARGET_ARCH
# Move to working directory /build
WORKDIR /build
# Copy and download dependency using go mod
COPY go.mod .
COPY go.sum .
RUN go mod download
# Copy the code into the container
COPY . .
# Build the application
RUN date +%s > buildtime
RUN APP_BUILD_TIME=$(cat buildtime); \
go build -ldflags="-X 'main.buildTime=${APP_BUILD_TIME}' -X 'main.buildVersion=${APP_VERSION}'" -o ${APP_NAME} .
# Move to /dist directory as the place for resulting binary folder
WORKDIR /app
# Copy binary from build to main folder
RUN cp /build/${APP_NAME} .
# Build a small image
FROM scratch
# ENSURE THAT WE SMART AS HELL.
# https://github.com/aws/aws-sdk-go/issues/2322
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/${APP_NAME} /
CMD ["/khcheck-aws-iam-role"]