From f2010dd876d17e74ed1d25446efc04cd9d29e439 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Wed, 29 Dec 2021 22:20:22 -0500 Subject: [PATCH] better build artifact copying --- Dockerfile.mingw | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/Dockerfile.mingw b/Dockerfile.mingw index 6ea64a26..75371165 100644 --- a/Dockerfile.mingw +++ b/Dockerfile.mingw @@ -35,8 +35,13 @@ ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC HOST MAINTAINER Tatsuhiro Tsujikawa -# Preserve HOST as an ENV var just in case Docker user will want to use it again -ENV HOST=${HOST} +# Preserve all build params as ENV vars. This way CMD below will work properly, +# plus they will be available if the container is executed with "docker run ... bash" +ENV SOURCE=${SOURCE} \ + GIT_TAG=${GIT_TAG} \ + LIBARIA2=${LIBARIA2} \ + ARIA2_STATIC=${ARIA2_STATIC} \ + HOST=${HOST} RUN echo "Build configuration:" && \ echo " - SOURCE='${SOURCE}'" && \ @@ -160,7 +165,6 @@ FROM build_${SOURCE} ARG SOURCE GIT_TAG LIBARIA2 ARIA2_STATIC HOST RUN ln -s /usr/local/${HOST} /usr/local/mingw && \ - mkdir -p /usr/local/mingw/lib && \ cd /aria2 && \ autoreconf -i && \ export LIBARIA2=${LIBARIA2} && \ @@ -169,8 +173,8 @@ RUN ln -s /usr/local/${HOST} /usr/local/mingw && \ export PREFIX=/usr/local/${HOST} && \ ./mingw-config && \ make && \ - (test -f /aria2/src/aria2c.exe && ${HOST}-strip /aria2/src/aria2c.exe) && \ - (test -f /aria2/src/main.o && ${HOST}-strip /aria2/src/main.o) + make install && \ + ${HOST}-strip /usr/local/${HOST}/bin/aria2c.exe RUN echo "Finished build configuration:" && \ echo " - SOURCE='${SOURCE}'" && \ @@ -179,6 +183,21 @@ RUN echo "Finished build configuration:" && \ echo " - ARIA2_STATIC='${ARIA2_STATIC}'" && \ echo " - HOST='${HOST}'" -CMD test ! -d /output && \ - echo 'The /output dir is not set. Use "docker run -v $PWD:/output ..." to copy build results into the current dir. To explore this container, append "bash" at the end of docker run command.' || \ - cp -v /aria2/src/aria2c.exe* /aria2/src/main.o /output +# Define default command to simplify copying the build artifacts out of the container. +# Requires the user to provide the /output volume with the docker run -v :/output ... +# By default, aria2c.exe will be copied to the /bin. +# If the container is built with LIBARIA2 enabled, it will also copy the aria2.h file +# to /include/aria2/aria2.h, and all *.la and *.a files to /lib/ dir. +CMD set -e ; \ + if [ ! -d /output ] ; then \ + echo 'The /output dir is not set. Use "docker run -v :/output ..." to copy build results into the dir. To explore this container, append "bash" at the end of docker run command.' ; \ + else \ + mkdir -p /output/bin + cp -v /usr/local/${HOST}/bin/aria2c.exe /output/bin ; \ + if [ "${LIBARIA2}" = "enable" ] ; then \ + mkdir -p /output/lib + cp -v /usr/local/${HOST}/lib/*.a /usr/local/${HOST}/lib/*.la /output/lib ; \ + mkdir -p /output/include/aria2 + cp -v /usr/local/${HOST}/include/aria2/*.h /output/include/aria2 ; \ + fi \ + fi