File: build-binary

package info (click to toggle)
etcd 3.2.26%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,620 kB
  • sloc: sh: 2,191; makefile: 729
file content (91 lines) | stat: -rwxr-xr-x 1,633 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash

set -e

VER=$1
PROJ="etcd"

if [ -z "$1" ]; then
	echo "Usage: ${0} VERSION" >> /dev/stderr
	exit 255
fi

set -u

function setup_env {
	local proj=${1}
	local ver=${2}

	if [ ! -d ${proj} ]; then
		git clone https://github.com/coreos/${proj}
	fi

	pushd ${proj} >/dev/null
		git checkout master
		git fetch --all
		git reset --hard origin/master
		git checkout $ver
	popd >/dev/null
}


function package {
	local target=${1}
	local srcdir="${2}/bin"

	local ccdir="${srcdir}/${GOOS}_${GOARCH}"
	if [ -d ${ccdir} ]; then
		srcdir=${ccdir}
	fi
	local ext=""
	if [ ${GOOS} == "windows" ]; then
		ext=".exe"
	fi
	for bin in etcd etcdctl; do
		cp ${srcdir}/${bin} ${target}/${bin}${ext}
	done

	cp etcd/README.md ${target}/README.md
	cp etcd/etcdctl/README.md ${target}/README-etcdctl.md
	cp etcd/etcdctl/READMEv2.md ${target}/READMEv2-etcdctl.md

	cp -R etcd/Documentation ${target}/Documentation
}

function main {
	mkdir release
	cd release
	setup_env ${PROJ} ${VER}

	for os in darwin windows linux; do
		export GOOS=${os}
		TARGET_ARCHS=("amd64")

		if [ ${GOOS} == "linux" ]; then
			TARGET_ARCHS+=("arm64")
			TARGET_ARCHS+=("ppc64le")
		fi

		for TARGET_ARCH in "${TARGET_ARCHS[@]}"; do
			export GOARCH=${TARGET_ARCH}

			pushd etcd >/dev/null
			GO_LDFLAGS="-s" ./build
			popd >/dev/null

			TARGET="etcd-${VER}-${GOOS}-${GOARCH}"
			mkdir ${TARGET}
			package ${TARGET} ${PROJ}

			if [ ${GOOS} == "linux" ]; then
				tar cfz ${TARGET}.tar.gz ${TARGET}
				echo "Wrote release/${TARGET}.tar.gz"
			else
				zip -qr ${TARGET}.zip ${TARGET}
				echo "Wrote release/${TARGET}.zip"
			fi
		done
	done
}

main