Skip to content

Commit

Permalink
Updates to the CI flow for releases/publishing images (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed May 14, 2018
1 parent 9afe226 commit f71b179
Show file tree
Hide file tree
Showing 5 changed files with 373 additions and 187 deletions.
171 changes: 107 additions & 64 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
# Defaults for our CircleCI jobs.
defaults: &defaults
working_directory: ~/synse-server
docker:
- image: circleci/python:3.6.5
environment:
IMAGE_NAME: "vaporio/synse-server"


# Common config for tag-triggered workflows
tag-filters: &tag-filters
filters:
branches:
ignore: /.*/
tags:
only: /^v?[0-9]*(\.[0-9]*)*(-(\S)*)?$/


# CircleCI Config
version: 2
jobs:

# Run tests and linting for Synse Server
# test
#
# This job is run for all commits. It makes sure that: the source code
# is properly linted and tests pass.
#
# This job does not publish any build artifacts.
test:
working_directory: ~/synse-server
docker:
- image: circleci/python:3.6.4
<<: *defaults
steps:
- checkout
- run:
Expand All @@ -16,7 +38,7 @@ jobs:
pip install tox>=2.9.0 codecov>=1.4.0
- restore_cache:
keys:
- v1.5-tox-test-cache-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
- v1-test-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
- run:
name: Unit Tests
command: make test-unit
Expand All @@ -27,55 +49,86 @@ jobs:
name: Integration Tests
command: make test-integration
- save_cache:
key: v1.5-tox-test-cache-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
key: v1-test-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
paths:
- .tox/py36
- restore_cache:
keys:
- v2.6-tox-lint-cache-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
- v1-lint-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
- run:
name: Lint
command: make lint
- save_cache:
key: v2.6-tox-lint-cache-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
key: v1-lint-{{ checksum "requirements.txt" }}-{{ checksum "tox.ini" }}
paths:
- .tox/lint
- store_artifacts:
path: ./results
- store_test_results:
path: ./results/pytest
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Build Docker Image
command: make docker

# Build and push the Synse Server docker image to DockerHub
build-push:
working_directory: ~/synse-server
docker:
- image: circleci/python:3.6.4
# publish-edge
#
# This job is run when a commit is made to the 'master' branch. This
# includes commits directly to master and pull request merges. It builds
# the Docker image for the repo and publishes it to DockerHub with the
# 'edge' tag. This is effectively the 'daily/nightly' build.
publish-edge:
<<: *defaults
steps:
- checkout
- setup_remote_docker
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install Dependencies
command: |
sudo chown -R circleci:circleci /usr/local/bin
sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
pip install tox>=2.9.0
- run:
name: Build Images
name: Build and Publish Docker Images
command: |
make docker
docker login -u $DOCKER_USER -p $DOCKER_PASS
./bin/ci/build_and_publish.sh edge
# publish-release
#
# This job is run when a tag is pushed to GitHub. Simultaneous to this, a
# release will be drafted in the 'release' job. This will build the Docker
# image for the repo and publishes it to DockerHub with the 'latest' tag
# and the appropriate version tags.
publish-release:
<<: *defaults
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- run:
name: Install Dependencies
command: |
sudo chown -R circleci:circleci /usr/local/bin
sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
pip install tox>=2.9.0
- run:
name: Check Version matches Tag
command: make ci-check-version
- run:
name: Push Images
name: Build and Publish Docker Images
command: |
docker login -u ${DOCKER_USER} -p ${DOCKER_PS}
for tag in $(make tags); do
docker push ${tag}
done
docker login -u $DOCKER_USER -p $DOCKER_PASS
./bin/ci/build_and_publish.sh latest
# Package the Synse Server
# package
#
# This job packages Synse Server into a distributable Python package.
# These packages are used as build artifacts when generating releases.
package:
working_directory: ~/synse-server
docker:
- image: circleci/python:3.6.4
<<: *defaults
steps:
- checkout
- run:
Expand All @@ -86,54 +139,47 @@ jobs:
pip install -r requirements.txt
- run:
name: Package
command: python setup.py sdist --formats=gztar,zip,bztar,tar
command: make ci-package
- persist_to_workspace:
root: .
paths:
- dist


# Create a new release draft when a tag is pushed
# release
#
# This job creates a GitHub release draft for the tag that was pushed.
# It generates a changelog for the release and attaches build artifacts
# to the release as well. The release should be manually published on GitHub.
release:
working_directory: ~/synse-server
docker:
- image: circleci/golang:latest
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: true
- checkout
- run:
name: Check version matches tag
command: |
version=$(make version)
# Note the 'v' prefix to the version. We expect the tag to start with
# v, e.g. v1.2.3, but the version as defined by synse.__version__ does
# not have the 'v' prefix, so we add it here.
if [ "v${version}" != "${CIRCLE_TAG}" ]; then
echo "Version ${version} does not match Tag ${CIRCLE_TAG}"
exit 1
else
echo "Versions match: ${version}"
fi
name: Check Version matches Tag
command: make ci-check-version
- attach_workspace:
at: /tmp/workspace
- run:
name: Get GHR Distributor
command: |
go get -v github.com/tcnksm/ghr
- run:
name: Generate Changelog
command: |
tag=$(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1` || true)
since_tag=$(if [ "${tag}" ]; then echo "--since-tag ${tag}"; fi)
docker pull timfallmk/github-changelog-generator
docker run --name changelog timfallmk/github-changelog-generator \
-u vapor-ware \
-p synse-server \
--since-tag $(git describe --abbrev=0 --tags `git rev-list --tags --skip=1 --max-count=1`) \
-t ${GITHUB_TOKEN}
-u ${CIRCLE_PROJECT_USERNAME} \
-p ${CIRCLE_PROJECT_REPONAME} \
-t ${GITHUB_TOKEN} \
${since_tag}
docker cp changelog:/usr/local/src/your-app/CHANGELOG.md ./
- run:
name: Create Release
command: |
go get -v github.com/tcnksm/ghr
if git describe --exact-match --tags HEAD; then
CIRCLE_TAG=$(git describe --exact-match --tags HEAD)
fi
Expand All @@ -145,31 +191,28 @@ jobs:
-draft \
${CIRCLE_TAG} /tmp/workspace/dist
workflows:
version: 2
build:
jobs:
- test

- build-push:
- publish-edge:
context: vapor-auto
requires:
- test
filters:
branches:
only:
- master
only: master
- package:
filters:
branches:
ignore: /.*/
tags:
only: /^v?[0-9]*(\.[0-9]*)*(-rc[0-9]*)?$/

<<: *tag-filters
- release:
context: vapor-auto
<<: *tag-filters
requires:
- package
filters:
branches:
ignore: /.*/
tags:
only: /^v?[0-9]*(\.[0-9]*)*(-rc[0-9]*)?$/
- publish-release:
context: vapor-auto
<<: *tag-filters
requires:
- release

0 comments on commit f71b179

Please sign in to comment.