Skip to content

Commit

Permalink
Make build scripts location-agnostic (linkerd#409)
Browse files Browse the repository at this point in the history
The build scripts assume they are executed from the root of this repo.
This prevents running scripts from other locations, for example,
`cd web && ../bin/go-run .`.

Modify the build scripts to work regardless of current directory.

Fixes linkerd#301

Signed-off-by: Andrew Seigner <siggy@buoyant.io>
  • Loading branch information
siggy committed Feb 23, 2018
1 parent b861a6d commit 304f4e1
Show file tree
Hide file tree
Showing 26 changed files with 158 additions and 113 deletions.
40 changes: 23 additions & 17 deletions BUILD.md
Expand Up @@ -189,13 +189,13 @@ build/run/debug loop faster.
In general, replace commands like this:

```bash
go run web/main.go
go run cli/main.go
```

with this:

```bash
bin/go-run web
bin/go-run cli
```

You may also leverage `go-run` to execute our `conduit` cli command. While in a
Expand Down Expand Up @@ -234,8 +234,8 @@ yarn
```bash
cd web/app
yarn && yarn webpack
cd ../..
bin/go-run web
cd ..
../bin/go-run .
```

The web server will be running on `localhost:8084`.
Expand All @@ -256,7 +256,8 @@ address of the public API server that's running in your docker environment:

```bash
docker-compose stop web
bin/go-run web --api-addr=$DOCKER_IP:8085
cd web
../bin/go-run . --api-addr=$DOCKER_IP:8085
```

#### 3. Connect to `public-api` in Kubernetes
Expand All @@ -272,7 +273,8 @@ kubectl -n conduit port-forward $POD_NAME 8085:8085
Then connect the local web process to the forwarded port:

```bash
bin/go-run web --api-addr=localhost:8085
cd web
../bin/go-run . --api-addr=localhost:8085
```

### Webpack dev server
Expand All @@ -287,7 +289,8 @@ yarn webpack-dev-server
And then set the `--webpack-dev-server` flag when running the web server:

```bash
bin/go-run web --webpack-dev-server=http://localhost:8080
cd web
../bin/go-run . --webpack-dev-server=http://localhost:8080
```

To add a JS dependency:
Expand Down Expand Up @@ -368,6 +371,7 @@ cargo check
If you make Protobuf changes, run:

```bash
bin/dep ensure
bin/protoc-go.sh
```

Expand Down Expand Up @@ -410,6 +414,8 @@ build_architecture
"_log.sh";
"_tag.sh";

"dep";

"docker-build" -> "docker-build-controller";
"docker-build" -> "docker-build-web";
"docker-build" -> "docker-build-proxy";
Expand Down Expand Up @@ -442,7 +448,6 @@ build_architecture

"docker-build-proxy" -> "_docker.sh";
"docker-build-proxy" -> "_tag.sh";
"docker-build-proxy" -> "docker-build-base";
"docker-build-proxy" -> "proxy/Dockerfile";

"docker-build-proxy-init" -> "_docker.sh";
Expand Down Expand Up @@ -473,6 +478,7 @@ build_architecture
"docker-retag-all" -> "_docker.sh";

"go-run" -> ".gorun";
"go-run" -> "root-tag";

"minikube-start-hyperv.bat";

Expand All @@ -484,15 +490,15 @@ build_architecture

"root-tag" -> "_tag.sh";

"travis.yml" -> "_gcp.sh";
"travis.yml" -> "docker-build";
"travis.yml" -> "docker-pull";
"travis.yml" -> "docker-pull-deps";
"travis.yml" -> "docker-push";
"travis.yml" -> "docker-push-deps";
"travis.yml" -> "docker-retag-all";
"travis.yml" -> "protoc-go.sh";
"travis.yml" -> "root-tag";
".travis.yml" -> "_gcp.sh";
".travis.yml" -> "dep";
".travis.yml" -> "docker-build";
".travis.yml" -> "docker-pull";
".travis.yml" -> "docker-pull-deps";
".travis.yml" -> "docker-push";
".travis.yml" -> "docker-push-deps";
".travis.yml" -> "docker-retag-all";
".travis.yml" -> "protoc-go.sh";

"update-go-deps-shas" -> "_tag.sh";
"update-go-deps-shas" -> "cli/Dockerfile-bin";
Expand Down
15 changes: 7 additions & 8 deletions bin/_docker.sh
@@ -1,11 +1,8 @@
#!/bin/sh
#
# docker
#

set -eu

. bin/_log.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

. $bindir/_log.sh

# TODO this should be set to the canonical public docker regsitry; we can override this
# docker regsistry in, for instance, CI.
Expand Down Expand Up @@ -42,8 +39,10 @@ docker_build() {
output="/dev/stderr"
fi

log_debug " :; docker build . -t $repo:$tag -f $file $extra"
docker build . \
rootdir="$( cd $bindir/.. && pwd )"

log_debug " :; docker build $rootdir -t $repo:$tag -f $file $extra"
docker build $rootdir \
-t "$repo:$tag" \
-f "$file" \
$extra \
Expand Down
5 changes: 0 additions & 5 deletions bin/_gcp.sh
@@ -1,8 +1,3 @@
#!/bin/sh
#
# gcp -- mostly for CI
#

set -eu

get_k8s_ctx() {
Expand Down
2 changes: 0 additions & 2 deletions bin/_log.sh
@@ -1,5 +1,3 @@
#!/bin/sh

set -eu

# build debug logging is disabled by default; enable with BUILD_DEBUG=1
Expand Down
12 changes: 6 additions & 6 deletions bin/_tag.sh
@@ -1,13 +1,13 @@
#!/bin/sh

set -eu

git_sha_head() {
git rev-parse --short=8 HEAD
}

go_deps_sha() {
cat Gopkg.lock Dockerfile-go-deps | shasum - | awk '{print $1}' |cut -c 1-8
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"
cat $rootdir/Gopkg.lock $rootdir/Dockerfile-go-deps | shasum - | awk '{print $1}' |cut -c 1-8
}

clean_head() {
Expand Down Expand Up @@ -59,9 +59,9 @@ validate_tag() {
fi
}

# These functions should be called by any docker-build-* script that relies on
# Go or Rust dependencies. To confirm the set of scripts that should call this
# function, run:
# This function should be called by any docker-build-* script that relies on Go
# dependencies. To confirm the set of scripts that should call this function,
# run:
# $ grep -ER 'docker-build-go-deps' .

validate_go_deps_tag() {
Expand Down
11 changes: 7 additions & 4 deletions bin/conduit
@@ -1,21 +1,24 @@
#!/bin/sh
#!/bin/bash

set -eu

bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

system=$(uname -s)

if [ "$system" = "Darwin" ]; then
bin=target/cli/darwin/conduit
bin=$rootdir/target/cli/darwin/conduit
elif [ "$system" = "Linux" ]; then
bin=target/cli/linux/conduit
bin=$rootdir/target/cli/linux/conduit
else
echo "unknown system: $system" >&2
exit 1
fi

# build conduit executable if it does not exist
if [ ! -f $bin ]; then
bin/docker-build-cli-bin >/dev/null
$bindir/docker-build-cli-bin >/dev/null
fi

exec $bin "$@"
14 changes: 8 additions & 6 deletions bin/docker-build
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -eu

Expand All @@ -7,9 +7,11 @@ if [ $# -ne 0 ]; then
exit 64
fi

bin/docker-build-controller
bin/docker-build-web
bin/docker-build-proxy-init
bin/docker-build-cli
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

bin/docker-build-proxy
$bindir/docker-build-controller
$bindir/docker-build-web
$bindir/docker-build-proxy-init
$bindir/docker-build-cli

$bindir/docker-build-proxy
9 changes: 6 additions & 3 deletions bin/docker-build-base
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# Builds (or pulls) our base runtime docker image.

Expand All @@ -9,12 +9,15 @@ if [ $# -ne 0 ]; then
exit 64
fi

. bin/_docker.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

. $bindir/_docker.sh

tag="2017-10-30.01"

if (docker_pull base "${tag}"); then
echo "$(docker_repo base):${tag}"
else
docker_build base "${tag}" Dockerfile-base
docker_build base "${tag}" $rootdir/Dockerfile-base
fi
13 changes: 8 additions & 5 deletions bin/docker-build-cli
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -eu

Expand All @@ -7,10 +7,13 @@ if [ $# -ne 0 ]; then
exit 64
fi

. bin/_docker.sh
. bin/_tag.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

. $bindir/_docker.sh
. $bindir/_tag.sh

# Build gcr.io/runconduit/cli-bin, which is used by cli/Dockerfile.
bin/docker-build-cli-bin >/dev/null
$bindir/docker-build-cli-bin >/dev/null

docker_build cli "$(head_root_tag)" cli/Dockerfile
docker_build cli "$(head_root_tag)" $rootdir/cli/Dockerfile
17 changes: 10 additions & 7 deletions bin/docker-build-cli-bin
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -eu

Expand All @@ -7,16 +7,19 @@ if [ $# -ne 0 ]; then
exit 64
fi

. bin/_docker.sh
. bin/_tag.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

dockerfile=cli/Dockerfile-bin
. $bindir/_docker.sh
. $bindir/_tag.sh

dockerfile=$rootdir/cli/Dockerfile-bin

validate_go_deps_tag $dockerfile

(
bin/docker-build-base
bin/docker-build-go-deps
$bindir/docker-build-base
$bindir/docker-build-go-deps
) >/dev/null

tag="$(head_root_tag)"
Expand All @@ -26,7 +29,7 @@ ID=$(docker create "$IMG")

# copy the newly built conduit cli binaries to the local system
for OS in darwin linux windows ; do
DIR="target/cli/${OS}"
DIR="${rootdir}/target/cli/${OS}"
mkdir -p "$DIR"

if docker cp "$ID:/out/conduit-${OS}" "$DIR/conduit" ; then
Expand Down
15 changes: 9 additions & 6 deletions bin/docker-build-controller
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

set -eu

Expand All @@ -7,16 +7,19 @@ if [ $# -ne 0 ]; then
exit 64
fi

. bin/_docker.sh
. bin/_tag.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

dockerfile=controller/Dockerfile
. $bindir/_docker.sh
. $bindir/_tag.sh

dockerfile=$rootdir/controller/Dockerfile

validate_go_deps_tag $dockerfile

(
bin/docker-build-base
bin/docker-build-go-deps
$bindir/docker-build-base
$bindir/docker-build-go-deps
) >/dev/null

tag="$(head_root_tag)"
Expand Down
11 changes: 7 additions & 4 deletions bin/docker-build-go-deps
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# Builds (or pulls) our go-deps docker image.

Expand All @@ -9,13 +9,16 @@ if [ $# -ne 0 ]; then
exit 64
fi

. bin/_docker.sh
. bin/_tag.sh
bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

. $bindir/_docker.sh
. $bindir/_tag.sh

tag=$(go_deps_sha)

if (docker_pull go-deps "${tag}"); then
echo "$(docker_repo go-deps):${tag}"
else
docker_build go-deps "${tag}" Dockerfile-go-deps
rootdir="$( cd $bindir/.. && pwd )"
docker_build go-deps "${tag}" $rootdir/Dockerfile-go-deps
fi

0 comments on commit 304f4e1

Please sign in to comment.