-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
76 lines (65 loc) · 1.95 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# ============================================================
# Dockerfile used to build the nrod-cif microservice
# ============================================================
ARG arch=amd64
ARG goos=linux
# ============================================================
# Build container containing our pre-pulled libraries.
# As this changes rarely it means we can use the cache between
# building each microservice.
FROM golang:alpine as build
# The golang alpine image is missing git so ensure we have additional tools
RUN apk add --no-cache \
curl \
git \
tzdata
# go-bindata
RUN go get -v github.com/kevinburke/go-bindata &&\
go build -o /usr/local/bin/go-bindata github.com/kevinburke/go-bindata/go-bindata
# Ensure we have the libraries - docker will cache these between builds
WORKDIR /work
ADD go.mod .
RUN go mod download
#RUN go get -v \
# github.com/lib/pq \
# github.com/peter-mount/golib/... \
# github.com/peter-mount/nre-feeds/util \
# github.com/peter-mount/sortfold
# ============================================================
# source container contains the source as it exists within the
# repository.
FROM build as source
WORKDIR /work
ADD . .
# Import sql so we can build as needed
RUN go-bindata -o cifimport/sqlassets.go -pkg cifimport sql/
# ============================================================
# Compile the source.
FROM source as compiler
ARG arch
ARG goos
ARG goarch
ARG goarm
WORKDIR /work
# NB: CGO_ENABLED=0 forces a static build
RUN for bin in \
cifimport \
cifretrieve;\
do\
echo "Building ${bin}";\
CGO_ENABLED=0 \
GOOS=${goos} \
GOARCH=${goarch} \
GOARM=${goarm} \
OUT= \
go build \
-o /dest/bin/${bin} \
./${bin}/bin;\
done
# ============================================================
# This is the final image
FROM alpine
RUN apk add --no-cache \
curl \
tzdata
COPY --from=compiler /dest/ /