From c47f52b54607c5dd1453f1fbe949876314c8a342 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 20 Feb 2024 17:39:48 +0100 Subject: [PATCH] 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. --- Dockerfile | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 72dad9b9ff..75b125a877 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,26 +20,24 @@ FROM tinygo-llvm AS tinygo-llvm-build RUN cd /tinygo/ && \ make llvm-build -# tinygo-compiler stage builds the compiler itself -FROM tinygo-llvm-build AS tinygo-compiler +# tinygo-compiler-build stage builds the compiler itself +FROM tinygo-llvm-build AS tinygo-compiler-build COPY . /tinygo -# update submodules +# build the compiler and tools RUN cd /tinygo/ && \ - rm -rf ./lib/*/ && \ - git submodule sync && \ - git submodule update --init --recursive --force - -RUN cd /tinygo/ && \ - make + git submodule update --init --recursive && \ + make gen-device -j4 && \ + make build/release -# tinygo-tools stage installs the needed dependencies to compile TinyGo programs for all platforms. -FROM tinygo-compiler AS tinygo-tools +# tinygo-compiler copies the compiler build over to a base Go container (without +# all the build tools etc). +FROM golang:1.21 AS tinygo-compiler -RUN cd /tinygo/ && \ - make wasi-libc binaryen && \ - make gen-device -j4 && \ - cp build/* $GOPATH/bin/ +# Copy tinygo build. +COPY --from=tinygo-compiler-build /tinygo/build/release/tinygo /tinygo +# Configure the container. +ENV PATH="${PATH}:/tinygo/bin" CMD ["tinygo"]