automation/build.sh: build base, nodesuper and gosuper before supervisor, and use them for cache

Otherwise the step where we build them doesn't reuse what was built when building the supervisor,
because we're explicitly setting `--cache-from` options.

We also push the images as soon as they're built.

Signed-off-by: Pablo Carranza Velez <pablo@resin.io>
This commit is contained in:
Pablo Carranza Velez 2017-07-18 18:43:00 -03:00
parent d7f7a0bf57
commit d9605c71dd
2 changed files with 23 additions and 19 deletions

View File

@ -12,7 +12,6 @@
# * ENABLE_TESTS
# * PUBNUB_SUBSCRIBE_KEY, PUBNUB_PUBLISH_KEY, MIXPANEL_TOKEN: default keys to inject in the supervisor image
# * EXTRA_TAG: when PUSH_IMAGES is true, additional tag to push to the registries
# * DOCKER_USERNAME, DOCKER_PASSWORD: if the password is set, then these will be used to login to dockerhub before pushing
#
# Builds the supervisor for the architecture defined by $ARCH.
# Will produce and push an image tagged as resin/$ARCH-supervisor:$TAG
@ -24,7 +23,7 @@
#
# In all of these cases it will use "master" if $TAG is not found.
#
# If PUSH_IMAGES is "true", it will also push the supervisor and intermediate images
# If PUSH_IMAGES is "true", it will also push the supervisor and intermediate images (must be logged in to dockerhub)
# to the docker registry.
# 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!
@ -104,36 +103,42 @@ export PUBNUB_PUBLISH_KEY
export PUBNUB_SUBSCRIBE_KEY
export MIXPANEL_TOKEN
make IMAGE=$BASE_IMAGE base
if [ "$PUSH_IMAGES" = "true" ]; then
make IMAGE=$BASE_IMAGE deploy || true
fi
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${BASE_IMAGE}"
make IMAGE=$GO_IMAGE gosuper
if [ "$PUSH_IMAGES" = "true" ]; then
make IMAGE=$GO_IMAGE deploy || true
fi
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${GO_IMAGE}"
make IMAGE=$NODE_IMAGE nodesuper
if [ "$PUSH_IMAGES" = "true" ]; then
make IMAGE=$NODE_IMAGE deploy || true
fi
export DOCKER_BUILD_OPTIONS="${DOCKER_BUILD_OPTIONS} --cache-from ${NODE_IMAGE}"
# This is the step that actually builds the supervisor
make IMAGE=$TARGET_IMAGE supervisor
if [ "$PUSH_IMAGES" = "true" ]; then
if [ -n "$DOCKER_PASSWORD" ]; then
docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
fi
make IMAGE=$TARGET_IMAGE deploy
if [ -n "$EXTRA_TAG" ]; then
docker tag $TARGET_IMAGE resin/$ARCH-supervisor:$EXTRA_TAG
make IMAGE=resin/$ARCH-supervisor:$EXTRA_TAG deploy
fi
# Try to push the intermediate images to improve caching in future builds
# But we don't care much if any of this fails.
( make IMAGE=$BASE_IMAGE base && make IMAGE=$BASE_IMAGE deploy ) || true
( make IMAGE=$GO_IMAGE gosuper && make IMAGE=$GO_IMAGE deploy ) || true
( make IMAGE=$NODE_IMAGE node && make IMAGE=$NODE_IMAGE deploy ) || true
fi
if [ "$CLEANUP" = "true" ]; then
tryRemove $TARGET_IMAGE
# Only attempt to remove intermediate imaegs if we built them
if [ "$PUSH_IMAGES" = "true" ]; then
tryRemove $BASE_IMAGE
tryRemove $GO_IMAGE
tryRemove $NODE_IMAGE
fi
tryRemove $TARGET_CACHE
tryRemove $BASE_CACHE

View File

@ -41,12 +41,11 @@ defaults: &defaults
export EXTRA_TAG=$VERSION_TAG
fi
echo "Starting build.sh"
docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD
# start the build for this architecture
export TAG=${CIRCLE_BRANCH}
export ARCH=${ARCH}
export PUSH_IMAGES=${PUSH_IMAGES}
export DOCKER_USERNAME=${DOCKER_USERNAME}
export DOCKER_PASSWORD=${DOCKER_PASSWORD}
bash automation/build.sh
if [ "${CIRCLE_BRANCH}" = "master" ] && [ "${DEPLOY_TO_RESIN}" = "true" ]; then
echo "Deploying to Resin API (staging)"