-
Notifications
You must be signed in to change notification settings - Fork 12
/
Dockerfile
36 lines (30 loc) · 1.3 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
FROM --platform=${BUILDPLATFORM} golang:1.22 AS build
COPY / /src
WORKDIR /src
# The TARGETOS and TARGETARCH args are set by docker. We set GOOS and GOARCH to
# these values to ask Go to compile a binary for these architectures. If
# TARGETOS and TARGETOS are different from BUILDPLATFORM, Go will cross compile
# for us (e.g. compile a linux/amd64 binary on a linux/arm64 build machine).
ARG TARGETOS
ARG TARGETARCH
RUN --mount=type=cache,target=/go/pkg --mount=type=cache,target=/root/.cache/go-build GOOS=${TARGETOS} GOARCH=${TARGETARCH} make build
FROM --platform=${BUILDPLATFORM} ubuntu:22.04 AS base
ENV LANG=en_US.utf8
FROM base
ARG TARGETARCH
COPY --from=build /src/bin/kcl /usr/local/bin/kcl
RUN /usr/local/bin/kcl
RUN cp -r /root/go/bin/* /usr/local/bin/
RUN apt-get update && apt-get install make gcc git -y && rm -rf /var/lib/apt/lists/*
# The reason for doing this below is to prevent the
# container from not having write permissions.
ENV KCL_PKG_PATH=/tmp
ENV KCL_CACHE_PATH=/tmp
# In the image, we can generate a runtime in advance to
# avoid writing files in the image
ENV KCL_GO_DISABLE_INSTALL_ARTIFACT=true
ENV KCL_GO_DISABLE_ARTIFACT_IN_PATH=false
# Install the tini
ENV TINI_VERSION v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-${TARGETARCH} /tini
RUN chmod +x /tini