diff --git a/Makefile b/Makefile index 3558ac7..a7bf681 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/clone_and_build.sh b/clone_and_build.sh new file mode 100755 index 0000000..779d9f6 --- /dev/null +++ b/clone_and_build.sh @@ -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" diff --git a/docs/installation.rst b/docs/installation.rst index 42176d9..c612feb 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -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 `_) 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 `_. +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 `_) 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: