Skip to content

Commit

Permalink
add everything to push releases through travis
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <acidburn@google.com>
  • Loading branch information
jessfraz committed Oct 29, 2016
1 parent a94727c commit 21adbbf
Show file tree
Hide file tree
Showing 241 changed files with 112,747 additions and 3,983 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -45,3 +45,4 @@ Icon
.Trashes

bane
cross
21 changes: 21 additions & 0 deletions .travis.yml
Expand Up @@ -18,3 +18,24 @@
- test -z "$(golint ./... | grep -v vendor | tee /dev/stderr)"
- test -z "$(gofmt -s -l . | grep -v vendor | tee /dev/stderr)"
- go test $(go list ./... | grep -v vendor)
- make release
deploy:
provider: releases
api_key:
secure: "E9Vf+YGU17qKZgIAzBNq22cawUKK/IXamBaB2JmEoeVfS1I6oN+7ibUrjiBeGAbFean/MsUUjhuzkElsbxh9k9VHtiM09CvctgxjCGveY7hMvXo6JOGW8JzjVHO15hwAE0a6XSYlmrz/AQ9A6hne6u4o+4h+YuE6QksWiEq7GNlP5BA0VYDAAfPEvZWhU7dUxp8hp7RAmtIUEuNa9SUCx0WRZPMjeUpPifN5zGTCBxJqrCXIDvsO4JhaqrUx6xONC5ZJiuDXIFXrBf1nCQ1J7S4hbV3TdohL4rUo4gbb+IvO54Wmubkm3VBB0O5ZAEFpjDlkbcMXBQrDkhmPLajM/MJ5ifu34T+RRb42tcplVi9Xe+HQ856BnvDVSz3uhFAe/5IPF5/jaUu75K0MZ0Cnaxhwhduxfny0wwbuTrSeEm4Xc79m6pTqovJLvxsao81dtTOIBzElJypIj4mbdPyE1woTTRB47h8a1e25HCxl93Cc1wfr3hiMy8fzSpzP/hxAQxI1WGeWBCHuaGFGDEFOpbbLqXJpdEme4GRKnxIMO5UGeVDzeLisaSZGC1wRrSvWTFFPcNQ29tmTr3DgDrpR6PTMlb2c+dI/9QXP1xldn1psQRhO/ixXOqwyhbJhBB6xmZfqpZhsFgjhMHpOC8ba3ulZDraVsNJAX+XIGNbqNZU="
go: 1.7
file:
- cross/bane-darwin-386
- cross/bane-freebsd-386
- cross/bane-linux-386
- cross/bane-windows-386
- cross/bane-darwin-amd64
- cross/bane-freebsd-amd64
- cross/bane-linux-amd64
- cross/bane-linux-arm
- cross/bane-linux-arm64
- cross/bane-solaris-amd64
- cross/bane-windows-amd64
skip_cleanup: true
on:
tags: true
106 changes: 87 additions & 19 deletions Makefile
@@ -1,40 +1,108 @@
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)
BUILDTAGS=

.PHONY: clean all fmt vet lint build test install static
.DEFAULT: default
# Setup name variables for the package/tool
NAME := bane
PKG := github.com/jessfraz/$(NAME)

all: clean build fmt lint test vet install
# Set any default go build tags
BUILDTAGS :=

build:
# Set the build dir, where built cross-compiled binaries will be output
BUILDDIR := ${PREFIX}/cross

# Populate version variables
# Add to compile time flags
VERSION := $(shell cat VERSION)
GITCOMMIT := $(shell git rev-parse --short HEAD)
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
ifneq ($(GITUNTRACKEDCHANGES),)
GITCOMMIT := $(GITCOMMIT)-dirty
endif
CTIMEVAR=-X $(PKG)/version.GITCOMMIT=$(GITCOMMIT) -X $(PKG)/version.VERSION=$(VERSION)
GO_LDFLAGS=-ldflags "-w $(CTIMEVAR)"
GO_LDFLAGS_STATIC=-ldflags "-w $(CTIMEVAR) -extldflags -static"

# List the GOOS and GOARCH to build
GOOSARCHES = darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 linux/arm linux/arm64 linux/amd64 linux/386 solaris/amd64 windows/amd64 windows/386

all: clean build fmt lint test vet install ## Runs a clean, build, fmt, lint, test, vet and install

.PHONY: build
build: $(NAME) ## Builds a dynamic executable or package

$(NAME): *.go VERSION
@echo "+ $@"
@go build -tags "$(BUILDTAGS) cgo" .
go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) .

