From d9605c71dd88542cfe434a7bfda19d7d7f61a95d Mon Sep 17 00:00:00 2001 From: Pablo Carranza Velez Date: Tue, 18 Jul 2017 18:43:00 -0300 Subject: [PATCH] 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 --- automation/build.sh | 39 ++++++++++++++++++++++----------------- circle.yml | 3 +-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/automation/build.sh b/automation/build.sh index 4bd5461f..257e19a9 100755 --- a/automation/build.sh +++ b/automation/build.sh @@ -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 $BASE_IMAGE + tryRemove $GO_IMAGE + tryRemove $NODE_IMAGE tryRemove $TARGET_CACHE tryRemove $BASE_CACHE diff --git a/circle.yml b/circle.yml index 753dc0b0..43c8917f 100644 --- a/circle.yml +++ b/circle.yml @@ -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)"