update go generated project files
Signed-off-by: Jess Frazelle <acidburn@microsoft.com>
This commit is contained in:
parent
e346c2e0ba
commit
2446892a69
8 changed files with 167 additions and 72 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -4,8 +4,6 @@
|
||||||
*.o
|
*.o
|
||||||
*.a
|
*.a
|
||||||
*.so
|
*.so
|
||||||
*.swo
|
|
||||||
*.swp
|
|
||||||
|
|
||||||
# Folders
|
# Folders
|
||||||
_obj
|
_obj
|
||||||
|
@ -45,6 +43,12 @@ Icon
|
||||||
.Trashes
|
.Trashes
|
||||||
|
|
||||||
binctr
|
binctr
|
||||||
|
cross/
|
||||||
|
|
||||||
|
# Go coverage results
|
||||||
|
coverage.txt
|
||||||
|
profile.out
|
||||||
|
|
||||||
*.tar
|
*.tar
|
||||||
rootfs
|
rootfs
|
||||||
config.json
|
config.json
|
||||||
|
|
28
.travis.yml
Normal file
28
.travis.yml
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
language: go
|
||||||
|
sudo: false
|
||||||
|
notifications:
|
||||||
|
email: true
|
||||||
|
go:
|
||||||
|
- 1.x
|
||||||
|
- tip
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- GO15VENDOREXPERIMENT=1
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- go: tip
|
||||||
|
fast_finish: true
|
||||||
|
install:
|
||||||
|
- go get github.com/golang/lint/golint
|
||||||
|
- go get honnef.co/go/tools/cmd/staticcheck
|
||||||
|
script:
|
||||||
|
- make IMAGE=alpine
|
||||||
|
- go vet $(go list ./... | grep -v vendor)
|
||||||
|
- staticcheck $(go list ./... | grep -v vendor)
|
||||||
|
- 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 cover
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
3
LICENSE
3
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Jess Frazelle
|
Copyright (c) 2018 The Genuinetools Authors
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
|
168
Makefile
168
Makefile
|
@ -1,82 +1,142 @@
|
||||||
.PHONY: clean clean-rootfs all fmt vet lint build test install image.tar rootfs.go static
|
# Set an output prefix, which is the local directory if not specified
|
||||||
PREFIX?=$(shell pwd)
|
PREFIX?=$(shell pwd)
|
||||||
BUILDTAGS=seccomp apparmor
|
BUILDTAGS=seccomp apparmor
|
||||||
|
|
||||||
PROJECT := github.com/jessfraz/binctr
|
# Setup name variables for the package/tool
|
||||||
VENDOR := vendor
|
NAME := binctr
|
||||||
|
PKG := github.com/genuinetools/$(NAME)
|
||||||
|
|
||||||
# Variable to get the current version.
|
# Set any default go build tags
|
||||||
VERSION := $(shell cat VERSION)
|
BUILDTAGS :=
|
||||||
|
|
||||||
# Variable to set the current git commit.
|
# 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.txt)
|
||||||
GITCOMMIT := $(shell git rev-parse --short HEAD)
|
GITCOMMIT := $(shell git rev-parse --short HEAD)
|
||||||
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
||||||
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
|
GITUNTRACKEDCHANGES := $(shell git status --porcelain --untracked-files=no)
|
||||||
ifneq ($(GITUNTRACKEDCHANGES),)
|
ifneq ($(GITUNTRACKEDCHANGES),)
|
||||||
GITCOMMIT := $(GITCOMMIT)-dirty
|
GITCOMMIT := $(GITCOMMIT)-dirty
|
||||||
endif
|
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"
|
||||||
|
|
||||||
IMAGE := alpine
|
# List the GOOS and GOARCH to build
|
||||||
DOCKER_ROOTFS_IMAGE := $(IMAGE)
|
GOOSARCHES = darwin/amd64 darwin/386 freebsd/amd64 freebsd/386 linux/arm linux/arm64 linux/amd64 linux/386 solaris/amd64 windows/amd64 windows/386
|
||||||
|
|
||||||
LDFLAGS := ${LDFLAGS} \
|
all: clean build fmt lint test staticcheck vet install ## Runs a clean, build, fmt, lint, test, staticcheck, vet and install
|
||||||
-X main.GITCOMMIT=${GITCOMMIT} \
|
|
||||||
-X main.VERSION=${VERSION} \
|
|
||||||
-X main.IMAGE=$(notdir $(IMAGE)) \
|
|
||||||
-X main.IMAGESHA=$(shell docker inspect --format "{{.Id}}" $(IMAGE))
|
|
||||||
|
|
||||||
BINDIR := $(CURDIR)/bin
|
.PHONY: build
|
||||||
|
build: $(NAME) ## Builds a dynamic executable or package
|
||||||
|
|
||||||
all: clean static fmt lint test vet install
|
$(NAME): *.go VERSION.txt
|
||||||
|
|
||||||
build: rootfs.go
|
|
||||||
@echo "+ $@"
|
@echo "+ $@"
|
||||||
go build -tags "$(BUILDTAGS)" -ldflags "${LDFLAGS}" .
|
go build -tags "$(BUILDTAGS)" ${GO_LDFLAGS} -o $(NAME) .
|
||||||
|
|
||||||
$(BINDIR):
|
.PHONY: static
|
||||||
@mkdir -p $@
|
static: ## Builds a static executable
|
||||||
|
|
||||||
static: $(BINDIR) rootfs.go
|
|
||||||
@echo "+ $@"
|
@echo "+ $@"
|
||||||
CGO_ENABLED=1 go build -tags "$(BUILDTAGS) cgo static_build" \
|
CGO_ENABLED=0 go build \
|
||||||
-ldflags "-w -extldflags -static ${LDFLAGS}" -o bin/$(notdir $(IMAGE)) .
|
-tags "$(BUILDTAGS) static_build" \
|
||||||
@echo "Static container created at: ./bin/$(notdir $(IMAGE))"
|
${GO_LDFLAGS_STATIC} -o $(NAME) .
|
||||||
@echo "Run with ./bin/$(notdir $(IMAGE))"
|
|
||||||
|
|
||||||
image.tar:
|
.PHONY: fmt
|
||||||
docker pull --disable-content-trust=false $(DOCKER_ROOTFS_IMAGE)
|
fmt: ## Verifies all files have men `gofmt`ed
|
||||||
docker export $(shell docker create $(DOCKER_ROOTFS_IMAGE) sh) > $@
|
|
||||||
|
|
||||||
rootfs.go: image.tar
|
|
||||||
GOMAXPROCS=1 go generate
|
|
||||||
|
|
||||||
fmt:
|
|
||||||
@echo "+ $@"
|
@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 "+ $@"
|
@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 "+ $@"
|
@echo "+ $@"
|
||||||
@go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v $(VENDOR))
|
@go test -v -tags "$(BUILDTAGS) cgo" $(shell go list ./... | grep -v vendor)
|
||||||
|
|
||||||
vet:
|
.PHONY: vet
|
||||||
|
vet: ## Verifies `go vet` passes
|
||||||
@echo "+ $@"
|
@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-rootfs:
|
.PHONY: staticcheck
|
||||||
@sudo $(RM) -r rootfs
|
staticcheck: ## Verifies `staticcheck` passes
|
||||||
|
|
||||||
clean: clean-rootfs
|
|
||||||
@echo "+ $@"
|
@echo "+ $@"
|
||||||
@$(RM) binctr
|
@staticcheck $(shell go list ./... | grep -v vendor) | grep -v '.pb.go:' | tee /dev/stderr
|
||||||
@$(RM) *.tar
|
|
||||||
@$(RM) rootfs.go
|
|
||||||
@$(RM) -r $(BINDIR)
|
|
||||||
-@docker rm $(shell docker ps -aq) /dev/null 2>&1
|
|
||||||
|
|
||||||
install:
|
.PHONY: cover
|
||||||
|
cover: ## Runs go test with coverage
|
||||||
|
@echo "" > coverage.txt
|
||||||
|
@for d in $(shell go list ./... | grep -v vendor); do \
|
||||||
|
go test -race -coverprofile=profile.out -covermode=atomic "$$d"; \
|
||||||
|
if [ -f profile.out ]; then \
|
||||||
|
cat profile.out >> coverage.txt; \
|
||||||
|
rm profile.out; \
|
||||||
|
fi; \
|
||||||
|
done;
|
||||||
|
|
||||||
|
.PHONY: install
|
||||||
|
install: ## Installs the executable or package
|
||||||
@echo "+ $@"
|
@echo "+ $@"
|
||||||
@go install .
|
go install -a -tags "$(BUILDTAGS)" ${GO_LDFLAGS} .
|
||||||
|
|
||||||
|
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} .;
|
||||||
|
md5sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).md5;
|
||||||
|
sha256sum $(BUILDDIR)/$(1)/$(2)/$(NAME) > $(BUILDDIR)/$(1)/$(2)/$(NAME).sha256;
|
||||||
|
endef
|
||||||
|
|
||||||
|
.PHONY: cross
|
||||||
|
cross: *.go VERSION.txt ## Builds the cross-compiled binaries, creating a clean directory structure (eg. GOOS/GOARCH/binary)
|
||||||
|
@echo "+ $@"
|
||||||
|
$(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} .;
|
||||||
|
md5sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).md5;
|
||||||
|
sha256sum $(BUILDDIR)/$(NAME)-$(1)-$(2) > $(BUILDDIR)/$(NAME)-$(1)-$(2).sha256;
|
||||||
|
endef
|
||||||
|
|
||||||
|
.PHONY: release
|
||||||
|
release: *.go VERSION.txt ## 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: bump-version
|
||||||
|
BUMP := patch
|
||||||
|
bump-version: ## Bump the version in the version file. Set BUMP to [ patch | major | minor ]
|
||||||
|
@go get -u github.com/jessfraz/junk/sembump # update sembump tool
|
||||||
|
$(eval NEW_VERSION = $(shell sembump --kind $(BUMP) $(VERSION)))
|
||||||
|
@echo "Bumping VERSION.txt from $(VERSION) to $(NEW_VERSION)"
|
||||||
|
echo $(NEW_VERSION) > VERSION.txt
|
||||||
|
@echo "Updating links to download binaries in README.md"
|
||||||
|
sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md
|
||||||
|
git add VERSION.txt README.md
|
||||||
|
git commit -vsam "Bump version to $(NEW_VERSION)"
|
||||||
|
@echo "Run make tag to create and push the tag for new version $(NEW_VERSION)"
|
||||||
|
|
||||||
|
.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}'
|
||||||
|
|
21
main.go
21
main.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
aaprofile "github.com/docker/docker/profiles/apparmor"
|
aaprofile "github.com/docker/docker/profiles/apparmor"
|
||||||
|
"github.com/genuinetools/binctr/version"
|
||||||
"github.com/opencontainers/runc/libcontainer"
|
"github.com/opencontainers/runc/libcontainer"
|
||||||
"github.com/opencontainers/runc/libcontainer/apparmor"
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
||||||
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
_ "github.com/opencontainers/runc/libcontainer/nsenter"
|
||||||
|
@ -31,7 +32,7 @@ const (
|
||||||
|
|
||||||
Embedded Image: %s - %s
|
Embedded Image: %s - %s
|
||||||
Version: %s
|
Version: %s
|
||||||
GitCommit: %s
|
Build: %s
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
|
@ -54,13 +55,7 @@ var (
|
||||||
hookflags stringSlice
|
hookflags stringSlice
|
||||||
|
|
||||||
debug bool
|
debug bool
|
||||||
version bool
|
vrsn bool
|
||||||
|
|
||||||
// GITCOMMIT is git commit the binary was compiled against.
|
|
||||||
GITCOMMIT = ""
|
|
||||||
|
|
||||||
// VERSION is the binary version.
|
|
||||||
VERSION = "v0.1.0"
|
|
||||||
|
|
||||||
// IMAGE is the name of the image that is embedded at compile time.
|
// IMAGE is the name of the image that is embedded at compile time.
|
||||||
IMAGE = "alpine"
|
IMAGE = "alpine"
|
||||||
|
@ -123,19 +118,19 @@ func init() {
|
||||||
flag.BoolVar(&detach, "d", false, "detach from the container's process")
|
flag.BoolVar(&detach, "d", false, "detach from the container's process")
|
||||||
flag.BoolVar(&readonly, "read-only", false, "make container filesystem readonly")
|
flag.BoolVar(&readonly, "read-only", false, "make container filesystem readonly")
|
||||||
|
|
||||||
flag.BoolVar(&version, "version", false, "print version and exit")
|
flag.BoolVar(&vrsn, "version", false, "print version and exit")
|
||||||
flag.BoolVar(&version, "v", false, "print version and exit (shorthand)")
|
flag.BoolVar(&vrsn, "v", false, "print version and exit (shorthand)")
|
||||||
flag.BoolVar(&debug, "D", false, "run in debug mode")
|
flag.BoolVar(&debug, "D", false, "run in debug mode")
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, IMAGE, IMAGESHA, VERSION, GITCOMMIT))
|
fmt.Fprint(os.Stderr, fmt.Sprintf(BANNER, IMAGE, IMAGESHA, version.VERSION, version.GITCOMMIT))
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if version {
|
if vrsn {
|
||||||
fmt.Printf("%s, commit: %s, image: %s, image digest: %s", VERSION, GITCOMMIT, IMAGE, IMAGESHA)
|
fmt.Printf("%s, commit: %s, image: %s, image digest: %s", version.VERSION, version.GITCOMMIT, IMAGE, IMAGESHA)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const DATA = ""
|
||||||
|
|
||||||
func unpackRootfs(spec *specs.Spec) error {
|
func unpackRootfs(spec *specs.Spec) error {
|
||||||
data, err := base64.StdEncoding.DecodeString(DATA)
|
data, err := base64.StdEncoding.DecodeString(DATA)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
7
version/version.go
Normal file
7
version/version.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package version
|
||||||
|
|
||||||
|
// VERSION indicates which version of the binary is running.
|
||||||
|
var VERSION string
|
||||||
|
|
||||||
|
// GITCOMMIT indicates which git hash the binary was built off of
|
||||||
|
var GITCOMMIT string
|
Loading…
Reference in a new issue