static:
.PHONY: static
static: # Builds a static executable
@echo "+ $@"
CGO_ENABLED=1 go build -tags "$(BUILDTAGS) cgo static_build" -ldflags "-w -extldflags -static" -o bane .
CGO_ENABLED=0 go build \
-tags "$(BUILDTAGS) static_build" \
${GO_LDFLAGS_STATIC} -o $(NAME) .

fmt:
.PHONY: fmt
fmt: ## Verifies all files have men `gofmt`ed
@echo "+ $@"
@gofmt -s -l . | grep -v vendor | tee /dev/stderr
@gofmt -s -l . | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr

lint:
.PHONY: lint
lint: ## Verifies `golint` passes
@echo "+ $@"
@golint ./... | grep -v vendor | tee /dev/stderr
@golint ./... | grep -v '.pb.go:' | grep -v vendor | tee /dev/stderr

test: fmt lint vet
.PHONY: test
test: ## Runs the go tests
@echo "+ $@"
@go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor)

vet:
.PHONY: vet
vet: ## Verifies `go vet` passes
@echo "+ $@"
@go vet $(shell go list ./... | grep -v vendor)
@go vet $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr

clean:
.PHONY: install
install: ## Installs the executable or package
@echo "+ $@"
@rm -rf bane
@go install .

install:
define buildpretty
mkdir -p $(BUILDDIR)/$(1)/$(2);
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(1)/$(2)/$(NAME) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo ${GO_LDFLAGS_STATIC} .;
endef

.PHONY: cross
cross: *.go VERSION ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary)
@echo "+ $@"
@go install .
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildpretty,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))

define buildrelease
GOOS=$(1) GOARCH=$(2) CGO_ENABLED=0 go build \
-o $(BUILDDIR)/$(NAME)-$(1)-$(2) \
-a -tags "$(BUILDTAGS) static_build netgo" \
-installsuffix netgo ${GO_LDFLAGS_STATIC} .;
endef

.PHONY: release
release: *.go VERSION ## Builds the cross-compiled binaries, naming them in such a way for release (eg. binary-GOOS-GOARCH)
@echo "+ $@"
$(foreach GOOSARCH,$(GOOSARCHES), $(call buildrelease,$(subst /,,$(dir $(GOOSARCH))),$(notdir $(GOOSARCH))))

.PHONY: tag
tag: ## Create a new git tag to prepare to build a release
git tag -sa $(VERSION) -m "$(VERSION)"
@echo "Run git push origin $(VERSION) to push your new tag to GitHub and trigger a travis build."

.PHONY: clean
clean: ## Cleanup any build binaries or packages
@echo "+ $@"
$(RM) $(NAME)
$(RM) -r $(BUILDDIR)

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
22 changes: 13 additions & 9 deletions main.go
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/Sirupsen/logrus"
"github.com/jessfraz/bane/apparmor"
"github.com/jessfraz/bane/version"
)

const (
Expand All @@ -23,32 +24,35 @@ const (
Version: %s
`
// VERSION is the binary version.
VERSION = "v0.1.0"
)

var (
apparmorProfileDir string

debug bool
version bool
debug bool
vrsn bool
)

func init() {
// parse flags
flag.StringVar(&apparmorProfileDir, "profile-dir", "/etc/apparmor.d/containers", "directory for saving the profiles")

flag.BoolVar(&version, "version", false, "print version and exit")
flag.BoolVar(&version, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&vrsn, "version", false, "print version and exit")
flag.BoolVar(&vrsn, "v", false, "print version and exit (shorthand)")
flag.BoolVar(&debug, "d", false, "run in debug mode")

flag.Usage = func() {
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, VERSION))
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, version.VERSION))
flag.PrintDefaults()
}

flag.Parse()

if vrsn {
fmt.Printf("bane version %s, build %s", version.VERSION, version.GITCOMMIT)
os.Exit(0)
}

if flag.NArg() < 1 {
usageAndExit("Pass the path to the config file.", 1)
}
Expand All @@ -60,8 +64,8 @@ func init() {
usageAndExit("", 0)
}

if version || arg == "version" {
fmt.Printf("%s", VERSION)
if arg == "version" {
fmt.Printf("bane version %s, build %s", version.VERSION, version.GITCOMMIT)
os.Exit(0)
}

Expand Down
3 changes: 0 additions & 3 deletions vendor/github.com/BurntSushi/toml/COMPATIBLE

This file was deleted.

19 changes: 0 additions & 19 deletions vendor/github.com/BurntSushi/toml/Makefile

This file was deleted.

0 comments on commit 21adbbf

Please sign in to comment.