-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
46 lines (35 loc) · 1.08 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
FROM --platform=${BUILDPLATFORM} golang:1.16-alpine AS base
FROM base AS dev
# docker-compose creates shared volume at /go/src
WORKDIR /usr/local/go/src/dkman
RUN apk add --no-cache --update --virtual shell-dependencies \
bash \
git \
vim
# Copy/rename shell startup file
COPY docker/home/profile /root/.bashrc
COPY docker/home/*.sh /root/
CMD /bin/bash
FROM base AS prep-build
WORKDIR /usr/local/go/src/dkman
ENV CGO_ENABLED=0
COPY go.* .
RUN go mod tidy
RUN --mount=type=cache,target=/go/pkg/mod \
go mod download
FROM prep-build AS build
ARG TARGETOS
ARG TARGETARCH
RUN --mount=target=. \
--mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /out/dkman .
# prep for cross-compiling, with sections named "bin-OSNAME"
FROM scratch AS bin-unix
COPY --from=build /out/dkman /
FROM bin-unix AS bin-linux
FROM bin-unix AS bin-darwin
FROM scratch AS bin-windows
COPY --from=build /out/dkman /dkman.exe
# This builds using the appopriately named section from above
FROM bin-${TARGETOS} as bin