Created
May 7, 2018 15:01
-
-
Save xavierpriour/4e3efa31c049074e55a3bda762f27dff to your computer and use it in GitHub Desktop.
meteor-in-docker production - build script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# Builds the docker image used in deployments. | |
# - embedding most files inside the image | |
# - turning on compilation and optimization | |
# - this requires the dev image as a tool (will pull it if not already available) | |
# | |
# This WILL wipe out any previous build and replace with a new one | |
# fetch build info to embed in the image | |
branch=`git rev-parse --abbrev-ref HEAD` | |
commit=`git rev-parse --short HEAD` | |
[ -z "`git status -s`" ] || untracked='+untracked' | |
repo=`basename -s .git \`git config --get remote.origin.url\`` | |
BUILD_ID="$repo#$branch@$commit$untracked" | |
BUILD_TS=`date -Iseconds` | |
echo "-- build $BUILD_ID on $BUILD_TS" | |
# dev image is our docker hub public image | |
docker_img_dev="assetsagacity/meteor-do" | |
# outuput imaeg is our private app image | |
docker_img_prod="assetsagacity/our-private-app" | |
# output dir must be a full path, as we later mount it as a docker volume | |
output_dir="$PWD/.tmp/build" | |
rm -rf $output_dir | |
mkdir -p $output_dir | |
# home dir for the builder is mounted, to provide a cache for meteor files between builds | |
home_dir=${PWD}/.tmp/home | |
mkdir -p $home_dir | |
# we do dep install + bundle build as part of this bash script, | |
# NOT inside the multi-stage dockerfile because: | |
# - we can mount code+meteor files here on run, | |
# whereas on build we could only ADD them (slowly copying them to the daemon) | |
echo "-- install dependencies" | |
docker run --rm \ | |
--volume="${PWD}":/app \ | |
--volume="$home_dir":/home/meteor \ | |
$docker_img_dev meteor npm install | |
# A few things to note | |
# - we use the dev container to build the prod image, to bypass host setup completely | |
# - we use `docker run` instead of `docker-compose` because build host might not have docker-compose | |
# - we set `METEOR_ALLOW_SUPERUSER` because host might be running this as root | |
# - we mount user /home/meteor, to provide a cache for meteor files between builds | |
echo "-- build meteor dump" | |
docker run --rm \ | |
--volume="${PWD}":/app \ | |
--volume="$home_dir":/home/meteor \ | |
--volume="$output_dir":/build \ | |
-e "METEOR_ALLOW_SUPERUSER=true" \ | |
$docker_img_dev meteor build --directory /build \ | |
&& cp Dockerfile $output_dir/Dockerfile \ | |
&& echo "-- build docker container $docker_img_prod" \ | |
&& docker build --build-arg BUILD_ID=$BUILD_ID --build-arg BUILD_TS=$BUILD_TS -t $docker_img_prod $output_dir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment