|
| 1 | +# This is a continuous build CircleCI configuration for a Docker container |
| 2 | +# intended to bulid on CircleCI to spread out testing over Travis/Circle. |
| 3 | +# The container is built and pushed to the CONTAINER_NAME variable |
| 4 | +# defined here or within the CircleCI settings. The following environment |
| 5 | +# variables are acceptable here or in these settings (for sensitive information) |
| 6 | +# |
| 7 | +# CONTAINER_NAME |
| 8 | +# DOCKER_USER |
| 9 | +# DOCKER_EMAIL |
| 10 | + |
| 11 | +################################################################################ |
| 12 | +# Functions |
| 13 | +################################################################################ |
| 14 | + |
| 15 | +# Defaults |
| 16 | + |
| 17 | +defaults: &defaults |
| 18 | + docker: |
| 19 | + - image: docker:18.01.0-ce-git |
| 20 | + working_directory: /tmp/src |
| 21 | + environment: |
| 22 | + - CONTAINER_NAME: singularityware/docker2singularity |
| 23 | + |
| 24 | +# Installation |
| 25 | + |
| 26 | +install: &install |
| 27 | + name: Install parallel gzip, gettext, python3, and jq |
| 28 | + command: apk add --no-cache pigz python3 gettext jq |
| 29 | + |
| 30 | + |
| 31 | +dockerload: &dockerload |
| 32 | + name: Load Docker container Image |
| 33 | + no_output_timeout: 30m |
| 34 | + command: | |
| 35 | + echo "Working directory is ${PWD}" |
| 36 | + docker info |
| 37 | + set +o pipefail |
| 38 | + if [ -f /tmp/cache/container.tar.gz ]; then |
| 39 | + apk update && apk add --no-cache pigz curl curl-dev |
| 40 | + pigz -d --stdout /tmp/cache/container.tar.gz | docker load |
| 41 | + fi |
| 42 | + |
| 43 | +
|
| 44 | +dockersave: &dockersave |
| 45 | + name: Docker Save |
| 46 | + no_output_timeout: 40m |
| 47 | + command: | |
| 48 | + DOCKER_TAG="v$(cat VERSION)" |
| 49 | + echo "Saving ${CONTAINER_NAME}:${DOCKER_TAG} to container.tar.gz" |
| 50 | + mkdir -p /tmp/cache |
| 51 | + docker save ${CONTAINER_NAME}:${DOCKER_TAG} \ |
| 52 | + | pigz -2 -p 3 > /tmp/cache/container.tar.gz |
| 53 | +
|
| 54 | +
|
| 55 | +dockerdeploy: &dockerdeploy |
| 56 | + name: Deploy to Docker Hub |
| 57 | + no_output_timeout: 40m |
| 58 | + command: | |
| 59 | + docker images |
| 60 | + DOCKER_TAG="v$(cat VERSION)" |
| 61 | + echo "Container name set to ${CONTAINER_NAME}:${DOCKER_TAG}" |
| 62 | + if [[ -n "$DOCKER_PASS" ]]; then |
| 63 | + docker login -u $DOCKER_USER -p $DOCKER_PASS |
| 64 | + docker push ${CONTAINER_NAME}:${DOCKER_TAG} |
| 65 | + echo "Tagging latest image..." |
| 66 | + docker tag ${CONTAINER_NAME}:${DOCKER_TAG} ${CONTAINER_NAME}:latest |
| 67 | + docker push ${CONTAINER_NAME}:latest |
| 68 | + fi |
| 69 | +
|
| 70 | +dockerbuild: &dockerbuild |
| 71 | + name: Build development Docker container |
| 72 | + command: | |
| 73 | + echo "Building base image..." |
| 74 | + DOCKER_TAG="v$(cat VERSION)" |
| 75 | + docker build -t ${CONTAINER_NAME}:${DOCKER_TAG} . |
| 76 | +
|
| 77 | +################################################################################ |
| 78 | +# Jobs |
| 79 | +################################################################################ |
| 80 | + |
| 81 | + |
| 82 | +version: 2 |
| 83 | +jobs: |
| 84 | + build: |
| 85 | + <<: *defaults |
| 86 | + steps: |
| 87 | + - checkout |
| 88 | + - restore_cache: |
| 89 | + keys: |
| 90 | + - docker-v1-{{ .Branch }} |
| 91 | + paths: |
| 92 | + - /tmp/cache/container.tar.gz |
| 93 | + - restore_cache: |
| 94 | + key: dependency-cache |
| 95 | + - setup_remote_docker |
| 96 | + - run: *install |
| 97 | + - run: *dockerload |
| 98 | + - run: *dockerbuild |
| 99 | + - run: *dockersave |
| 100 | + - persist_to_workspace: |
| 101 | + root: /tmp |
| 102 | + paths: |
| 103 | + - src |
| 104 | + - cache |
| 105 | + |
| 106 | + update_cache: |
| 107 | + <<: *defaults |
| 108 | + steps: |
| 109 | + - attach_workspace: |
| 110 | + at: /tmp |
| 111 | + - save_cache: |
| 112 | + key: docker-v1-{{ .Branch }} |
| 113 | + paths: |
| 114 | + - /tmp/cache/container.tar.gz |
| 115 | + |
| 116 | + deploy: |
| 117 | + <<: *defaults |
| 118 | + steps: |
| 119 | + - attach_workspace: |
| 120 | + at: /tmp |
| 121 | + - setup_remote_docker |
| 122 | + - run: *dockerload |
| 123 | + - run: *dockerdeploy |
| 124 | + |
| 125 | + |
| 126 | +################################################################################ |
| 127 | +# Workflows |
| 128 | +################################################################################ |
| 129 | + |
| 130 | + |
| 131 | +workflows: |
| 132 | + version: 2 |
| 133 | + build_deploy: |
| 134 | + jobs: |
| 135 | + - build: |
| 136 | + filters: |
| 137 | + branches: |
| 138 | + ignore: |
| 139 | + - gh-pages |
| 140 | + - /docs?/.*/ |
| 141 | + tags: |
| 142 | + only: /.*/ |
| 143 | + |
| 144 | + - update_cache: |
| 145 | + requires: |
| 146 | + - build |
| 147 | + filters: |
| 148 | + branches: |
| 149 | + ignore: |
| 150 | + - gh-pages |
| 151 | + - /docs?/.*/ |
| 152 | + tags: |
| 153 | + only: /.*/ |
| 154 | + |
| 155 | + # Upload the container to Docker Hub |
| 156 | + - deploy: |
| 157 | + requires: |
| 158 | + - build |
| 159 | + - update_cache |
| 160 | + filters: |
| 161 | + branches: |
| 162 | + only: master |
| 163 | + tags: |
| 164 | + only: /.*/ |
0 commit comments