This repository was archived by the owner on Jun 2, 2023. It is now read-only.
File tree 3 files changed +93
-10
lines changed
3 files changed +93
-10
lines changed Original file line number Diff line number Diff line change @@ -23,22 +23,15 @@ jobs:
23
23
- run :
24
24
name : Wait for db
25
25
command : dockerize -wait tcp://localhost:5432 -timeout 1m
26
- - run : make test
26
+ - run : ./.circleci/lock.sh make test
27
27
build_docker_image :
28
28
machine : true
29
29
steps :
30
30
- checkout
31
31
- run : docker login -u $DOCKER_USER -p $DOCKER_PASS
32
32
- run : git clone $DEPLOYMENTS_REPO ~/deploy
33
33
34
- - run : cp ~/deploy/golangci-worker/Dockerfile worker.dockerfile
35
- - run : docker build -t golangci/golangci-worker -f worker.dockerfile .
36
-
37
- - run : cp ~/deploy/golangci-api/Dockerfile api.dockerfile
38
- - run : docker build -t golangci/golangci-api -f api.dockerfile .
39
-
40
- - run : docker push golangci/golangci-worker
41
- - run : docker push golangci/golangci-api
34
+ - run : ./.circleci/lock.sh --branch master make build_docker_images
42
35
43
36
workflows :
44
37
version : 2
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ # https://github.com/bellkev/circle-lock-test/blob/master/do-exclusively
3
+
4
+ # sets $branch, $tag, $rest
5
+ parse_args () {
6
+ while [[ $# -gt 0 ]]; do
7
+ case $1 in
8
+ -b|--branch) branch=" $2 " ;;
9
+ -t|--tag) tag=" $2 " ;;
10
+ * ) break ;;
11
+ esac
12
+ shift 2
13
+ done
14
+ rest=(" $@ " )
15
+ }
16
+
17
+ # reads $branch, $tag, $commit_message
18
+ should_skip () {
19
+ if [[ " $branch " && " $CIRCLE_BRANCH " != " $branch " ]]; then
20
+ echo " Not on branch $branch . Skipping..."
21
+ return 0
22
+ fi
23
+
24
+ if [[ " $tag " && " $commit_message " != * \[ $tag \] * ]]; then
25
+ echo " No [$tag ] commit tag found. Skipping..."
26
+ return 0
27
+ fi
28
+
29
+ return 1
30
+ }
31
+
32
+ # reads $branch, $tag
33
+ # sets $jq_prog
34
+ make_jq_prog () {
35
+ local jq_filters=" "
36
+
37
+ if [[ $branch ]]; then
38
+ jq_filters+=" and .branch == \" $branch \" "
39
+ fi
40
+
41
+ if [[ $tag ]]; then
42
+ jq_filters+=" and (.subject | contains(\" [$tag ]\" ))"
43
+ fi
44
+
45
+ jq_prog=" .[] | select(.build_num < $CIRCLE_BUILD_NUM and (.status | test(\" running|pending|queued\" )) $jq_filters ) | .build_num"
46
+ }
47
+
48
+
49
+ if [[ " $0 " != * bats* ]]; then
50
+ set -e
51
+ set -u
52
+ set -o pipefail
53
+
54
+ branch=" "
55
+ tag=" "
56
+ rest=()
57
+ api_url=" https://circleci.com/api/v1/project/$CIRCLE_PROJECT_USERNAME /$CIRCLE_PROJECT_REPONAME ?circle-token=$CIRCLE_TOKEN &limit=100"
58
+
59
+ parse_args " $@ "
60
+ commit_message=$( git log -1 --pretty=%B)
61
+ if should_skip; then exit 0; fi
62
+ make_jq_prog
63
+
64
+ echo " Checking for running builds..."
65
+
66
+ while true ; do
67
+ builds=$( curl -s -H " Accept: application/json" " $api_url " | jq " $jq_prog " )
68
+ if [[ $builds ]]; then
69
+ echo " Waiting on builds:"
70
+ echo " $builds "
71
+ else
72
+ break
73
+ fi
74
+ echo " Retrying in 5 seconds..."
75
+ sleep 5
76
+ done
77
+
78
+ echo " Acquired lock"
79
+
80
+ if [[ " ${# rest[@]} " -ne 0 ]]; then
81
+ " ${rest[@]} "
82
+ fi
83
+ fi
Original file line number Diff line number Diff line change @@ -80,4 +80,11 @@ mod_update:
80
80
GO111MODULE=on go mod vendor
81
81
82
82
psql :
83
- docker-compose exec pg psql -U postgres -dapi_prod
83
+ docker-compose exec pg psql -U postgres -dapi_prod
84
+
85
+ build_docker_images :
86
+ cp ~ /deploy/golangci-worker/Dockerfile worker.dockerfile
87
+ docker build -t golangci/golangci-worker -f worker.dockerfile . && docker push golangci/golangci-worker
88
+
89
+ cp ~/deploy/golangci-api/Dockerfile api.dockerfile
90
+ docker build -t golangci/golangci-api -f api.dockerfile . && docker push golangci/golangci-api
You can’t perform that action at this time.
0 commit comments