Skip to content

Commit e75064c

Browse files
committed
Merge pull request #3404 from vegaprotocol/3400-ci-docker-image-build
Fix CI docker image build (#3400)
1 parent 150398c commit e75064c

3 files changed

Lines changed: 117 additions & 50 deletions

File tree

.drone-github.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ steps:
4848
./script/build-multiarch-no-cgo.sh default || exit 1 ;
4949
else
5050
echo "No Go files changed. Skipping building of binary." ;
51-
rm -f cmd/vega/vega-* ;
51+
rm -f cmd/vega/vega-* cmd/vegabenchmark/vegabenchmark-* ;
5252
fi
5353
depends_on:
5454
- fetch
@@ -73,6 +73,35 @@ steps:
7373
event:
7474
- pull_request
7575

76+
- name: build_docker_image-PR
77+
image: docker.pkg.github.com/vegaprotocol/devops-infra/cipipeline-docker:18.09.9
78+
volumes:
79+
- name: dockersock
80+
path: /run/docker.sock
81+
environment:
82+
DOCKER_HOST: unix:///run/docker.sock
83+
DOCKER_CONFIG_JSON:
84+
from_secret: dockerconfig
85+
commands:
86+
- mkdir -p docker/bin
87+
- find cmd -maxdepth 1 -and -not -name cmd | sed -e 's#^cmd/##' | while read -r app ; do
88+
if test -f "cmd/$$app/$$app-linux-amd64" ; then
89+
cp -a "cmd/$$app/$$app-linux-amd64" "docker/bin/$$app" || exit 1 ;
90+
else
91+
echo "dummy_noop" >"docker/bin/$$app" ;
92+
fi ;
93+
done
94+
- tmptag="$$(openssl rand -hex 10)"
95+
- docker build -t "docker.pkg.github.com/vegaprotocol/vega/vega:$$tmptag" docker/
96+
- rm -rf docker/bin
97+
- mkdir -p "$$HOME/.docker" ; echo "$$DOCKER_CONFIG_JSON" >"$$HOME/.docker/config.json" ; unset DOCKER_CONFIG_JSON
98+
- docker rmi "docker.pkg.github.com/vegaprotocol/vega/vega:$$tmptag"
99+
depends_on:
100+
- build-PR
101+
when:
102+
event:
103+
- pull_request
104+
76105
- name: test-PR
77106
image: docker.pkg.github.com/vegaprotocol/devops-infra/cipipeline:1.16.2
78107
volumes:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Vega specific entries
22
cmd/*/*-dbg
33
cmd/vega/vega*
4+
cmd/vegabenchmark/vegabenchmark*
45
data/
56
.DS_Store
67
.envrc

script/build-multiarch-no-cgo.sh

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,96 @@
11
#!/usr/bin/env bash
22

3-
default_combinations="linux,amd64
4-
darwin,amd64
5-
windows,amd64"
6-
7-
all_combinations="$default_combinations
8-
linux,386
9-
linux,arm64
10-
linux,mips64
11-
linux,mips64le
12-
linux,mips
13-
linux,mipsle
14-
windows,386"
3+
# Get a list of apps to build by looking at the directories in cmd.
4+
mapfile -t apps < <(find cmd -maxdepth 1 -and -not -name cmd | sed -e 's#^cmd/##' | sort)
5+
6+
default_combinations=(
7+
linux-amd64
8+
darwin-amd64
9+
windows-amd64
10+
)
11+
12+
all_combinations=("${default_combinations[@]}")
13+
all_combinations+=(
14+
linux-386
15+
linux-arm64
16+
linux-mips64
17+
linux-mips64le
18+
linux-mips
19+
linux-mipsle
20+
windows-386
21+
)
1522

1623
case "${1:-}" in
17-
"") combinations="$default_combinations" ;;
18-
default) combinations="$default_combinations" ;;
19-
all) combinations="$all_combinations" ;;
20-
*) echo "Invalid: $1" ; exit 1 ;;
24+
"")
25+
combinations=("${default_combinations[@]}")
26+
;;
27+
default)
28+
combinations=("${default_combinations[@]}")
29+
;;
30+
all)
31+
combinations=("${all_combinations[@]}")
32+
;;
33+
*)
34+
echo "Invalid: $1"
35+
exit 1
36+
;;
2137
esac
2238

23-
version="${DRONE_TAG:-$(git describe --tags 2>/dev/null)}"
24-
version_hash="$(echo "${CI_COMMIT_SHA:-$(git rev-parse HEAD)}" | cut -b1-8)"
25-
ldflags="-X main.CLIVersion=$version -X main.CLIVersionHash=$version_hash"
26-
27-
pidsfile="$(mktemp)"
28-
for combo in $combinations ; do
29-
goos="$(echo "$combo" | cut -f1 -d,)"
30-
goarch="$(echo "$combo" | cut -f2 -d,)"
31-
case "$goos" in
32-
windows) o="cmd/vega/vega-$goos-$goarch.exe" ;;
33-
*) o="cmd/vega/vega-$goos-$goarch" ;;
39+
build_app() {
40+
local app
41+
app="${1:?}"
42+
43+
local combo goarch goos ldflags o pidsfile
44+
45+
case "$app" in
46+
vega)
47+
version="${DRONE_TAG:-$(git describe --tags 2>/dev/null)}"
48+
version_hash="$(echo "${CI_COMMIT_SHA:-$(git rev-parse HEAD)}" | cut -b1-8)"
49+
ldflags="-X main.CLIVersion=$version -X main.CLIVersionHash=$version_hash"
50+
;;
51+
*)
52+
ldflags=""
53+
;;
3454
esac
35-
env \
36-
CGO_ENABLED=0 \
37-
GOOS="$goos" \
38-
GOARCH="$goarch" \
39-
go build -o "$o" -ldflags "$ldflags" ./cmd/vega &
40-
pid="$!"
41-
echo "Building for OS=$goos arch=$goarch in subprocess $pid"
42-
echo "$pid" >>"$pidsfile"
43-
done
4455

45-
final=0
46-
while read -r pid ; do
47-
echo -n "Waiting for subprocess $pid ..."
48-
wait "$pid"
49-
code="$?"
50-
if test "$code" = 0 ; then
51-
echo "OK"
52-
else
53-
echo "code $code"
54-
final="$((final+1))"
56+
pidsfile="$(mktemp)"
57+
for combo in "${combinations[@]}" ; do
58+
goos="$(echo "$combo" | cut -f1 -d-)"
59+
goarch="$(echo "$combo" | cut -f2 -d-)"
60+
case "$goos" in
61+
windows) o="cmd/$app/$app-$goos-$goarch.exe" ;;
62+
*) o="cmd/$app/$app-$goos-$goarch" ;;
63+
esac
64+
env \
65+
CGO_ENABLED=0 \
66+
GOOS="$goos" \
67+
GOARCH="$goarch" \
68+
go build -o "$o" -ldflags "$ldflags" "./cmd/$app" &
69+
pid="$!"
70+
echo "Building $app for OS=$goos arch=$goarch in subprocess $pid"
71+
echo "$pid" >>"$pidsfile"
72+
done
73+
74+
final=0
75+
while read -r pid ; do
76+
echo -n "Waiting for subprocess $pid ..."
77+
wait "$pid"
78+
code="$?"
79+
if test "$code" = 0 ; then
80+
echo "OK"
81+
else
82+
echo "code $code"
83+
final="$((final+1))"
84+
fi
85+
done <"$pidsfile"
86+
rm -f "$pidsfile"
87+
88+
if test "$final" -gt 0 ; then
89+
echo "Failed to build $app"
90+
exit "$final"
5591
fi
56-
done <"$pidsfile"
57-
rm -f "$pidsfile"
92+
}
5893

59-
exit "$final"
94+
for app in "${apps[@]}" ; do
95+
build_app "$app"
96+
done

0 commit comments

Comments
 (0)