-
Notifications
You must be signed in to change notification settings - Fork 23
/
Dockerfile
56 lines (43 loc) · 1.56 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
# This is a multi-stage Dockerfile.
# The first part retrieves Go dependencies, the second compiles the binary in
# a Go container, and the second retrieves the binary from the build container and
# inserts it into a "scratch" image.
# An additional image is included for executing tests.
# Part 1: Create a layer for Go module dependencies
#
FROM golang:1.17 as gomodules
WORKDIR /gort
COPY go.mod go.sum /gort/
RUN go mod download
# Part 1a: Execute quick tests in a containerized Golang environment
#
FROM gomodules as test
WORKDIR /gort
COPY . /gort
RUN --mount=type=cache,target=/root/.cache/go-build \
go test -v -short ./...
# Part 3: Compile the binary in a containerized Golang environment
#
FROM gomodules as builder
COPY . /gort
WORKDIR /gort
RUN --mount=type=cache,target=/root/.cache/go-build \
GOOS=linux go build -a -installsuffix cgo -o gort .
# Part 4: Build the Gort image proper
#
FROM ubuntu:20.04 as image
# Install Ansible
#
RUN apt update \
&& apt-get -y --force-yes install --no-install-recommends \
ssh \
ca-certificates \
&& apt-get clean \
&& apt-get autoclean \
&& apt-get autoremove \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN ssh-keygen -b 2048 -f /root/.ssh/id_rsa -P ''
COPY --from=builder /gort/gort /bin
ENTRYPOINT [ "/bin/gort" ]
EXPOSE 4000
CMD [ "start", "-v" ]