Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Jess Frazelle <acidburn@google.com>
  • Loading branch information
jessfraz committed Aug 4, 2017
0 parents commit 852ff98
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .travis.yml
@@ -0,0 +1,43 @@
---
language: go
sudo: false
notifications:
email: true
go:
- 1.6.x
- 1.7.x
- 1.8.x
- tip
env:
global:
- GO15VENDOREXPERIMENT=1
install:
- go get github.com/golang/lint/golint
script:
- go build -v
- go vet $(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 release
deploy:
provider: releases
api_key:
secure: "LMrByDP/cIjxaGdXAOrDGtlzsiBt//LRrhrwpdimdl6rnijkc+NlhRhGNItceJzQLs6kz5sihHY1YVaeqzJXnJ+Eo4b0Kz1BQwpOk5DRn85y+tTg2G7HvCIjrWsVleCnbmAK/IbOsVdY7HlK7s0i9eG+7fYfSGiNMevwwtfQjiKH3yFu+nUPPH4Z85Lvz8Wvjg0Nmhnt+nY4R7IFHgMNVGsUn1qjUrrCK8X9fuY3ulnK6nghQ/KSrxyJdkfWWOqs8EfxMpcKH6iL5wYeAXxEFp97WJiqjqIh2RfGjB4q/nRWVWDviVUxUxrgIFh4AEtZMphdKsNhoyyLMZB42O1daP7SCR498xeCZLpx4jTfOTJ6QhD2zJ56rkXlvcEDomCIo+A3fHUiknKLmEnRE6aQQTkn3E49D7A+GG15x/3ec6WBizR1Ht8nMxDh7Z5glVqs8Sf/AHry3RLEYbO6HS2j3Axx6yS9dg5K8keOpKygVpyNNFUb1KDpO/ZJdq4GaBqyjHZoh/PBNvYxHsMhVL9L57LBabckV5pTjGunTTY6CHmhPdzWCVCl1SRRUw1spqZMxydQSkxYd04QqAVsb3vw4f+iA0uTSgWRKpcC0CVjiML1BIxnjXDmBP7v6+oVaEHF9Gyj9+StvodS7GUWScL8p1NvQlHaC4bdzKytMTMuzmc="
go: 1.8.x
file:
- cross/amicontained-linux-amd64.md5
- cross/amicontained-linux-arm
- cross/amicontained-linux-arm64.sha256
- cross/amicontained-linux-arm.sha256
- cross/amicontained-linux-386.sha256
- cross/amicontained-linux-arm64.md5
- cross/amicontained-linux-arm64
- cross/amicontained-linux-amd64.sha256
- cross/amicontained-linux-386.md5
- cross/amicontained-linux-arm.md5
- cross/amicontained-linux-386
- cross/amicontained-linux-amd64
skip_cleanup: true
on:
tags: true
125 changes: 125 additions & 0 deletions Makefile
@@ -0,0 +1,125 @@
# Set an output prefix, which is the local directory if not specified
PREFIX?=$(shell pwd)

# Setup name variables for the package/tool
NAME := amicontained
PKG := github.com/jessfraz/$(NAME)

# Set any default go build tags
BUILDTAGS :=

# 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 = linux/arm linux/arm64 linux/amd64 linux/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)" ${GO_LDFLAGS} -o $(NAME) .

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

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

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

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

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

.PHONY: install
install: ## Installs the executable or package
@echo "+ $@"
@go 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} .;
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 ## 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 ## 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 KIND 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 from $(VERSION) to $(NEW_VERSION)"
echo $(NEW_VERSION) > VERSION
@echo "Updating links to download binaries in README.md"
sed -i s/$(VERSION)/$(NEW_VERSION)/g README.md
git add VERSION 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}'
24 changes: 24 additions & 0 deletions README.md
@@ -0,0 +1,24 @@
# amicontained

[![Travis CI](https://travis-ci.org/jessfraz/amicontained.svg?branch=master)](https://travis-ci.org/jessfraz/amicontained)

Container introspection tool. Find out what container runtime is being used as
well as features available.

## Installation

#### Binaries

- **linux** [386](https://github.com/jessfraz/amicontained/releases/download/v0.0.0/amicontained-linux-386) / [amd64](https://github.com/jessfraz/amicontained/releases/download/v0.0.0/amicontained-linux-amd64) / [arm](https://github.com/jessfraz/amicontained/releases/download/v0.0.0/amicontained-linux-arm) / [arm64](https://github.com/jessfraz/amicontained/releases/download/v0.0.0/amicontained-linux-arm64)

#### Via Go

```bash
$ go get github.com/jessfraz/amicontained
```

## Usage

```console
$ amicontained -h
```
1 change: 1 addition & 0 deletions VERSION
@@ -0,0 +1 @@
v0.0.0
81 changes: 81 additions & 0 deletions main.go
@@ -0,0 +1,81 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/Sirupsen/logrus"
"github.com/jessfraz/amicontained/version"
)

const (
// BANNER is what is printed for help/info output
BANNER = ` _ _ _ _
__ _ _ __ ___ (_) ___ ___ _ __ | |_ __ _(_)_ __ ___ __| |
/ _` + "`" + ` | '_ ` + "`" + ` _ \| |/ __/ _ \| '_ \| __/ _` + "`" + ` | | '_ \ / _ \/ _` + "`" + ` |
| (_| | | | | | | | (_| (_) | | | | || (_| | | | | | __/ (_| |
\__,_|_| |_| |_|_|\___\___/|_| |_|\__\__,_|_|_| |_|\___|\__,_|
Container introspection tool.
Version: %s
`
)

var (
debug bool
vrsn bool
)

func init() {
// parse flags
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.VERSION))
flag.PrintDefaults()
}

flag.Parse()

// set log level
if debug {
logrus.SetLevel(logrus.DebugLevel)
}

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

if flag.NArg() < 1 {
return
}

// parse the arg
arg := flag.Args()[0]

if arg == "help" {
usageAndExit("", 0)
}

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

func main() {
}

func usageAndExit(message string, exitCode int) {
if message != "" {
fmt.Fprintf(os.Stderr, message)
fmt.Fprintf(os.Stderr, "\n\n")
}
flag.Usage()
fmt.Fprintf(os.Stderr, "\n")
os.Exit(exitCode)
}
7 changes: 7 additions & 0 deletions version/version.go
@@ -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

0 comments on commit 852ff98

Please sign in to comment.