improve install from source

* Idempotent clone_and_build.sh does everything
* Add documentation for how to build in Docker

Had to sacrificy go generate because stringer apparently can't handle
vendor directory used by go dep, fails with error
on go generate rpc/frame_layer.go

refs #37
This commit is contained in:
Christian Schwarz 2017-11-12 16:15:12 +01:00
parent 3b6cede108
commit 47726ad877
3 changed files with 79 additions and 16 deletions

View File

@ -7,14 +7,14 @@ _TESTPKGS := $(ROOT) $(foreach p,$(SUBPKGS),$(ROOT)/$(p))
ARTIFACTDIR := artifacts
build: generate
go build -o $(ARTIFACTDIR)/zrepl
generate:
generate: #not part of the build, must do that manually
@for pkg in $(_TESTPKGS); do\
go generate "$$pkg" || exit 1; \
done;
build:
go build -o $(ARTIFACTDIR)/zrepl
test:
@for pkg in $(_TESTPKGS); do \
echo "Testing $$pkg"; \
@ -39,7 +39,7 @@ cover: artifacts
artifacts:
mkdir artifacts
release: generate artifacts vet test
release: artifacts vet test
GOOS=linux GOARCH=amd64 go build -o "$(ARTIFACTDIR)/zrepl-linux-amd64"
GOOS=freebsd GOARCH=amd64 go build -o "$(ARTIFACTDIR)/zrepl-freebsd-amd64"

45
clone_and_build.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/sh -e
bold=$(tput bold)
normal=$(tput sgr0)
step() {
echo "${bold}$1${normal}"
}
if [ -z "$GOPATH" ]; then
step "Make sure you have your GOPATH configured correctly" 1>&2
exit 1
fi
step "Checkout sources to \$GOPATH/github.com/zrepl/zrepl"
CHECKOUTPATH="${GOPATH}/src/github.com/zrepl/zrepl"
if [ -e "$CHECKOUTPATH" ]; then
echo "${CHECKOUTPATH} already exists"
if [ ! -d "$CHECKOUTPATH" ]; then
echo "${CHECKOUTPATH} is not a directory, aborting" 1>&2
else
cd "$CHECKOUTPATH"
fi
else
mkdir -p "$GOPATH/src/github.com/zrepl"
cd "$GOPATH/src/github.com/zrepl"
git clone https://github.com/zrepl/zrepl.git
cd zrepl
fi
step "Install build depdencies using 'go get' to \$GOPATH/bin"
go get -u golang.org/x/tools/cmd/stringer
go get -u github.com/golang/dep/cmd/dep
if ! type stringer || ! type dep; then
echo "Installed dependencies but can't find them in \$PATH, adjust it to contain \$GOPATH/bin" 1>&2
exit 1
fi
step "Fetching dependencies using 'dep ensure'"
dep ensure
step "Making release"
make release
step "Release artifacts are available in $(pwd)/artifacts"

View File

@ -38,22 +38,40 @@ The following list may be incomplete, feel free to submit a PR with an update:
Compile From Source
~~~~~~~~~~~~~~~~~~~
Check out the sources yourself, fetch dependencies using ``dep``, compile and install to the zrepl user's ``$PATH``.
You may want to switch to a tagged commit (we use `semver <http://semver.org>`_) although a checkout of ``master`` branch should generally work.
**Note**: if the zrepl binary is not in ``$PATH``, the examples in the :ref:`tutorial` may need to be adjusted.
Go 1.9 or newer and a configured ``$GOPATH`` environment variable and a few build dependencies are required to build zrepl.
A tutorial is available over at `golang.org <https://golang.org/doc/install>`_.
If Go 1.9 is not available on your distro consider build in Docker (see below).
The following shell script checks out the zrepl project into your ``$GOPATH``,
installs the build dependencies, installs dependencies using ``dep ensure`` and does a ``make release``.
Build artifacts are placed into ``$GOPATH/github.com/zrepl/zrepl/artifacts/``.
When doing builds afterwards, it should be sufficient to checkout the new revision, run ``dep ensure`` and ``make release``.
You may want to switch to a tagged commit (we use `semver <http://semver.org>`_) but master should generally be considered stable.
**Note**: it is your job to install the apropriate binary in the zrepl users's ``$PATH``, e.g. ``/usr/local/bin/zrepl``.
Otherwise, the examples in the :ref:`tutorial` may need to be adjusted.
**You are encouraged to understand what happens by auditing the script.**
::
curl 'https://raw.githubusercontent.com/zrepl/zrepl/master/clone_and_build.sh' | sh
You can also build in a Docker container if you want an isolated build environment or don't have a compatible Go version.
::
# NOTE: you may want to checkout & build as an unprivileged user
cd /root
git clone https://github.com/zrepl/zrepl.git
cd zrepl
dep ensure
go build -o zrepl
cp zrepl /usr/local/bin/zrepl
rehash
# see if it worked
zrepl help
sudo docker run -it --rm \
-v "${PWD}:/zrepl" \
--user "$(id -u):$(id -g)" \
golang:latest bash -c 'export CLONEPATH=/go/src/github.com/zrepl; mkdir -p "$CLONEPATH" && ln -s /zrepl $CLONEPATH/zrepl && ${CLONEPATH}/zrepl/clone_and_build.sh'
.. literalinclude:: ../clone_and_build.sh
:language: sh
.. _mainconfigfile: