Skip to content

Commit 7546100

Browse files
author
Christian Parpart
committed
Dockerfile: improves docker image size and small others
This greatly improves size of the final docker image with the help of multi-stage docker builds. With that change, we can also make the build stage readable/maintainable again by splitting up into multiple RUN statements as well as not needing to clean-up temporary objects. The dependencies have been put on top of the primary COPY statement in order to not rebuild the dependencies each time one wants to rebuild the docker image (for example due to code changes). The solc compilation itself is now parallelized to the CPU core count to speed up those builds that have more cores available on their docker build system. Future Notes: ------------- We could further improve the Dockerfile by explicitely adding the directories this docker build is interested in (such as solc source code exclusively). Or one may want to also use the build step for automated testing (CI) by enforcing soltest and cmdlineTests.sh right before finalizing the image.
1 parent 4be9dc4 commit 7546100

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

scripts/Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
FROM alpine
1+
FROM alpine AS build
22
MAINTAINER chriseth <chris@ethereum.org>
33
#Official solidity docker image
44

55
#Establish working directory as solidity
66
WORKDIR /solidity
7+
8+
# Build dependencies
9+
ADD /scripts/install_deps.sh /solidity/scripts/install_deps.sh
10+
RUN ./scripts/install_deps.sh
11+
712
#Copy working directory on travis to the image
813
COPY / $WORKDIR
914

10-
#Install dependencies, eliminate annoying warnings, and build release, delete all remaining points and statically link.
11-
RUN ./scripts/install_deps.sh && sed -i -E -e 's/include <sys\/poll.h>/include <poll.h>/' /usr/include/boost/asio/detail/socket_types.hpp &&\
12-
cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSOLC_LINK_STATIC=1 &&\
13-
make solc && install -s solc/solc /usr/bin &&\
14-
cd / && rm -rf solidity &&\
15-
apk del sed build-base git make cmake gcc g++ musl-dev curl-dev boost-dev &&\
16-
rm -rf /var/cache/apk/*
15+
#Install dependencies, eliminate annoying warnings
16+
RUN sed -i -E -e 's/include <sys\/poll.h>/include <poll.h>/' /usr/include/boost/asio/detail/socket_types.hpp
17+
RUN cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=0 -DSOLC_LINK_STATIC=1
18+
RUN make solc -j$(grep -c ^processor /proc/cpuinfo) && install -s solc/solc /usr/bin
19+
#RUN strip solc/solc
1720

18-
ENTRYPOINT ["/usr/bin/solc"]
21+
FROM scratch
22+
COPY --from=build /solidity/solc/solc /usr/bin/solc
23+
ENTRYPOINT ["/usr/bin/solc"]

0 commit comments

Comments
 (0)