forked from tsuru/tsuru
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-compose.sh
executable file
·36 lines (28 loc) · 1.08 KB
/
build-compose.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
#!/bin/bash
# This script builds tsurud inside container and call compose to build and run a new api image.
set -e
IP="10.200.10.1"
if ! `ping -c 1 -t 1 "$IP" > /dev/null`
then
CURRENT_OS="$(uname)"
if [[ "$CURRENT_OS" == "Linux" ]]; then
sudo ip addr add dev docker0 $IP/24 || true
elif [[ "$CURRENT_OS" == "Darwin" ]]; then
sudo ifconfig lo0 alias $IP/24 || true
else
echo "Unsupported OS"
exit 1
fi
fi
context=$(mktemp -d)
docker build -t tsuru-build -f Dockerfile.build $context
rmdir $context
BUILD_IMAGE='tsuru-build'
LOCAL_PKG=`go env GOPATH`'/pkg/linux_amd64'
CONTAINER_PKG='/go/pkg/linux_amd64'
CONTAINER_PROJECT_PATH='/go/src/github.com/tsuru/tsuru'
BUILD_CMD="go build -i -v --ldflags '-linkmode external -extldflags \"-static\"' -o build/tsurud ./cmd/tsurud"
set -x
docker run --rm -v ${LOCAL_PKG}:${CONTAINER_PKG} -v ${PWD}:${CONTAINER_PROJECT_PATH} -w ${CONTAINER_PROJECT_PATH} -e CC=/usr/bin/gcc -e GOPATH=/go ${BUILD_IMAGE} sh -c "${BUILD_CMD}"
docker-compose -f ${1:-"docker-compose.yml"} build api
docker-compose -f ${1:-"docker-compose.yml"} up -d