The shellscript you have seems simple enough. It looks fairly nice, though the use of
export is unnecessary.
The dockerfile is a bit of a different story.
It's not fully clear whether you intend to use the built application from within the docker container you are setting up there or whether the container is only used to build the executables that are later moved elsewhere.
For now I am assuming that the docker container you create there is the final artifact, and I highly recommend looking into multi-stage builds to slim down the final result.
In addition to that, it feels quite peculiar to install four different C/C++ compilers. It could make sense to separate the dependencies of your application into two categories and keep a
make_package_list) that can be used to set up the application.
This dovetails nicely with my next suggestion: Make use of docker's caching mechanism.
Currently this Docker container will be rebuilt from scratch every single codechange. That is because you are first
COPYing all the source files into the container.
Instead of doing that, you want to take advantage of caching and perform steps that rarely change first:
FROM node:8.3.0 AS package
RUN apt-get update
# install building time dependencies
COPY make_package_list .
RUN make_package_list > xargs apt-get install -y -q --no-install-recommends
# install nodec compiler
RUN curl -L http://enclose.io/nodec/nodec-linux-x64.gz | gunzip > /usr/local/bin/nodec
RUN chmod +x /usr/local/bin/nodec
# install runtime dependencies
COPY package_list .
RUN package_list > xargs apt-get install -y -q --no-install-recommends
# NOW we copy the source files and start the build process
COPY . .
RUN npm i --no-optional \
&& ls -lh
# Run build scripts
RUN mkdir compile-bin \
&& chmod +x ./build-script \
&& sync \
This setup should make the build a bit quicker after the first run, so long as none of the dependencies for your application change. That does not work for the npm-dependencies, though.
It would be possible to change that, too (by copying the package-lock and running
npm -i before copying the remainder of the source files), but since you are copying the complete local directory, the current script will use your local package-cache.
While that will be a faster build, it can introduce subtle issues with stale packages and will take a smidge more time during the