Skip to content

Commit

Permalink
Use local build script in CI
Browse files Browse the repository at this point in the history
- Extracts commands into a separate script
- Updates CI to Docker 17.X
- Normalises pushed images to:
  - revision: eg. 22dd724
  - branch: maintenance
  - semver: eg v1.5.2-5-g22dd724

Change-Type: patch
  • Loading branch information
dfunckt committed Mar 13, 2018
1 parent 5130f53 commit 435adf0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
36 changes: 9 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: library/docker:1.12.6
- image: library/docker:17
working_directory: /tmp/build
environment:
DOCKER_USERNAME: travisciresin
Expand All @@ -14,31 +14,13 @@ jobs:
version: 17.07.0-ce
reusable: true
exclusive: false
- run: |
docker info
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
- run:
name: Build
- run:
name: Setup
command: |
set -ex
docker pull ${DOCKER_IMAGE}:${CIRCLE_BRANCH} || true
docker build --rm=false --pull --tag ${DOCKER_IMAGE}:${CIRCLE_SHA1} .
- deploy:
docker info
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
apk add --no-cache git
- run:
name: Build and push
command: |
docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"
set -ex
docker push ${DOCKER_IMAGE}:${CIRCLE_SHA1}
docker tag ${DOCKER_IMAGE}:${CIRCLE_SHA1} ${DOCKER_IMAGE}:${CIRCLE_BRANCH}
docker push ${DOCKER_IMAGE}:${CIRCLE_BRANCH}
if [ "${CIRCLE_TAG}" != "" ]; then
docker tag ${DOCKER_IMAGE}:${CIRCLE_SHA1} ${DOCKER_IMAGE}:${CIRCLE_TAG}
docker push ${DOCKER_IMAGE}:${CIRCLE_TAG}
fi
# Tag the branch
apk add --no-cache git
tag=$(git describe --tags) || true
if [ "${tag}" != "" ]; then
docker tag ${DOCKER_IMAGE}:${CIRCLE_SHA1} ${DOCKER_IMAGE}:${tag}
docker push ${DOCKER_IMAGE}:${tag}
fi
IMAGE_NAME=$DOCKER_IMAGE BRANCH_NAME=$CIRCLE_BRANCH ./automation/build.sh
23 changes: 23 additions & 0 deletions automation/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
set -e

# Input is:
# - IMAGE_NAME: the repo to push the image to, eg. resin/repository-name
# - BRANCH_NAME: eg. fix-some-bug

VERSION=$(git describe --tags)
REVISION=$(git rev-parse --short HEAD)
BRANCH=$(echo $BRANCH_NAME | sed 's/[^a-z0-9A-Z_.-]/-/g')

# Try pulling the old build first for caching purposes.
docker pull ${IMAGE_NAME}:${BRANCH} || docker pull ${IMAGE_NAME}:master || true

# Build and tag
docker build --pull --tag ${IMAGE_NAME}:${REVISION} .
docker tag ${IMAGE_NAME}:${REVISION} ${IMAGE_NAME}:${BRANCH}
docker tag ${IMAGE_NAME}:${REVISION} ${IMAGE_NAME}:${VERSION}

# Push the images
docker push ${IMAGE_NAME}:${REVISION}
docker push ${IMAGE_NAME}:${BRANCH}
docker push ${IMAGE_NAME}:${VERSION}

0 comments on commit 435adf0

Please sign in to comment.