forked from devopshobbies/docker-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
39 lines (27 loc) · 758 Bytes
/
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
# builder stage
# Use your custom Golang image from ECR
FROM public.ecr.aws/k8l2c2v3/ubc-docker:latest as builder
# Installing Git for alpine
RUN apk add --no-cache git
# create work directory called src
WORKDIR /src
# build argument for framework
ARG FRAMEWORK=echo
# copy go.mod and go.sum
COPY $FRAMEWORK/go.mod $FRAMEWORK/go.sum ./
# download dependencies
RUN go mod download
# copy other files
COPY $FRAMEWORK $FRAMEWORK
# build golang app
RUN CGO_ENABLED=0 GO111MODULE=on go build -v -o /main -installsuffix cgo -ldflags="-w -s" ./$FRAMEWORK/*.go
# second stage
FROM alpine
# copy executable file
COPY --from=builder /main .
# allow main to be executed
RUN chmod +x /main
# expose port 80
EXPOSE 80
# run app executable file
CMD ["./main"]