forked from charmed-kubernetes/jenkins
/
build-etcd.sh
executable file
·46 lines (34 loc) · 1.12 KB
/
build-etcd.sh
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
#!/usr/bin/env bash
# Build the etcd binaries.
# The first argument ($1) should be the etcd version you would like to build.
set -o errexit # Exit when an individual command fails.
set -o pipefail # The exit status of the last command is returned.
#set -o xtrace # Print the commands that are executed.
echo "${0} started at `date`."
ETCD_VERSION=${ETCD_VERSION:-"v2.3.7"}
OS=${OS:-"linux"}
ARCH=${ARCH:-"amd64"}
SCRIPT_DIR=${PWD}
if [ ! -d etcd ]; then
# Clone the coreos etcd project.
git clone https://github.com/coreos/etcd.git etcd
fi
cd etcd
# Check out the tag or branch to build.
git checkout -f ${ETCD_VERSION}
cd ..
# Grab the user id and group id of this current user.
GROUP_ID=$(id -g)
USER_ID=$(id -u)
echo "Building etcd for ${OS} and ${ARCH} in a docker conatiner..."
docker run \
--rm \
-e "GOOS=${OS}" \
-e "GOARCH=${ARCH}" \
-v ${PWD}/etcd:/etcd \
golang \
/bin/bash -c "cd /etcd &&./build && chown -R ${USER_ID}:${GROUP_ID} /etcd"
# Copy the binaries to the output directory.
cp -v etcd/bin/* ${TEMPORARY_DIRECTORY}/${OS}/${ARCH}
cd ${SCRIPT_DIR}
echo "${0} completed successfully at `date`."