Skip to content

Commit 60ed81c

Browse files
rexhoffmanbors-libra
authored andcommitted
[CI] pre-release docker images with bors/auto
Closes: diem#4831 Approved by: rexhoffman Closes: diem#4851 Approved by: sausagee
1 parent 662a844 commit 60ed81c

File tree

3 files changed

+219
-52
lines changed

3 files changed

+219
-52
lines changed

.circleci/config.yml

+119-52
Original file line numberDiff line numberDiff line change
@@ -536,92 +536,152 @@ jobs:
536536
gh-pages --dotfiles --message "[skip ci] documentation update" --dist target/doc
537537
538538
######################################################################################################
539-
# Docker Builds: #
539+
# Publish docker artifacts for prs targeting release branches built in "auto" by bors #
540540
######################################################################################################
541-
542-
docker-publish:
541+
docker-pre-publish:
543542
executor: docker-executor
544543
description: publish docker images
545544
steps:
546545
- checkout
547546
- run:
548-
name: use validator to build shared layers (compile)
549-
command: |
550-
docker build --target builder -f docker/validator/Dockerfile . --tag local_build
551-
- run:
552-
name: build init
553-
command: |
554-
docker/init/build.sh
555-
- run:
556-
name: build mint
557-
command: |
558-
docker/mint/build.sh
559-
- run:
560-
name: build safety-rules
561-
command: |
562-
docker/safety-rules/build.sh
563-
- run:
564-
name: build validators
565-
command: |
566-
docker/validator/build.sh
567-
docker/validator-dynamic/build.sh
568-
- run:
569-
name: view images
547+
name: should pre build docker images (targeting a release branch)?
570548
command: |
571-
docker images
549+
export RELEASE_BRANCH_PATTERN='^v[0-9]+-release$'
550+
export TEST_BRANCH_PATTERN="^testflow[0-9]+$"
551+
export commit_message=$( git log -1 --pretty=%B )
552+
export pr_num=`echo "$commit_message" | tail -2 | head -1 | sed 's/Closes: #//'`
553+
if [ -z $pr_num ]; then
554+
echo "Did not find pull request num in commit message. -\\_(O_o)_/-";
555+
exit 1
556+
fi
557+
curl -o /tmp/pr https://api.github.com/repos/libra/libra/pulls/${pr_num}
558+
export TARGET_BRANCH=$( cat /tmp/pr | jq ".base .ref" | sed 's/"//g' )
559+
if [[ $TARGET_BRANCH =~ $RELEASE_BRANCH_PATTERN ]] || [[ $TARGET_BRANCH =~ $TEST_BRANCH_PATTERN ]]; then
560+
export BRANCH=$TARGET_BRANCH
561+
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
562+
docker/update_or_build.sh -u -p -b ${BRANCH} -n client
563+
docker/update_or_build.sh -u -p -b ${BRANCH} -n init
564+
docker/update_or_build.sh -u -p -b ${BRANCH} -n mint
565+
docker/update_or_build.sh -u -p -b ${BRANCH} -n safety-rules
566+
docker/update_or_build.sh -u -p -b ${BRANCH} -n tools
567+
docker/update_or_build.sh -u -p -b ${BRANCH} -n validator-dynamic
568+
docker/update_or_build.sh -u -p -b ${BRANCH} -n cluster-test
569+
#build but don't publish
570+
docker/update_or_build.sh -p -b ${BRANCH} -n validator
571+
else
572+
echo Targeting branch $TARGET_BRANCH will not publish docker images.
573+
fi
574+
575+
######################################################################################################
576+
# Docker Builds: #
577+
######################################################################################################
578+
docker-publish:
579+
executor: docker-executor
580+
description: publish docker images
581+
steps:
582+
- checkout
572583
- run:
573-
name: push release docker images
584+
name: pull pre images (or build if not pullable) and push release docker images
574585
command: |
575-
export BRANCH=$CIRCLE_BRANCH
576-
export GIT_REV=$(git rev-parse --short=8 HEAD)
577-
docker tag libra_init libra/test:libra_init_$BRANCH_$GIT_REV
578-
docker tag libra_mint libra/test:libra_mint_$BRANCH_$GIT_REV
579-
docker tag libra_safety_rules libra/test:libra_safety_rules_$BRANCH_$GIT_REV
580-
docker tag libra_e2e libra/test:libra_e2e_$BRANCH_$GIT_REV
581-
docker tag libra_validator_dynamic libra/test:libra_validator_dynamic_$BRANCH_$GIT_REV
586+
set -x
587+
export BRANCH=${CIRCLE_BRANCH}
582588
echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
583-
docker push libra/test:libra_init_$BRANCH_$GIT_REV
584-
docker push libra/test:libra_mint_$BRANCH_$GIT_REV
585-
docker push libra/test:libra_safety_rules_$BRANCH_$GIT_REV
586-
docker push libra/test:libra_e2e_$BRANCH_$GIT_REV
587-
docker push libra/test:libra_validator_dynamic_$BRANCH_$GIT_REV
588-
- run:
589-
name: build cluster-test
590-
command: |
591-
docker/cluster-test/build.sh
592-
- run:
593-
name: build cluster-test
594-
command: |
595-
docker tag cluster-test libra/test:cluster-test_$BRANCH_$GITHASH
596-
#echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
597-
#docker push libra/test:cluster-test_$BRANCH_$GITHASH
589+
docker/update_or_build.sh -u -b ${BRANCH} -n client
590+
docker/update_or_build.sh -u -b ${BRANCH} -n init
591+
docker/update_or_build.sh -u -b ${BRANCH} -n mint
592+
docker/update_or_build.sh -u -b ${BRANCH} -n safety-rules
593+
docker/update_or_build.sh -u -b ${BRANCH} -n tools
594+
docker/update_or_build.sh -u -b ${BRANCH} -n validator-dynamic
595+
docker/update_or_build.sh -u -b ${BRANCH} -n cluster-test
596+
598597
workflows:
599598
commit-workflow:
600599
jobs:
601-
- lint-docker
602-
- terraform
600+
- lint-docker:
601+
filters:
602+
branches:
603+
ignore:
604+
- gh-pages
605+
- master
606+
- /^testflow[\d]+$/
607+
- /^v[\d]+-release$/
608+
- terraform:
609+
filters:
610+
branches:
611+
ignore:
612+
- gh-pages
613+
- master
614+
- /^testflow[\d]+$/
615+
- /^v[\d]+-release$/
603616
- prefetch-crates
604617
- lint:
605618
requires:
606619
- prefetch-crates
620+
filters:
621+
branches:
622+
ignore:
623+
- gh-pages
624+
- /^testflow[\d]+$/
625+
- /^v[\d]+-release$/
607626
- build-dev:
608627
requires:
609628
- prefetch-crates
629+
filters:
630+
branches:
631+
ignore:
632+
- gh-pages
633+
- master
634+
- /^testflow[\d]+$/
635+
- /^v[\d]+-release$/
610636
- build-release:
611637
requires:
612638
- prefetch-crates
639+
filters:
640+
branches:
641+
ignore:
642+
- gh-pages
643+
- master
644+
- /^testflow[\d]+$/
645+
- /^v[\d]+-release$/
613646
- run-e2e-test:
614647
requires:
615648
- prefetch-crates
649+
filters:
650+
branches:
651+
ignore:
652+
- gh-pages
653+
- master
654+
- /^testflow[\d]+$/
655+
- /^v[\d]+-release$/
616656
- run-unit-test:
617657
requires:
618658
- prefetch-crates
659+
filters:
660+
branches:
661+
ignore:
662+
- gh-pages
663+
- master
664+
- /^testflow[\d]+$/
665+
- /^v[\d]+-release$/
619666
- run-crypto-unit-test:
620667
requires:
621668
- prefetch-crates
669+
filters:
670+
branches:
671+
ignore:
672+
- gh-pages
673+
- master
674+
- /^testflow[\d]+$/
675+
- /^v[\d]+-release$/
622676
- build-docs:
623677
requires:
624678
- lint
679+
filters:
680+
branches:
681+
ignore:
682+
- gh-pages
683+
- /^testflow[\d]+$/
684+
- /^v[\d]+-release$/
625685
- deploy-docs:
626686
requires:
627687
- build-docs
@@ -634,10 +694,17 @@ workflows:
634694
filters:
635695
branches:
636696
only: master
697+
- docker-pre-publish:
698+
filters:
699+
branches:
700+
only:
701+
- auto
637702
- docker-publish:
638703
filters:
639704
branches:
640-
only: circle-docker
705+
only:
706+
- /^testflow[\d]+$/
707+
- /^v[\d]+-release$/
641708

