diff --git a/.travis.yml b/.travis.yml index edd9eefb..d4ac0340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,7 @@ matrix: install: - go get github.com/golang/lint/golint script: - - ./test + - make test deploy: provider: script script: scripts/travis-docker-push diff --git a/Documentation/dev/develop.md b/Documentation/dev/develop.md index 64687d4e..a2371846 100644 --- a/Documentation/dev/develop.md +++ b/Documentation/dev/develop.md @@ -1,42 +1,26 @@ - # Development -To develop `matchbox` locally, compile the binary and build the container image. The following tasks can also be performed using the `Makefile` if you prefer. +To develop `matchbox` locally, compile the binary and build the container image. ## Static Binary Build the static binary. - ./build + make build Test with vendored dependencies. - ./test - -## Vendor - -Use `glide` to manage dependencies committed to the `vendor` directory. - - glide update --strip-vendor --skip-test - -## Codegen - -Generate code from *proto* definitions using `protoc` and the `protoc-gen-go` plugin. - - # install tools - ./scripts/gentools - # generate code from proto definitions in subpackages - ./scripts/codegen + make test ## Container Image Build an ACI `matchbox.aci`. - ./build-aci + make aci Alternately, build a Docker image `coreos/matchbox:latest`. - sudo ./build-docker + make docker-image ## Version @@ -58,8 +42,21 @@ Alternately, run the Docker image on `docker0`. sudo docker run -p 8080:8080 --rm -v $PWD/examples:/var/lib/matchbox:Z -v $PWD/examples/groups/etcd:/var/lib/matchbox/groups:Z coreos/matchbox:latest -address=0.0.0.0:8080 -log-level=debug -### bootcmd +## bootcmd Run `bootcmd` against the gRPC API of the service running via rkt. ./bin/bootcmd profile list --endpoints 172.18.0.2:8081 --cacert examples/etc/matchbox/ca.crt + +## Vendor + +Use `glide` and `glide-vc` to manage dependencies committed to the `vendor` directory. + + make vendor + +## Codegen + +Generate code from *proto* definitions using `protoc` and the `protoc-gen-go` plugin. + + make codegen + diff --git a/Documentation/dev/release.md b/Documentation/dev/release.md index a815d049..75d53c20 100644 --- a/Documentation/dev/release.md +++ b/Documentation/dev/release.md @@ -32,7 +32,6 @@ Publish the release on Github with release notes. Build the release tarballs. - make build make release Verify the reported version. @@ -43,7 +42,7 @@ Verify the reported version. Build the rkt ACI on a Linux host with `acbuild`, - ./build-aci + make aci Check that the listed version is correct/clean. diff --git a/Makefile b/Makefile index d765aed3..59255ade 100644 --- a/Makefile +++ b/Makefile @@ -1,64 +1,85 @@ - export CGO_ENABLED:=0 -LD_FLAGS="-w -X github.com/coreos/matchbox/matchbox/version.Version=$(shell ./git-version)" -LOCAL_BIN=/usr/local/bin + +VERSION=$(shell ./scripts/git-version) +LD_FLAGS="-w -X github.com/coreos/matchbox/matchbox/version.Version=$(VERSION)" + +REPO=github.com/coreos/matchbox +IMAGE_REPO=coreos/matchbox +QUAY_REPO=quay.io/coreos/matchbox all: build + build: clean bin/matchbox bin/bootcmd -tools: - ./scripts/gentools - -codegen: tools - ./scripts/codegen - -bin/matchbox: - go build -o bin/matchbox -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/matchbox - -bin/bootcmd: - go build -o bin/bootcmd -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/bootcmd +bin/%: + @go build -o bin/$* -v -ldflags $(LD_FLAGS) $(REPO)/cmd/$* test: - ./test + @./scripts/test -install: - cp bin/matchbox $(LOCAL_BIN) - cp bin/bootcmd $(LOCAL_BIN) +.PHONY: aci +aci: clean build + @sudo ./scripts/build-aci + +.PHONY: docker-image +docker-image: + @sudo docker build --rm=true -t $(IMAGE_REPO):$(VERSION) . + @sudo docker tag $(IMAGE_REPO):$(VERSION) $(IMAGE_REPO):latest + +.PHONY: docker-push +docker-push: docker-image + @sudo docker tag $(IMAGE_REPO):$(VERSION) $(QUAY_REPO):latest + @sudo docker tag $(IMAGE_REPO):$(VERSION) $(QUAY_REPO):$(VERSION) + @sudo docker push $(QUAY_REPO):latest + @sudo docker push $(QUAY_REPO):$(VERSION) + +.PHONY: vendor +vendor: + @glide update --strip-vendor + @glide-vc --use-lock-file --no-tests --only-code + +.PHONY: codegen +codegen: tools + @./scripts/codegen + +.PHONY: tools +tools: bin/protoc bin/protoc-gen-go + +bin/protoc: + @./scripts/get-protoc + +bin/protoc-gen-go: + @go build -o bin/protoc-gen-go $(REPO)/vendor/github.com/golang/protobuf/protoc-gen-go + +clean: + @rm -rf bin + +clean-release: + @rm -rf _output release: \ clean \ + clean-release \ _output/matchbox-linux-amd64.tar.gz \ _output/matchbox-linux-arm.tar.gz \ _output/matchbox-linux-arm64.tar.gz \ - _output/matchbox-darwin-amd64.tar.gz \ + _output/matchbox-darwin-amd64.tar.gz -# matchbox +bin/linux-amd64/matchbox: GOARGS = GOOS=linux GOARCH=amd64 +bin/linux-arm/matchbox: GOARGS = GOOS=linux GOARCH=arm +bin/linux-arm64/matchbox: GOARGS = GOOS=linux GOARCH=arm64 +bin/darwin-amd64/matchbox: GOARGS = GOOS=darwin GOARCH=amd64 -bin/linux-amd64/matchbox: - GOOS=linux GOARCH=amd64 go build -o bin/linux-amd64/matchbox -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/matchbox +bin/%/matchbox: + $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/matchbox -bin/linux-arm/matchbox: - GOOS=linux GOARCH=arm go build -o bin/linux-arm/matchbox -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/matchbox +bin/linux-amd64/bootcmd: GOARGS = GOOS=linux GOARCH=amd64 +bin/linux-arm/bootcmd: GOARGS = GOOS=linux GOARCH=arm +bin/linux-arm64/bootcmd: GOARGS = GOOS=linux GOARCH=arm64 +bin/darwin-amd64/bootcmd: GOARGS = GOOS=darwin GOARCH=amd64 -bin/linux-arm64/matchbox: - GOOS=linux GOARCH=arm64 go build -o bin/linux-arm64/matchbox -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/matchbox - -bin/darwin-amd64/matchbox: - GOOS=darwin GOARCH=amd64 go build -o bin/darwin-amd64/matchbox -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/matchbox - -# bootcmd - -bin/linux-amd64/bootcmd: - GOOS=linux GOARCH=amd64 go build -o bin/linux-amd64/bootcmd -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/bootcmd - -bin/linux-arm/bootcmd: - GOOS=linux GOARCH=arm go build -o bin/linux-arm/bootcmd -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/bootcmd - -bin/linux-arm64/bootcmd: - GOOS=linux GOARCH=arm64 go build -o bin/linux-arm64/bootcmd -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/bootcmd - -bin/darwin-amd64/bootcmd: - GOOS=darwin GOARCH=amd64 go build -o bin/darwin-amd64/bootcmd -ldflags $(LD_FLAGS) -a github.com/coreos/matchbox/cmd/bootcmd +bin/%/bootcmd: + $(GOARGS) go build -o $@ -ldflags $(LD_FLAGS) -a $(REPO)/cmd/bootcmd _output/matchbox-%.tar.gz: NAME=matchbox-$(VERSION)-$* _output/matchbox-%.tar.gz: DEST=_output/$(NAME) @@ -69,11 +90,6 @@ _output/matchbox-%.tar.gz: bin/%/matchbox bin/%/bootcmd ./scripts/release-files $(DEST) tar zcvf $(DEST).tar.gz -C _output $(NAME) -clean: - rm -rf tools - rm -rf bin - rm -rf _output - -.PHONY: all build tools test install release clean +.PHONY: all build clean test release .SECONDARY: _output/matchbox-linux-amd64 _output/matchbox-darwin-amd64 diff --git a/build b/build deleted file mode 100755 index 633c65d8..00000000 --- a/build +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - -LD_FLAGS="-w -X github.com/coreos/matchbox/matchbox/version.Version=$(./git-version)" -CGO_ENABLED=0 go build -o bin/matchbox -ldflags "$LD_FLAGS" -a github.com/coreos/matchbox/cmd/matchbox - -# bootcmd CLI binary -CGO_ENABLED=0 go build -o bin/bootcmd -ldflags "$LD_FLAGS" -a github.com/coreos/matchbox/cmd/bootcmd diff --git a/build-docker b/build-docker deleted file mode 100755 index 037b396f..00000000 --- a/build-docker +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -e - -REPO=coreos/matchbox -GIT_SHA=$(./git-version) - -docker build --rm=true -t $REPO:$GIT_SHA . -docker tag $REPO:$GIT_SHA $REPO:latest diff --git a/push-docker b/push-docker deleted file mode 100755 index 68c909ae..00000000 --- a/push-docker +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -e - -REPO=coreos/matchbox -QUAY_REPO=quay.io/coreos/matchbox -GIT_SHA=$(./git-version) - -# quay.io -docker tag $REPO:$GIT_SHA $QUAY_REPO:latest -docker tag $REPO:$GIT_SHA $QUAY_REPO:$GIT_SHA -docker push $QUAY_REPO:latest -docker push $QUAY_REPO:$GIT_SHA diff --git a/build-aci b/scripts/build-aci similarity index 95% rename from build-aci rename to scripts/build-aci index 1af9187a..8d950a55 100755 --- a/build-aci +++ b/scripts/build-aci @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -GIT_SHA=$(./git-version) +GIT_SHA=$(./scripts/git-version) # Start with an empty ACI acbuild --debug begin diff --git a/scripts/codegen b/scripts/codegen index 51b9d98e..159811e5 100755 --- a/scripts/codegen +++ b/scripts/codegen @@ -1,21 +1,11 @@ #!/usr/bin/env bash +# USAGE ./scripts/codegen # Generate Go protocol buffer code from proto definitions set -eu -# Add tools to the PATH so binaries are the correct version -export PATH=$PWD/tools:$PATH - -# Check location and tools -if ! [[ "$0" =~ "scripts/codegen" ]]; then - echo "must be run from repository root" - exit 255 -fi - -if ! [[ $(protoc --version) =~ "3.0.0" ]]; then - echo "could not find protoc 3.0.0" - exit 255 -fi +# Add protoc and protoc-gen-go tools to PATH +export PATH=$PWD/bin:$PATH # protobuf subpackages end in "pb" PBUFS=$(go list ./... | grep -v /vendor | grep 'pb$') @@ -28,4 +18,5 @@ for pkg in $PBUFS ; do # generate protocol buffers, make other .proto files available to import protoc --go_out=plugins=grpc:. -I=.:"${GOPATH}/src/" *.proto popd > /dev/null -done \ No newline at end of file +done + diff --git a/scripts/get-protoc b/scripts/get-protoc new file mode 100755 index 00000000..4aadd3a3 --- /dev/null +++ b/scripts/get-protoc @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# USAGE: ./get-protoc bin/protoc +# Get the 'protoc' protocol buffer compiler +set -eu + +DEST=${1:-"bin/protoc"} +VERSION="3.1.0" + +OS=$(uname | tr A-Z a-z) +if [[ $OS == 'darwin' ]]; then + OS=osx # protoc names downloads with OSX, not darwin +fi + +FILE="protoc-${VERSION}-${OS}-x86_64.zip" +URL="https://github.com/google/protobuf/releases/download/v${VERSION}/${FILE}" + +curl -L -# -o protoc.zip ${URL} +unzip -p protoc.zip bin/protoc > ${DEST} +chmod +x ${DEST} +rm -f protoc.zip + diff --git a/git-version b/scripts/git-version similarity index 100% rename from git-version rename to scripts/git-version diff --git a/test b/scripts/test similarity index 100% rename from test rename to scripts/test diff --git a/scripts/travis-docker-push b/scripts/travis-docker-push index 4f513056..05cd7968 100755 --- a/scripts/travis-docker-push +++ b/scripts/travis-docker-push @@ -1,8 +1,9 @@ #!/bin/bash -e # Travis Deploy Docker Push -GOOS=linux ./build docker info -./build-docker -docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p=$DOCKER_PASSWORD quay.io -./push-docker +GOOS=linux make build +make docker-image +docker login -u="$DOCKER_USERNAME" -p=$DOCKER_PASSWORD quay.io +make docker-push +