-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3404 from vegaprotocol/3400-ci-docker-image-build
Fix CI docker image build (#3400)
- Loading branch information
1 parent
150398c
commit e75064c
Showing
3 changed files
with
117 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Vega specific entries | ||
cmd/*/*-dbg | ||
cmd/vega/vega* | ||
cmd/vegabenchmark/vegabenchmark* | ||
data/ | ||
.DS_Store | ||
.envrc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,96 @@ | ||
#!/usr/bin/env bash | ||
|
||
default_combinations="linux,amd64 | ||
darwin,amd64 | ||
windows,amd64" | ||
|
||
all_combinations="$default_combinations | ||
linux,386 | ||
linux,arm64 | ||
linux,mips64 | ||
linux,mips64le | ||
linux,mips | ||
linux,mipsle | ||
windows,386" | ||
# Get a list of apps to build by looking at the directories in cmd. | ||
mapfile -t apps < <(find cmd -maxdepth 1 -and -not -name cmd | sed -e 's#^cmd/##' | sort) | ||
|
||
default_combinations=( | ||
linux-amd64 | ||
darwin-amd64 | ||
windows-amd64 | ||
) | ||
|
||
all_combinations=("${default_combinations[@]}") | ||
all_combinations+=( | ||
linux-386 | ||
linux-arm64 | ||
linux-mips64 | ||
linux-mips64le | ||
linux-mips | ||
linux-mipsle | ||
windows-386 | ||
) | ||
|
||
case "${1:-}" in | ||
"") combinations="$default_combinations" ;; | ||
default) combinations="$default_combinations" ;; | ||
all) combinations="$all_combinations" ;; | ||
*) echo "Invalid: $1" ; exit 1 ;; | ||
"") | ||
combinations=("${default_combinations[@]}") | ||
;; | ||
default) | ||
combinations=("${default_combinations[@]}") | ||
;; | ||
all) | ||
combinations=("${all_combinations[@]}") | ||
;; | ||
*) | ||
echo "Invalid: $1" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
version="${DRONE_TAG:-$(git describe --tags 2>/dev/null)}" | ||
version_hash="$(echo "${CI_COMMIT_SHA:-$(git rev-parse HEAD)}" | cut -b1-8)" | ||
ldflags="-X main.CLIVersion=$version -X main.CLIVersionHash=$version_hash" | ||
|
||
pidsfile="$(mktemp)" | ||
for combo in $combinations ; do | ||
goos="$(echo "$combo" | cut -f1 -d,)" | ||
goarch="$(echo "$combo" | cut -f2 -d,)" | ||
case "$goos" in | ||
windows) o="cmd/vega/vega-$goos-$goarch.exe" ;; | ||
*) o="cmd/vega/vega-$goos-$goarch" ;; | ||
build_app() { | ||
local app | ||
app="${1:?}" | ||
|
||
local combo goarch goos ldflags o pidsfile | ||
|
||
case "$app" in | ||
vega) | ||
version="${DRONE_TAG:-$(git describe --tags 2>/dev/null)}" | ||
version_hash="$(echo "${CI_COMMIT_SHA:-$(git rev-parse HEAD)}" | cut -b1-8)" | ||
ldflags="-X main.CLIVersion=$version -X main.CLIVersionHash=$version_hash" | ||
;; | ||
*) | ||
ldflags="" | ||
;; | ||
esac | ||
env \ | ||
CGO_ENABLED=0 \ | ||
GOOS="$goos" \ | ||
GOARCH="$goarch" \ | ||
go build -o "$o" -ldflags "$ldflags" ./cmd/vega & | ||
pid="$!" | ||
echo "Building for OS=$goos arch=$goarch in subprocess $pid" | ||
echo "$pid" >>"$pidsfile" | ||
done | ||
|
||
final=0 | ||
while read -r pid ; do | ||
echo -n "Waiting for subprocess $pid ..." | ||
wait "$pid" | ||
code="$?" | ||
if test "$code" = 0 ; then | ||
echo "OK" | ||
else | ||
echo "code $code" | ||
final="$((final+1))" | ||
pidsfile="$(mktemp)" | ||
for combo in "${combinations[@]}" ; do | ||
goos="$(echo "$combo" | cut -f1 -d-)" | ||
goarch="$(echo "$combo" | cut -f2 -d-)" | ||
case "$goos" in | ||
windows) o="cmd/$app/$app-$goos-$goarch.exe" ;; | ||
*) o="cmd/$app/$app-$goos-$goarch" ;; | ||
esac | ||
env \ | ||
CGO_ENABLED=0 \ | ||
GOOS="$goos" \ | ||
GOARCH="$goarch" \ | ||
go build -o "$o" -ldflags "$ldflags" "./cmd/$app" & | ||
pid="$!" | ||
echo "Building $app for OS=$goos arch=$goarch in subprocess $pid" | ||
echo "$pid" >>"$pidsfile" | ||
done | ||
|
||
final=0 | ||
while read -r pid ; do | ||
echo -n "Waiting for subprocess $pid ..." | ||
wait "$pid" | ||
code="$?" | ||
if test "$code" = 0 ; then | ||
echo "OK" | ||
else | ||
echo "code $code" | ||
final="$((final+1))" | ||
fi | ||
done <"$pidsfile" | ||
rm -f "$pidsfile" | ||
|
||
if test "$final" -gt 0 ; then | ||
echo "Failed to build $app" | ||
exit "$final" | ||
fi | ||
done <"$pidsfile" | ||
rm -f "$pidsfile" | ||
} | ||
|
||
exit "$final" | ||
for app in "${apps[@]}" ; do | ||
build_app "$app" | ||
done |