-
Notifications
You must be signed in to change notification settings - Fork 12
/
Dockerfile
executable file
·51 lines (35 loc) · 1.66 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
# Local image to download dependencies
# No emulation, runs with host arch
FROM --platform=${BUILDPLATFORM} debian:stable-slim as base
ARG TARGETOS
ARG TARGETARCH
RUN apt-get clean && apt-get update && \
apt-get install -y wget
ENV GO_RELEASE=1.23.2
RUN wget https://dl.google.com/go/go${GO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz && \
tar xfv go${GO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz -C /usr/local && \
find /usr/local/go -mindepth 1 -maxdepth 1 ! -name 'src' ! -name 'VERSION' ! -name 'bin' ! -name 'pkg' ! -name 'go.env' -exec rm -rf {} +
ENV TINYGO_RELEASE=0.34.0
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_RELEASE}/tinygo${TINYGO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz && \
tar xfv tinygo${TINYGO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz -C /usr/local
# Build final image, emulation, runs as TARGETARCH
FROM debian:stable-slim as build
RUN apt-get clean && apt-get update && \
apt-get install -y gcc git sudo make && \
rm -rf /var/lib/apt/lists/*
RUN useradd -ms /bin/bash tinygo
RUN usermod -aG sudo tinygo && echo "tinygo ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
USER tinygo
WORKDIR /home/tinygo
COPY --from=base /usr/local/go /usr/local/go
COPY --from=base /usr/local/tinygo /usr/local/tinygo
ENV PATH=${PATH}:/usr/local/tinygo/bin
ENV PATH=${PATH}:/usr/local/go/bin
# Run a unittest to validate that the image arch and the compiled version matches
FROM build as UnitTest
ARG TARGETARCH
RUN export TINY_ARCH=$(tinygo info | grep GOARCH | awk '{print $2}') && \
if [ "${TARGETARCH}" != "${TINY_ARCH}" ]; then exit 1; else exit 0; fi
# Final image, runs as TARGETARCH
FROM build as final
CMD ["tinygo"]