2017-07-07 21:54:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# resin-supervisor automated build
|
|
|
|
#
|
|
|
|
# Required variables:
|
|
|
|
# * ARCH
|
|
|
|
# * TAG
|
|
|
|
#
|
|
|
|
# Optional variables:
|
|
|
|
# * PUSH_IMAGES
|
|
|
|
# * CLEANUP
|
|
|
|
# * ENABLE_TESTS
|
2018-07-18 00:39:57 +00:00
|
|
|
# * MIXPANEL_TOKEN: default key to inject in the supervisor image
|
2017-07-12 17:18:35 +00:00
|
|
|
# * EXTRA_TAG: when PUSH_IMAGES is true, additional tag to push to the registries
|
2017-07-07 21:54:11 +00:00
|
|
|
#
|
|
|
|
# Builds the supervisor for the architecture defined by $ARCH.
|
|
|
|
# Will produce and push an image tagged as resin/$ARCH-supervisor:$TAG
|
|
|
|
#
|
|
|
|
# It pulls intermediate images for caching, if available:
|
|
|
|
# resin/$ARCH-supervisor-node:$TAG
|
|
|
|
#
|
|
|
|
# In all of these cases it will use "master" if $TAG is not found.
|
|
|
|
#
|
2017-07-18 21:43:00 +00:00
|
|
|
# If PUSH_IMAGES is "true", it will also push the supervisor and intermediate images (must be logged in to dockerhub)
|
2017-07-17 20:11:24 +00:00
|
|
|
# to the docker registry.
|
2017-07-07 21:54:11 +00:00
|
|
|
# If CLEANUP is "true", all images will be removed after pushing - including any relevant images
|
|
|
|
# that may have been on the host from before the build, so be careful!
|
|
|
|
# If ENABLE_TESTS is "true", tests will be run.
|
|
|
|
#
|
|
|
|
# Requires docker >= 17.05, and make.
|
|
|
|
#
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
THIS_FILE=$0
|
|
|
|
if [ -z "$ARCH" ] || [ -z "$TAG" ]; then
|
|
|
|
cat $THIS_FILE | awk '{if(/^#/)print;else exit}' | tail -n +2 | sed 's/\#//'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
function tryRemove() {
|
|
|
|
docker rmi $1 || true
|
|
|
|
}
|
|
|
|
|
|
|
|
# This is the supervisor image we will produce
|
|
|
|
TARGET_IMAGE=resin/$ARCH-supervisor:$TAG
|
|
|
|
|
|
|
|
# Intermediate images and cache
|
|
|
|
NODE_IMAGE=resin/$ARCH-supervisor-node:$TAG
|
2017-12-14 03:55:26 +00:00
|
|
|
NODE_BUILD_IMAGE=resin/$ARCH-supervisor-node:$TAG-build
|
2017-07-07 21:54:11 +00:00
|
|
|
|
|
|
|
TARGET_CACHE=$TARGET_IMAGE
|
|
|
|
NODE_CACHE=$NODE_IMAGE
|
2017-12-14 03:55:26 +00:00
|
|
|
NODE_BUILD_CACHE=$NODE_BUILD_IMAGE
|
2017-07-07 21:54:11 +00:00
|
|
|
|
2017-11-02 01:15:33 +00:00
|
|
|
TARGET_CACHE_MASTER=resin/$ARCH-supervisor:master
|
|
|
|
NODE_CACHE_MASTER=resin/$ARCH-supervisor-node:master
|
2017-12-14 03:55:26 +00:00
|
|
|
NODE_BUILD_CACHE_MASTER=resin/$ARCH-supervisor-node:master-build
|
2017-11-02 01:15:33 +00:00
|
|
|
|
2017-07-07 21:54:11 +00:00
|
|
|
CACHE_FROM=""
|
2017-11-02 01:15:33 +00:00
|
|
|
function tryPullForCache() {
|
|
|
|
image=$1
|
|
|
|
docker pull $image && {
|
|
|
|
CACHE_FROM="$CACHE_FROM --cache-from $image"
|
|
|
|
} || true
|
|
|
|
}
|
|
|
|
|
2017-07-07 21:54:11 +00:00
|
|
|
# Attempt to pull images for cache
|
|
|
|
# Only if the pull succeeds we add a --cache-from option
|
2017-11-02 01:15:33 +00:00
|
|
|
tryPullForCache $TARGET_CACHE
|
|
|
|
tryPullForCache $TARGET_CACHE_MASTER
|
|
|
|
tryPullForCache $NODE_CACHE
|
|
|
|
tryPullForCache $NODE_CACHE_MASTER
|
2017-12-14 03:55:26 +00:00
|
|
|
tryPullForCache $NODE_BUILD_CACHE
|
|
|
|
tryPullForCache $NODE_BUILD_CACHE_MASTER
|
2017-07-07 21:54:11 +00:00
|
|
|
|
|
|
|
export DOCKER_BUILD_OPTIONS=${CACHE_FROM}
|
|
|
|
export ARCH
|
|
|
|
export MIXPANEL_TOKEN
|
|
|
|
|
2017-12-14 03:55:26 +00:00
|
|
|
make IMAGE=$NODE_BUILD_IMAGE nodebuild
|
|
|
|
if [ "$PUSH_IMAGES" = "true" ]; then
|
|
|
|
make IMAGE=$NODE_BUILD_IMAGE deploy || true
|
|
|
|
fi
|
|
|
|
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${NODE_BUILD_IMAGE}"
|
|
|
|
|
|
|
|
make IMAGE=$NODE_IMAGE nodedeps
|
2017-07-18 21:43:00 +00:00
|
|
|
if [ "$PUSH_IMAGES" = "true" ]; then
|
|
|
|
make IMAGE=$NODE_IMAGE deploy || true
|
|
|
|
fi
|
|
|
|
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${NODE_IMAGE}"
|
|
|
|
|
2017-07-07 21:54:11 +00:00
|
|
|
# This is the step that actually builds the supervisor
|
|
|
|
make IMAGE=$TARGET_IMAGE supervisor
|
|
|
|
|
|
|
|
if [ "$PUSH_IMAGES" = "true" ]; then
|
|
|
|
make IMAGE=$TARGET_IMAGE deploy
|
|
|
|
|
2017-07-12 17:18:35 +00:00
|
|
|
if [ -n "$EXTRA_TAG" ]; then
|
|
|
|
docker tag $TARGET_IMAGE resin/$ARCH-supervisor:$EXTRA_TAG
|
|
|
|
make IMAGE=resin/$ARCH-supervisor:$EXTRA_TAG deploy
|
|
|
|
fi
|
2017-07-07 21:54:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$CLEANUP" = "true" ]; then
|
|
|
|
tryRemove $TARGET_IMAGE
|
|
|
|
|
2017-07-18 21:43:00 +00:00
|
|
|
tryRemove $NODE_IMAGE
|
2017-12-14 03:55:26 +00:00
|
|
|
tryRemove $NODE_BUILD_IMAGE
|
2017-07-07 21:54:11 +00:00
|
|
|
|
|
|
|
tryRemove $TARGET_CACHE
|
2017-12-14 03:55:26 +00:00
|
|
|
tryRemove $NODE_BUILD_CACHE
|
2017-07-07 21:54:11 +00:00
|
|
|
tryRemove $NODE_CACHE
|
|
|
|
fi
|