Simplify docker image in several ways (#523)
- `--embeddded` mode is the now the default - embedded cache and ports is also the default - emsdk now fully polulates the cache by default so no need to do that. - always "activate" the SDK avoiding that need things to work without that. - avoid making extra symlinks. - remove python2
This commit is contained in:
@@ -3,17 +3,11 @@ FROM debian:buster AS stage_build
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Supports only 1.38.40+, accepts also '-upstream' variants
|
# Supports only 1.38.40+, accepts also '-upstream' variants
|
||||||
ARG EMSCRIPTEN_VERSION=1.39.11
|
ARG EMSCRIPTEN_VERSION=1.39.18
|
||||||
ARG EMSDK_CHANGESET=master
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
# NOTE: Any change of following variables should be reflected in ./entrypoint file
|
|
||||||
ENV EMSDK /emsdk
|
ENV EMSDK /emsdk
|
||||||
ENV EM_DATA ${EMSDK}/.data
|
|
||||||
ENV EM_CONFIG ${EMSDK}/.emscripten
|
|
||||||
ENV EM_CACHE ${EM_DATA}/cache
|
|
||||||
ENV EM_PORTS ${EM_DATA}/ports
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -28,70 +22,27 @@ RUN echo "## Start building" \
|
|||||||
ca-certificates \
|
ca-certificates \
|
||||||
build-essential \
|
build-essential \
|
||||||
file \
|
file \
|
||||||
python python-pip \
|
|
||||||
python3 python3-pip \
|
python3 python3-pip \
|
||||||
\
|
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
RUN echo "## Get EMSDK" \
|
RUN echo "## Get EMSDK" \
|
||||||
&& git clone https://github.com/emscripten-core/emsdk.git ${EMSDK} \
|
&& git clone https://github.com/emscripten-core/emsdk.git ${EMSDK} \
|
||||||
&& cd ${EMSDK} && git reset --hard ${EMSDK_CHANGESET} \
|
|
||||||
\
|
|
||||||
&& ./emsdk.py update-tags \
|
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
RUN echo "## Install Emscripten" \
|
RUN echo "## Install Emscripten" \
|
||||||
&& cd ${EMSDK} \
|
&& cd ${EMSDK} \
|
||||||
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
|
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
|
||||||
\
|
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
# This generates configuration that contains all valid paths according to installed SDK
|
# This generates configuration that contains all valid paths according to installed SDK
|
||||||
RUN cd ${EMSDK} \
|
RUN cd ${EMSDK} \
|
||||||
&& echo "## Generate standard configuration" \
|
&& echo "## Generate standard configuration" \
|
||||||
\
|
&& ./emsdk activate ${EMSCRIPTEN_VERSION} \
|
||||||
&& ./emsdk activate ${EMSCRIPTEN_VERSION} --embedded \
|
&& ./emsdk construct_env \
|
||||||
&& ./emsdk construct_env > /dev/null \
|
|
||||||
&& cat ${EMSDK}/emsdk_set_env.sh \
|
&& cat ${EMSDK}/emsdk_set_env.sh \
|
||||||
\
|
&& chmod -R 777 ${EMSDK}/upstream/emscripten/cache \
|
||||||
# remove wrongly created entry with EM_CACHE, variable will be picked up from ENV
|
|
||||||
&& sed -i -e "/EM_CACHE/d" ${EMSDK}/emsdk_set_env.sh \
|
|
||||||
# add a link to tools like asm2wasm in a system path
|
|
||||||
# asm2wasm (and friends might be places either in ./upstream of ./fastcomp folder, hence detection is needed)
|
|
||||||
&& printf "export PATH=$(dirname $(find . -name asm2wasm -exec readlink -f {} +)):\$PATH\n" >> ${EMSDK}/emsdk_set_env.sh \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
# Create a structure and make mutable folders accessible for r/w
|
|
||||||
RUN cd ${EMSDK} \
|
|
||||||
&& echo "## Create .data structure" \
|
|
||||||
&& for mutable_dir in ${EM_DATA} ${EM_PORTS} ${EM_CACHE} ${EMSDK}/zips ${EMSDK}/tmp; do \
|
|
||||||
mkdir -p ${mutable_dir}; \
|
|
||||||
chmod -R 777 ${mutable_dir}; \
|
|
||||||
done \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
|
||||||
|
|
||||||
# Create an entrypoint that activates Emscripten SDK and helps running this image as non-root user
|
|
||||||
COPY entrypoint ${EMSDK}/
|
|
||||||
|
|
||||||
|
|
||||||
# Create symbolic links for critical Emscripten Tools
|
|
||||||
# This is important for letting people using Emscripten in Dockerfiles without activation
|
|
||||||
# As each Emscripten release is placed to a different folder (i.e. /emsdk/emscripten/tag-1.38.31)
|
|
||||||
RUN echo "## Create symbolic links" \
|
|
||||||
&& . ${EMSDK}/emsdk_set_env.sh \
|
|
||||||
\
|
|
||||||
&& mkdir -p ${EMSDK}/llvm ${EMSDK}/emscripten ${EMSDK}/binaryen \
|
|
||||||
\
|
|
||||||
&& ln -s $(dirname $(which node))/.. ${EMSDK}/node/current \
|
|
||||||
&& ln -s $(dirname $(which clang))/.. ${EMSDK}/llvm/clang \
|
|
||||||
&& ln -s $(dirname $(which emcc)) ${EMSDK}/emscripten/sdk \
|
|
||||||
\
|
|
||||||
&& ln -s $(dirname $(which asm2wasm)) ${EMSDK}/binaryen/bin \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
|
||||||
|
|
||||||
# Clean up emscripten installation and strip some symbols
|
# Clean up emscripten installation and strip some symbols
|
||||||
RUN echo "## Aggresive optimization: Remove debug symbols" \
|
RUN echo "## Aggresive optimization: Remove debug symbols" \
|
||||||
&& apt-get -qq -y update && apt-get -qq install -y --no-install-recommends \
|
&& apt-get -qq -y update && apt-get -qq install -y --no-install-recommends \
|
||||||
@@ -100,36 +51,21 @@ RUN echo "## Aggresive optimization: Remove debug symbols" \
|
|||||||
# Remove debugging symbols from embedded node (extra 7MB)
|
# Remove debugging symbols from embedded node (extra 7MB)
|
||||||
&& strip -s `which node` \
|
&& strip -s `which node` \
|
||||||
# Tests consume ~80MB disc space
|
# Tests consume ~80MB disc space
|
||||||
&& rm -fr ${EMSDK}/llvm/clang/emscripten/tests \
|
&& rm -fr ${EMSDK}/upstream/emscripten/tests \
|
||||||
# strip out symbols from clang (~extra 50MB disc space)
|
# strip out symbols from clang (~extra 50MB disc space)
|
||||||
&& find ${EMSDK}/llvm/clang/bin -type f -exec strip -s {} + || true \
|
&& find ${EMSDK}/upstream/bin -type f -exec strip -s {} + || true \
|
||||||
&& find ${EMSDK}/llvm/clang/fastcomp/bin -type f -exec strip -s {} + || true \
|
&& find ${EMSDK}/upstream/fastcomp/bin -type f -exec strip -s {} + || true \
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
# Populate Emscripten SDK cache with libc++, to improve further compilation times.
|
# Generate sanity
|
||||||
RUN echo "## Pre-populate cache" \
|
# TODO(sbc): We should be able to use just emcc -v here but it doesn't
|
||||||
&& . ${EMSDK}/emsdk_set_env.sh \
|
# currently create the sanity file.
|
||||||
\
|
RUN echo "## Generate sanity" \
|
||||||
&& embuilder.py build SYSTEM \
|
&& . ${EMSDK}/emsdk_set_env.sh \
|
||||||
\
|
&& echo "int main() { return 0; }" > hello.c \
|
||||||
&& mkdir -p /tmp/emscripten_test \
|
&& emcc -c hello.c \
|
||||||
&& cd /tmp/emscripten_test \
|
&& cat ${EMSDK}/.emscripten_sanity \
|
||||||
\
|
&& echo "## Done"
|
||||||
&& printf '#include <iostream>\nint main(){std::cout << "HELLO FROM DOCKER C++"<<std::endl;return 0;}' > test.cpp \
|
|
||||||
&& em++ --std=c++11 test.cpp -o test.js -s WASM=0 && node test.js \
|
|
||||||
&& em++ --std=c++11 -g3 test.cpp -o test.js -s WASM=0 && node test.js \
|
|
||||||
&& em++ --std=c++11 test.cpp -o test.js -s WASM=1 && node test.js \
|
|
||||||
\
|
|
||||||
&& cd / \
|
|
||||||
&& rm -fr /tmp/emscripten_test \
|
|
||||||
\
|
|
||||||
# some files were created, and we need to make sure that those can be accessed by non-root people
|
|
||||||
&& chmod -R 777 ${EM_DATA} \
|
|
||||||
\
|
|
||||||
# cleanup
|
|
||||||
&& find ${EMSDK} -name "*.pyc" -exec rm {} \; \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# -------------------------------- STAGE DEPLOY --------------------------------
|
# -------------------------------- STAGE DEPLOY --------------------------------
|
||||||
@@ -140,33 +76,26 @@ FROM debian:buster-slim AS stage_deploy
|
|||||||
COPY --from=stage_build /emsdk /emsdk
|
COPY --from=stage_build /emsdk /emsdk
|
||||||
|
|
||||||
# Fallback in case Emscripten isn't activated.
|
# Fallback in case Emscripten isn't activated.
|
||||||
# This will let use tools offered by this image inside other Docker images (sub-stages) or with custom / no entrypoint
|
# This will let use tools offered by this image inside other Docker images
|
||||||
ENV EMSDK /emsdk
|
# (sub-stages) or with custom / no entrypoint
|
||||||
ENV EMSCRIPTEN=${EMSDK}/emscripten/sdk
|
ENV EMSDK_NODE=/emsdk/node/12.9.1_64bit/bin/node
|
||||||
|
ENV EMSDK=/emsdk
|
||||||
ENV EM_DATA ${EMSDK}/.data
|
ENV EM_CONFIG=/emsdk/.emscripten
|
||||||
ENV EM_CONFIG ${EMSDK}/.emscripten
|
ENV PATH="${EMSDK}:${EMSDK}/upstream/emscripten:${EMSDK}/upstream/bin:emsdk/node/12.9.1_64bit/bin:${PATH}"
|
||||||
ENV EM_CACHE ${EM_DATA}/cache
|
|
||||||
ENV EM_PORTS ${EM_DATA}/ports
|
|
||||||
|
|
||||||
# Fallback in case Emscripten isn't activated
|
|
||||||
# Expose Major tools to system PATH, so that emcc, node, asm2wasm etc can be used without activation
|
|
||||||
ENV PATH="${EMSDK}:${EMSDK}/emscripten/sdk:${EMSDK}/llvm/clang/bin:${EMSDK}/node/current/bin:${EMSDK}/binaryen/bin:${PATH}"
|
|
||||||
|
|
||||||
# Use entrypoint that's coming from emscripten-slim image. It sets all required system paths and variables
|
|
||||||
ENTRYPOINT ["/emsdk/entrypoint"]
|
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Create a 'standard` 1000:1000 user
|
# Create a 'standard` 1000:1000 user
|
||||||
# Thanks to that this image can be executed as non-root user and created files will not require root access level on host machine
|
# Thanks to that this image can be executed as non-root user and created files
|
||||||
# Please note that this solution even if widely spread (i.e. Node.js uses it) is far from perfect as user 1000:1000 might not exist on
|
# will not require root access level on host machine Please note that this
|
||||||
# host machine, and in this case running any docker image will cause other random problems (mostly due `$HOME` pointing to `/`)
|
# solution even if widely spread (i.e. Node.js uses it) is far from perfect as
|
||||||
# This extra user works nicely with entrypoint provided in `/emsdk/entrypoint` as it detects case explained before.
|
# user 1000:1000 might not exist on host machine, and in this case running any
|
||||||
|
# docker image will cause other random problems (mostly due `$HOME` pointing to
|
||||||
|
# `/`)
|
||||||
RUN echo "## Create emscripten user (1000:1000)" \
|
RUN echo "## Create emscripten user (1000:1000)" \
|
||||||
&& groupadd --gid 1000 emscripten \
|
&& groupadd --gid 1000 emscripten \
|
||||||
&& useradd --uid 1000 --gid emscripten --shell /bin/bash --create-home emscripten \
|
&& useradd --uid 1000 --gid emscripten --shell /bin/bash --create-home emscripten \
|
||||||
\
|
&& echo "umask 0000" >> /etc/bash.bashrc \
|
||||||
|
&& echo ". /emsdk/emsdk_set_env.sh" >> /etc/bash.bashrc \
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@@ -178,9 +107,7 @@ RUN echo "## Update and install packages" \
|
|||||||
&& apt-get -qq -y update && apt-get -qq install -y --no-install-recommends \
|
&& apt-get -qq -y update && apt-get -qq install -y --no-install-recommends \
|
||||||
libxml2 \
|
libxml2 \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
python \
|
|
||||||
python3 \
|
python3 \
|
||||||
python-pip \
|
|
||||||
python3-pip \
|
python3-pip \
|
||||||
wget \
|
wget \
|
||||||
curl \
|
curl \
|
||||||
@@ -208,17 +135,10 @@ RUN echo "## Update and install packages" \
|
|||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Internal test suite of tools that this image provides
|
# Internal test suite of tools that this image provides
|
||||||
COPY test_dockerimage.sh ${EMSDK}/
|
COPY test_dockerimage.sh /emsdk/
|
||||||
|
|
||||||
RUN echo "## Internal Testing of image (activated)" \
|
RUN echo "## Internal Testing of image" \
|
||||||
&& . ${EMSDK}/emsdk_set_env.sh \
|
&& /emsdk/test_dockerimage.sh \
|
||||||
&& ${EMSDK}/test_dockerimage.sh \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
|
||||||
|
|
||||||
RUN echo "## Internal Testing of image (not-activated)" \
|
|
||||||
&& ${EMSDK}/test_dockerimage.sh \
|
|
||||||
\
|
|
||||||
&& echo "## Done"
|
&& echo "## Done"
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
# In case when mapped user id by `docker run -u` is not created inside docker image
|
|
||||||
# The `$HOME` variable points to `/` - which prevents any tool to write to, as it requires root access
|
|
||||||
# In such case we set `$HOME` to `/tmp` as it should r/w for everyone
|
|
||||||
|
|
||||||
if [ "$HOME" = "/" ] ; then
|
|
||||||
export HOME=/tmp
|
|
||||||
fi
|
|
||||||
|
|
||||||
# In case of running as root, use `umask` to reduce problem of file permission on host
|
|
||||||
if [ "$(id -g)" = "0" ] && [ "$(id -u)" = "0" ] ;
|
|
||||||
then
|
|
||||||
umask 0000
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Export this image specific Environment variables
|
|
||||||
# Those variables are important to use dedicated folder for all cache and predefined config file
|
|
||||||
export EM_CONFIG=/emsdk/.emscripten
|
|
||||||
export EM_CACHE=/emsdk/.data/cache
|
|
||||||
export EM_PORTS=/emsdk/.data/ports
|
|
||||||
|
|
||||||
# Activate Emscripten SDK
|
|
||||||
. ${EMSDK}/emsdk_set_env.sh
|
|
||||||
|
|
||||||
# Evaluate a command that's coming after `docker run` / `docker exec`
|
|
||||||
"$@"
|
|
||||||
@@ -8,8 +8,6 @@ node --version
|
|||||||
npm --version
|
npm --version
|
||||||
python3 --version
|
python3 --version
|
||||||
pip3 --version
|
pip3 --version
|
||||||
python --version
|
|
||||||
pip --version
|
|
||||||
em++ --version
|
em++ --version
|
||||||
emcc --version
|
emcc --version
|
||||||
java -version
|
java -version
|
||||||
|
|||||||
Reference in New Issue
Block a user