2015-03-31 03:26:09 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Jenkins build steps
|
2016-12-15 18:14:53 +00:00
|
|
|
export ESCAPED_BRANCH_NAME=$(echo $sourceBranch | sed 's/[^a-z0-9A-Z_.-]/-/g')
|
2016-12-17 03:50:39 +00:00
|
|
|
git submodule update --init --recursive
|
|
|
|
git clean -fxd base-image
|
|
|
|
git submodule foreach --recursive git clean -fxd
|
|
|
|
BASE_IMAGE_VERSION=$(find base-image -print0 | LC_ALL=C sort -z | tar --null -cf - --no-recursion --mtime=@0 --owner=root --group=root --numeric-owner -T - | md5sum | awk -F " " '{print $1}')
|
2016-12-15 18:14:53 +00:00
|
|
|
export BASE_IMAGE_REPO=resin/$ARCH-supervisor-base
|
|
|
|
export BASE_IMAGE_TAG=resin/$ARCH-supervisor-base:$BASE_IMAGE_VERSION
|
|
|
|
|
|
|
|
# Try to pull the base image according to the contents of the base-image folder, otherwise build it
|
|
|
|
docker pull $BASE_IMAGE_TAG || (cd base-image && bash -ex automation/jenkins-build.sh)
|
2015-03-31 03:26:09 +00:00
|
|
|
|
2015-07-31 16:01:36 +00:00
|
|
|
# Try pulling the old build first for caching purposes.
|
|
|
|
docker pull resin/${ARCH}-supervisor:${ESCAPED_BRANCH_NAME} || docker pull resin/${ARCH}-supervisor:master || true
|
2016-09-30 19:57:57 +00:00
|
|
|
# Also pull the intermediate images, if possible, to improve caching
|
2016-12-15 18:14:53 +00:00
|
|
|
NODE_SUPERVISOR_REPO=registry.resinstaging.io/resin/node-supervisor-${ARCH}
|
|
|
|
GO_SUPERVISOR_REPO=registry.resinstaging.io/resin/go-supervisor-${ARCH}
|
|
|
|
docker pull ${NODE_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} || docker pull ${NODE_SUPERVISOR_REPO}:master || true
|
|
|
|
docker pull ${GO_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} || docker pull ${GO_SUPERVISOR_REPO}:master || true
|
2015-07-31 16:01:36 +00:00
|
|
|
|
2015-07-23 21:14:50 +00:00
|
|
|
# Test the gosuper
|
2016-10-05 19:49:53 +00:00
|
|
|
make SUPERVISOR_VERSION=${ESCAPED_BRANCH_NAME} JOB_NAME=${JOB_NAME} test-gosuper
|
2015-07-23 21:14:50 +00:00
|
|
|
|
2016-04-14 13:04:46 +00:00
|
|
|
MAKE_ARGS="ARCH=${ARCH} \
|
2016-12-15 18:14:53 +00:00
|
|
|
ESCAPED_BASE_IMAGE_TAG=$(echo $BASE_IMAGE_TAG | sed -e 's/\//\\\//g; s/\./\\\./g') \
|
2016-04-14 13:04:46 +00:00
|
|
|
PUBNUB_SUBSCRIBE_KEY=${PUBNUB_SUBSCRIBE_KEY} \
|
|
|
|
PUBNUB_PUBLISH_KEY=${PUBNUB_PUBLISH_KEY} \
|
2016-10-05 19:49:53 +00:00
|
|
|
MIXPANEL_TOKEN=${MIXPANEL_TOKEN} \
|
|
|
|
SUPERVISOR_VERSION=${ESCAPED_BRANCH_NAME}"
|
2016-04-14 13:04:46 +00:00
|
|
|
|
|
|
|
make ${MAKE_ARGS} \
|
|
|
|
DEPLOY_REGISTRY= \
|
|
|
|
deploy
|
|
|
|
|
2016-09-30 19:57:57 +00:00
|
|
|
# Try to push the intermediate images to improve caching in future builds
|
2016-12-15 18:14:53 +00:00
|
|
|
docker tag resin/node-supervisor-${ARCH}:${ESCAPED_BRANCH_NAME} ${NODE_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} \
|
|
|
|
|| docker tag -f resin/node-supervisor-${ARCH}:${ESCAPED_BRANCH_NAME} ${NODE_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} \
|
|
|
|
|| true
|
|
|
|
docker tag -f resin/go-supervisor-${ARCH}:${ESCAPED_BRANCH_NAME} ${GO_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} \
|
|
|
|
|| docker tag -f resin/go-supervisor-${ARCH}:${ESCAPED_BRANCH_NAME} ${GO_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} \
|
|
|
|
|| true
|
|
|
|
docker push ${NODE_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} || true
|
|
|
|
docker push ${GO_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME} || true
|
2016-09-30 19:57:57 +00:00
|
|
|
|
2016-04-14 13:04:46 +00:00
|
|
|
make ${MAKE_ARGS} \
|
|
|
|
DEPLOY_REGISTRY=registry.resinstaging.io/ \
|
|
|
|
deploy
|
|
|
|
|
2016-10-27 14:30:10 +00:00
|
|
|
# Cleanup removing by Id to actually remove the images rather than untagging them
|
|
|
|
docker rmi -f $(docker inspect -f "{{.Id}}" registry.resinstaging.io/resin/${ARCH}-supervisor:${ESCAPED_BRANCH_NAME}) || true
|
|
|
|
docker rmi -f $(docker inspect -f "{{.Id}}" resin/${ARCH}-supervisor:${ESCAPED_BRANCH_NAME}) || true
|
2016-12-15 18:14:53 +00:00
|
|
|
docker rmi -f $(docker inspect -f "{{.Id}}" ${NODE_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME}) || true
|
|
|
|
docker rmi -f $(docker inspect -f "{{.Id}}" ${GO_SUPERVISOR_REPO}:${ESCAPED_BRANCH_NAME}) || true
|
|
|
|
docker rmi -f $(docker inspect -f "{{.Id}}" ${BASE_IMAGE_TAG}) || true
|