Skip to content

Commit 8bec4ae

Browse files
authored
fix: correct docker image name; simplify build pipeline (#393)
1 parent dcc5517 commit 8bec4ae

File tree

2 files changed

+61
-50
lines changed

2 files changed

+61
-50
lines changed

.circleci/config.yml

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,50 +32,68 @@ commands:
3232
- run: sudo apt-get update
3333
- run: git submodule sync
3434
- run: git submodule update --init
35-
build-docker-and-maybe-push:
36-
parameters:
37-
push:
38-
description: whether to push created docker image after build
39-
type: boolean
40-
default: false
35+
publish-docker-master-production:
4136
steps:
42-
- checkout
43-
- setup_remote_docker:
44-
version: "18.09.3"
45-
- run:
46-
name: Build Dev Docker image
47-
command: docker build -t ${IMAGE_NAME}-dev -f Dockerfile.dev .
4837
- run:
4938
name: Build Production Docker image
5039
command: docker build -t $IMAGE_NAME -f Dockerfile .
51-
- when:
52-
condition: << parameters.push >>
53-
steps:
54-
- run:
55-
name: Publish Dev Docker Image to Docker Hub
56-
command: |
57-
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
58-
tag_suffix=$(echo "$CIRCLE_SHA1" | cut -c 1-8)
59-
./scripts/push-docker-tags.sh "${IMAGE_NAME}-dev" "$CIRCLE_SHA1" "${CIRCLE_BRANCH}-${tag_suffix}-dev"
60-
- run:
61-
name: Publish Production Docker Image to Docker Hub
62-
command: |
63-
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
64-
tag_suffix=$(echo "$CIRCLE_SHA1" | cut -c 1-8)
65-
./scripts/push-docker-tags.sh "${IMAGE_NAME}-dev" "$CIRCLE_SHA1" "${CIRCLE_BRANCH}-${tag_suffix}"
66-
when: always
40+
- run:
41+
name: Publish Production Docker Image to Docker Hub
42+
command: |
43+
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
44+
tag_suffix=$(echo "$CIRCLE_SHA1" | cut -c 1-8)
45+
./scripts/push-docker-tags.sh "${IMAGE_NAME}" "$CIRCLE_SHA1" "${CIRCLE_BRANCH}-${tag_suffix}"
46+
publish-docker-master-dev:
47+
steps:
48+
- run:
49+
name: Build Dev Docker image
50+
command: docker build -t ${IMAGE_NAME} -f Dockerfile.dev .
51+
- run:
52+
name: Publish Dev Docker Image to Docker Hub
53+
command: |
54+
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
55+
tag_suffix=$(echo "$CIRCLE_SHA1" | cut -c 1-8)
56+
./scripts/push-docker-tags.sh "${IMAGE_NAME}" "$CIRCLE_SHA1" "${CIRCLE_BRANCH}-${tag_suffix}-dev"
57+
publish-docker-semver-production:
58+
steps:
59+
- run:
60+
name: Build Production Semver Docker image
61+
command: docker build -t ${IMAGE_NAME} -f Dockerfile .
62+
- run:
63+
name: Publish Production Semver Docker Image to Docker Hub
64+
command: |
65+
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
66+
./scripts/push-docker-tags.sh "${IMAGE_NAME}" "$CIRCLE_SHA1" "${CIRCLE_TAG}"
67+
publish-docker-semver-dev:
68+
steps:
69+
- run:
70+
name: Build Dev Semver Docker image
71+
command: docker build -t ${IMAGE_NAME} -f Dockerfile.dev .
72+
- run:
73+
name: Publish Dev Semver Docker Image to Docker Hub
74+
command: |
75+
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
76+
./scripts/push-docker-tags.sh "${IMAGE_NAME}" "$CIRCLE_SHA1" "${CIRCLE_TAG}-dev"
6777
6878
jobs:
69-
build-push-master:
79+
publish-docker-from-master:
7080
executor: dockerizer
7181
steps:
72-
- build-docker-and-maybe-push:
73-
push: true
74-
build-push-semver-tag:
82+
- checkout
83+
- setup_remote_docker:
84+
docker_layer_caching: true
85+
version: "18.09.3"
86+
- publish-docker-master-dev
87+
- publish-docker-master-production
88+
publish-docker-from-tag:
7589
executor: dockerizer
7690
steps:
77-
- build-docker-and-maybe-push:
78-
push: true
91+
- checkout
92+
- setup_remote_docker:
93+
docker_layer_caching: true
94+
version: "18.09.3"
95+
- publish-docker-semver-dev
96+
- publish-docker-semver-production
7997
mod-tidy-check:
8098
executor: golang
8199
steps:
@@ -124,18 +142,18 @@ workflows:
124142
jobs:
125143
- mod-tidy-check
126144
- test
127-
docker-and-deploy:
145+
build-docker-images:
128146
# `build-push-*` runs on master or main branches and tags that look like semver
129147
# see: https://circleci.com/docs/2.0/workflows/#executing-workflows-for-a-git-tag
130148
jobs:
131-
- build-push-master:
149+
- publish-docker-from-master:
132150
# build and push latest master docker image
133151
filters:
134152
branches:
135153
only: /^(master|main)$/
136154
tags:
137155
ignore: /.*/
138-
- build-push-semver-tag:
156+
- publish-docker-from-tag:
139157
# build and push semver tags docker image
140158
filters:
141159
branches:

scripts/push-docker-tags.sh

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99
# what tag, if any, to push to dockerhub.
1010
#
1111
# Usage:
12-
# ./push-docker-tags.sh <image name> <git commit sha1> [git tag name] [dry run]
12+
# ./push-docker-tags.sh <image name> <git commit sha1> <docker tag> [dry run]
1313
#
1414
# Example:
1515
# # dry run. pass a 5th arg to have it print what it would do rather than do it.
1616
# ./push-docker-tags.sh myiamge testingsha "" dryrun
1717
#
18-
# # push tag for commit on the main branch
19-
# ./push-docker-tags.sh myimage testingsha
20-
#
2118
# # push tag for a new release tag
2219
# ./push-docker-tags.sh myimage testingsha v0.5.0
2320
#
@@ -26,10 +23,10 @@
2623
#
2724
set -euo pipefail
2825

29-
if [[ $# -lt 2 ]] ; then
30-
echo 'At least 2 args required. Pass 4 args for a dry run.'
26+
if [[ $# -lt 3 ]] ; then
27+
echo 'At least 3 args required. Pass 4 args for a dry run.'
3128
echo 'Usage:'
32-
echo './push-docker-tags.sh <image name> <git commit sha1> [git tag name] [dry run]'
29+
echo './push-docker-tags.sh <image name> <git commit sha1> <docker tag> [dry run]'
3330
exit 1
3431
fi
3532

@@ -40,7 +37,7 @@ GIT_TAG=${3:-""}
4037
DRY_RUN=${4:-false}
4138

4239
pushTag () {
43-
local IMAGE_TAG="${1/\//-}"
40+
local IMAGE_TAG="${1//\//-}"
4441
if [ "$DRY_RUN" != false ]; then
4542
echo "DRY RUN!"
4643
echo docker tag "$IMAGE_NAME" "$IMAGE_NAME:$IMAGE_TAG"
@@ -52,8 +49,4 @@ pushTag () {
5249
fi
5350
}
5451

55-
if [ -z "${GIT_TAG}" ]; then
56-
pushTag "${GIT_BRANCH}-${GIT_SHA1_SHORT}"
57-
else
58-
pushTag "${GIT_TAG}"
59-
fi
52+
pushTag "${GIT_TAG}"

0 commit comments

Comments
 (0)