*: Switch to a Makefile driven develop/release process

* Add make targets for vendor, docker-image, and tools
* Move scripts into the scripts folder
This commit is contained in:
Dalton Hubble
2017-01-17 01:46:16 -08:00
parent b9d73c58ee
commit 219da4d934
13 changed files with 118 additions and 118 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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.

114
Makefile
View File

@@ -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

7
build
View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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
done

21
scripts/get-protoc Executable file
View File

@@ -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

View File

View File

@@ -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