Skip to content

Commit c47f52b

Browse files
aykevldeadprogram
authored andcommitted
Dockerfile: reduce size of resulting image
This reduces the size of the Docker image from 13GB to 1.71GB, and should therefore make CI of the drivers package much faster. It should hopefully also avoid the out-of-space problem we currently have when building the smoke tests for the drivers repo. This size reduction is done by using multistage builds and only copying the necessary files in the final stage.
1 parent a2588d8 commit c47f52b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

Dockerfile

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,24 @@ FROM tinygo-llvm AS tinygo-llvm-build
2020
RUN cd /tinygo/ && \
2121
make llvm-build
2222

23-
# tinygo-compiler stage builds the compiler itself
24-
FROM tinygo-llvm-build AS tinygo-compiler
23+
# tinygo-compiler-build stage builds the compiler itself
24+
FROM tinygo-llvm-build AS tinygo-compiler-build
2525

2626
COPY . /tinygo
2727

28-
# update submodules
28+
# build the compiler and tools
2929
RUN cd /tinygo/ && \
30-
rm -rf ./lib/*/ && \
31-
git submodule sync && \
32-
git submodule update --init --recursive --force
33-
34-
RUN cd /tinygo/ && \
35-
make
30+
git submodule update --init --recursive && \
31+
make gen-device -j4 && \
32+
make build/release
3633

37-
# tinygo-tools stage installs the needed dependencies to compile TinyGo programs for all platforms.
38-
FROM tinygo-compiler AS tinygo-tools
34+
# tinygo-compiler copies the compiler build over to a base Go container (without
35+
# all the build tools etc).
36+
FROM golang:1.21 AS tinygo-compiler
3937

40-
RUN cd /tinygo/ && \
41-
make wasi-libc binaryen && \
42-
make gen-device -j4 && \
43-
cp build/* $GOPATH/bin/
38+
# Copy tinygo build.
39+
COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo
4440

41+
# Configure the container.
42+
ENV PATH="${PATH}:/tinygo/bin"
4543
CMD ["tinygo"]

0 commit comments

Comments
 (0)