Skip to content

Commit

Permalink
Dockerfile: reduce size of resulting image
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aykevl authored and deadprogram committed Feb 20, 2024
1 parent a2588d8 commit c47f52b
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

0 comments on commit c47f52b

Please sign in to comment.