Skip to content

Instantly share code, notes, and snippets.

@philipz
Last active May 10, 2016 03:50
Show Gist options
  • Save philipz/f9c97fdca8862e9e7868 to your computer and use it in GitHub Desktop.
Save philipz/f9c97fdca8862e9e7868 to your computer and use it in GitHub Desktop.
Build Node binary Docker image
#!/bin/bash
cd /app
npm install
npm install -g enclose
enclose --loglevel info -x -o ./$2 ./$1
./copy_ldd.sh $2 build
cd build && tar zcf build.tar.gz * && mv build.tar.gz ../ && cd /app && rm -rf build
exit
#!/bin/bash
if [ $# != 2 ] ; then
echo "usage $0 PATH_TO_BINARY TARGET_FOLDER"
exit 1
fi
PATH_TO_BINARY="$1"
TARGET_FOLDER="$2"
# if we cannot find the the binary we have to abort
if [ ! -f "$PATH_TO_BINARY" ] ; then
echo "The file '$PATH_TO_BINARY' was not found. Aborting!"
exit 1
fi
# copy the binary to the target folder
# create directories if required
echo "---> copy binary itself"
mkdir -p "$TARGET_FOLDER"/app
cp --parents -v "$PATH_TO_BINARY" "$TARGET_FOLDER"/app
cp --parents -v -R node_modules "$TARGET_FOLDER"/app
# copy the required shared libs to the target folder
# create directories if required
echo "---> copy libraries"
for lib in `ldd "$PATH_TO_BINARY" | cut -d'>' -f2 | awk '{print $1}' | grep "/"` ; do
if [ -f "$lib" ] ; then
cp -v --parents "$lib" "$TARGET_FOLDER"
fi
done
echo "Done!!!"
NAME = mqtt2fluent
APP_NAME = server.js
NODE_VERSION = 0.12.7
PWD := $(shell pwd)
.PHONY: all
all: clean build
build:
docker run -ti --rm -v $(PWD):/app node:$(NODE_VERSION) /app/compile.sh $(APP_NAME) $(NAME)
echo 'FROM scratch\nADD build.tar.gz /\nCMD ["/app/$(NAME)"]' > Dockerfile
docker build -t philipz/$(NAME) .
clean: clean-exe clean-build
clean-docker:
docker rmi philipz/$(NAME)
clean-exe:
sudo rm -f $(NAME)
clean-build:
sudo rm -rf build
sudo rm -f build.tar.gz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment