Skip to content

Commit

Permalink
f post merge fix to circleci config
Browse files Browse the repository at this point in the history
  • Loading branch information
jrconlin committed Aug 18, 2020
1 parent 0f44b03 commit 112ba3b
Showing 1 changed file with 64 additions and 24 deletions.
88 changes: 64 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# These environment variables must be set in CircleCI UI
#
# DOCKERHUB_REPO - docker hub repo, format: <username>/<repo>
# DOCKERHUB_ENDPOINT_REPO - same as DOCKERHUB_REPO, but for autoendpoint
# DOCKER_EMAIL - login info for docker hub
# DOCKER_USER
# DOCKER_PASS
#
#
version: 2

version: 2.1

jobs:
audit:
docker:
Expand Down Expand Up @@ -86,14 +89,20 @@ jobs:
docker:
- image: docker:18.03.0-ce
working_directory: /dockerflow
parameters:
image:
type: string
crate:
type: string
binary:
type: string
steps:
# Install these packages before checkout because git may not exist or work
- run:
name: Install Docker build dependencies
command: apk add --no-cache openssh-client git

- checkout
- setup_remote_docker

- run:
name: Create a version.json
command: |
Expand All @@ -104,47 +113,52 @@ jobs:
"$CIRCLE_PROJECT_USERNAME" \
"$CIRCLE_PROJECT_REPONAME" \
"$CIRCLE_BUILD_URL" > version.json
- run:
name: Build Docker image
command: docker build -t app:build .

# save the built docker container into CircleCI's cache. This is
command: |
docker build -t <<parameters.image>> \
--build-arg CRATE=<<parameters.crate>> \
--build-arg BINARY=<<parameters.binary>> .
# save the built docker container into CircleCI's workspace cache. This is
# required since Workflows do not have the same remote docker instance.
- run:
name: docker save app:build
command: mkdir -p /cache; docker save -o /cache/docker.tar "app:build"
- save_cache:
key: v1-{{ .Branch }}-{{ .Environment.CIRCLE_TAG }}-{{ epoch }}
name: docker save <<parameters.image>>
command: mkdir -p /cache; docker save -o /cache/docker.tar "<<parameters.image>>"
- persist_to_workspace:
root: /cache
paths:
- /cache/docker.tar
- docker.tar

deploy:
docker:
- image: docker:18.03.0-ce
parameters:
image:
type: string
repo:
type: string
steps:
- setup_remote_docker
- restore_cache:
key: v1-{{ .Branch }}-{{ .Environment.CIRCLE_TAG }}
- attach_workspace:
at: /cache
- run:
name: Restore Docker image cache
command: docker load -i /cache/docker.tar

- run:
name: Deploy to Dockerhub
command: |
# deploy master
if [ "${CIRCLE_BRANCH}" == "master" ]; then
# deploy master
docker login -u $DOCKER_USER -p $DOCKER_PASS
docker tag app:build ${DOCKERHUB_REPO}:latest
docker push ${DOCKERHUB_REPO}:latest
docker tag <<parameters.image>> <<parameters.repo>>:latest
docker push <<parameters.repo>>:latest
elif [ ! -z "${CIRCLE_TAG}" ]; then
# deploy a release tag...
# deploy a release tag
docker login -u $DOCKER_USER -p $DOCKER_PASS
echo "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
docker tag app:build "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
echo "<<parameters.repo>>:${CIRCLE_TAG}"
docker tag <<parameters.image>> "<<parameters.repo>>:${CIRCLE_TAG}"
docker images
docker push "${DOCKERHUB_REPO}:${CIRCLE_TAG}"
docker push "<<parameters.repo>>:${CIRCLE_TAG}"
fi
workflows:
Expand All @@ -155,20 +169,46 @@ workflows:
filters:
tags:
only: /.*/

- test:
filters:
tags:
only: /.*/
- build:
name: build-autopush
image: autopush:build
crate: autopush
binary: autopush_rs
filters:
tags:
only: /.*/

- build:
name: build-autoendpoint
image: autoendpoint:build
crate: autoendpoint
binary: autoendpoint
filters:
tags:
only: /.*/

- deploy:
name: deploy-autopush
image: autopush:build
repo: ${DOCKERHUB_REPO}
requires:
- build-autopush
filters:
tags:
only: /.*/
branches:
only: master

- deploy:
name: deploy-autoendpoint
image: autoendpoint:build
repo: ${DOCKERHUB_ENDPOINT_REPO}
requires:
- build
- build-autoendpoint
- test
filters:
tags:
Expand Down

0 comments on commit 112ba3b

Please sign in to comment.