642709
scheduled-workflow:
643710
triggers:

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ target/
55
!target/libra-node-builder/libra-node
66
**/*Dockerfile
77
.circleci/config.yml
8+
docker/update_or_build.sh

docker/update_or_build.sh

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#!/bin/bash
2+
# Copyright (c) The Libra Core Contributors
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
function usage {
6+
echo "Usage:"
7+
echo "build and properly tags images for deployment to docker hub"
8+
echo "update_or_build.sh [-p] -g <GITHASH> -b <TARGET_BRANCH> -n <image name> [-u]"
9+
echo "-p indicates this a prebuild, where images are built and pushed to dockerhub with an infix of '_pre_', should be run on the 'auto' branch, trigger by bors."
10+
echo "-b the branch we're building on, or the branch we're targeting if a prebuild"
11+
echo "-n name, one of init, mint, validator, validator-dynamic, safety-rules, cluster-test"
12+
echo "-u 'upload', or 'push' the docker images will be pushed to dockerhub, otherwise only locally tag"
13+
echo "should be called from the root folder of the libra project, and must have it's .git history"
14+
}
15+
16+
PREBUILD=false;
17+
NAME=
18+
BRANCH=
19+
PUSH=false
20+
21+
#parse args
22+
while getopts "pb:n:u" arg; do
23+
case $arg in
24+
p)
25+
PREBUILD="true"
26+
;;
27+
n)
28+
NAME=$OPTARG
29+
;;
30+
b)
31+
BRANCH=$OPTARG
32+
;;
33+
u)
34+
PUSH="true"
35+
;;
36+
h)
37+
usage;
38+
exit 0;
39+
;;
40+
esac
41+
done
42+
43+
GIT_REV=$(git rev-parse --short=8 HEAD)
44+
45+
[ "$BRANCH" != "" ] || { echo "-b branch must be set"; usage; exit 99; }
46+
[ "$GIT_REV" != "" ] || { echo "Could not determine git revision, aborting"; usage; exit 99; }
47+
[ "$NAME" != "" ] || { echo "-n name must be set"; usage; exit 99; }
48+
49+
PULLED="-1"
50+
51+
#Convert dashes to underscores to get tag names, except for validator, which for some reason is "e2e"
52+
tag_name=`echo $NAME | sed 's/-/_/g'`
53+
if [ $NAME == "validator" ]; then
54+
tag_name="e2e";
55+
fi
56+
57+
#The name of the docker image built in the "auto" branch
58+
PRE_NAME=libra/test:libra_${tag_name}_pre_${BRANCH}_${GIT_REV}
59+
60+
#If not a prebuild *attempt* to pull the previously built image.
61+
if [ $PREBUILD != "true" ]; then
62+
docker pull ${PRE_NAME}
63+
export PULLED=$?
64+
fi
65+
66+
#if a prebuild, always -1, else if "docker pull" failed build the image.
67+
if [ "$PULLED" != "0" ]; then
68+
docker/$NAME/build.sh
69+
#tag the built image with consistent naming... ugh cluster-test, and e2e
70+
if [ $NAME == "cluster-test" ]; then
71+
echo retagging cluster-test as ${PRE_NAME}
72+
docker tag cluster-test ${PRE_NAME}
73+
else
74+
echo retagging libra_${tag_name} as ${PRE_NAME}
75+
docker tag libra_${tag_name} ${PRE_NAME}
76+
fi
77+
#push our tagged prebuild image if this is a prebuild. Usually means this is called from bors' auto branch.
78+
if [ $PREBUILD == "true" ]; then
79+
if [ $PUSH == "true" ]; then
80+
echo pushing ${PRE_NAME}
81+
docker push ${PRE_NAME}
82+
else
83+
echo Dry run, Not pushing ${PRE_NAME}
84+
fi
85+
fi
86+
fi
87+
88+
#if not a prebuild tag and push, usually means this is called from a release branch
89+
if [ $PREBUILD != "true" ]; then
90+
PUB_NAME=libra/test:libra_${tag_name}_${BRANCH}_${GIT_REV}
91+
echo retagging ${PRE_NAME} as ${PUB_NAME}
92+
docker tag ${PRE_NAME} ${PUB_NAME}
93+
if [ $PUSH == "true" ]; then
94+
echo pushing ${PUB_NAME}
95+
docker push ${PUB_NAME}
96+
else
97+
echo Dry run, Not pushing ${PUB_NAME}
98+
fi
99+
fi

0 commit comments

Comments
 (0)