-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile_dev
55 lines (48 loc) · 1.89 KB
/
Dockerfile_dev
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
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.21.4
ARG BASE_DEBIAN_DISTRO="bullseye"
ARG GOLANG_IMAGE="golang:${GO_VERSION}-${BASE_DEBIAN_DISTRO}"
ARG APPNAME="app-template"
FROM ${GOLANG_IMAGE} AS base
ARG APT_MIRROR
ARG GOPROXY
ARG SLIM_LDFLAGS
ARG APPNAME
WORKDIR /root/app
RUN sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list \
&& sed -ri "s/(snapshot).debian.org/${APT_MIRROR:-snapshot.debian.org}/g" /etc/apt/sources.list \
&& cat /etc/apt/sources.list
RUN git config --global --add safe.directory /root/app
FROM base AS gox
RUN --mount=type=cache,target=/root/.cache/go-build \
--mount=type=cache,target=/go/pkg/mod \
GOBIN=/build/ GO111MODULE=on GOPROXY=${GOPROXY} go install github.com/mitchellh/gox@latest \
&& /build/gox --help
FROM base AS build-env
WORKDIR /root/app
COPY --from=gox /build/ /usr/local/bin/
RUN --mount=type=cache,sharing=locked,id=${APPNAME}-build-aptlib,target=/var/lib/apt \
--mount=type=cache,sharing=locked,id=${APPNAME}-build-aptcache,target=/var/cache/apt \
apt update && apt install -y \
upx jq
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/root/.cache/go-build,id=${APPNAME}-build \
--mount=type=cache,target=/go/pkg/mod,id=${APPNAME}-mod \
--mount=type=tmpfs,target=/go/src/ \
GOPROXY=${GOPROXY} go mod download
FROM build-env AS build
RUN --mount=type=bind,target=.,rw \
--mount=type=cache,target=/root/.cache/go-build,id=${APPNAME}-build \
--mount=type=cache,target=/go/pkg/mod,id=${APPNAME}-mod \
--mount=type=tmpfs,target=/go/src/ \
make build && mv bin /build
# usage:
# > docker buildx bake binary
# or
# > make binary
FROM scratch AS binary
COPY --from=build /build /
FROM build-env AS shell
ENV GOPROXY=${GOPROXY}
ENV SLIM_LDFLAGS=${SLIM_LDFLAGS}