Skip to content

Commit 625a7cc

Browse files
authored
chore: make default docker image name deterministic; adjust ci build (#390)
1 parent 3dfc8c7 commit 625a7cc

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

.circleci/config.yml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ commands:
3434
- run: git submodule update --init
3535
build-docker-and-maybe-push:
3636
parameters:
37-
tagname:
38-
description: docker tag name with which to build and push
39-
type: string
40-
default: $CIRCLE_TAG
4137
push:
4238
description: whether to push created docker image after build
4339
type: boolean
@@ -59,26 +55,27 @@ commands:
5955
name: Publish Dev Docker Image to Docker Hub
6056
command: |
6157
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
62-
./scripts/push-docker-tags.sh "${IMAGE_NAME}-dev" "$CIRCLE_SHA1" "$CIRCLE_BRANCH" "<< parameters.tagname >>-dev"
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"
6360
- run:
6461
name: Publish Production Docker Image to Docker Hub
6562
command: |
6663
echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
67-
./scripts/push-docker-tags.sh "$IMAGE_NAME" "$CIRCLE_SHA1" "$CIRCLE_BRANCH" "<< parameters.tagname >>"
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
6867

6968
jobs:
7069
build-push-master:
7170
executor: dockerizer
7271
steps:
7372
- build-docker-and-maybe-push:
7473
push: true
75-
tagname: master-latest
7674
build-push-semver-tag:
7775
executor: dockerizer
7876
steps:
7977
- build-docker-and-maybe-push:
8078
push: true
81-
# use default tagname
8279
mod-tidy-check:
8380
executor: golang
8481
steps:

scripts/push-docker-tags.sh

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,35 @@
99
# what tag, if any, to push to dockerhub.
1010
#
1111
# Usage:
12-
# ./push-docker-tags.sh <image name> <git commit sha1> <git branch name> [git tag name] [dry run]
12+
# ./push-docker-tags.sh <image name> <git commit sha1> [git tag name] [dry run]
1313
#
1414
# Example:
1515
# # dry run. pass a 5th arg to have it print what it would do rather than do it.
16-
# ./push-docker-tags.sh myiamge testingsha master "" dryrun
16+
# ./push-docker-tags.sh myiamge testingsha "" dryrun
1717
#
1818
# # push tag for commit on the main branch
19-
# ./push-docker-tags.sh myimage testingsha main
19+
# ./push-docker-tags.sh myimage testingsha
2020
#
2121
# # push tag for a new release tag
22-
# ./push-docker-tags.sh myimage testingsha release v0.5.0
22+
# ./push-docker-tags.sh myimage testingsha v0.5.0
2323
#
2424
# # serving suggestion in circle ci - https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
25-
# ./push-docker-tags.sh filecoin/sentinel-visor $CIRCLE_SHA1 $CIRCLE_BRANCH $CIRCLE_TAG
25+
# ./push-docker-tags.sh filecoin/sentinel-visor $CIRCLE_SHA1 $CIRCLE_TAG
2626
#
2727
set -euo pipefail
2828

29-
if [[ $# -lt 3 ]] ; then
30-
echo 'At least 3 args required. Pass 5 args for a dry run.'
29+
if [[ $# -lt 2 ]] ; then
30+
echo 'At least 2 args required. Pass 4 args for a dry run.'
3131
echo 'Usage:'
32-
echo './push-docker-tags.sh <image name> <git commit sha1> <git branch name> [git tag name] [dry run]'
32+
echo './push-docker-tags.sh <image name> <git commit sha1> [git tag name] [dry run]'
3333
exit 1
3434
fi
3535

3636
IMAGE_NAME=$1
3737
GIT_SHA1=$2
38-
GIT_SHA1_SHORT=$(echo "$GIT_SHA1" | cut -c 1-7)
39-
GIT_BRANCH=$3
40-
GIT_TAG=${4:-""}
41-
DRY_RUN=${5:-false}
42-
DATE_SHORT=$(date -u +%F)
38+
GIT_SHA1_SHORT=$(echo "$GIT_SHA1" | cut -c 1-8)
39+
GIT_TAG=${3:-""}
40+
DRY_RUN=${4:-false}
4341

4442
pushTag () {
4543
local IMAGE_TAG="${1/\//-}"
@@ -54,8 +52,8 @@ pushTag () {
5452
fi
5553
}
5654

57-
if [ -z "$GIT_TAG" ]; then
58-
pushTag "$GIT_BRANCH-${DATE_SHORT}-${GIT_SHA1_SHORT}"
55+
if [ -z "${GIT_TAG}" ]; then
56+
pushTag "${GIT_BRANCH}-${GIT_SHA1_SHORT}"
5957
else
60-
pushTag "$GIT_TAG"
58+
pushTag "${GIT_TAG}"
6159
fi

0 commit comments

Comments
 (0)