Skip to content

Commit

Permalink
Goreleaser (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryane authored Jun 26, 2019
1 parent 6ec39a4 commit 109c8bb
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 55 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/kfilt
kfilt
dist
43 changes: 43 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
project_name: kfilt
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
goos:
- windows
- linux
- darwin
# Default is `-s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}} -X main.builtBy=goreleaser`.
ldflags:
- -s -w -X github.com/ryane/kfilt/cmd.Version={{.Version}} -X github.com/ryane/kfilt/cmd.GitCommit={{.ShortCommit}}
archives:
- format: binary
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "master"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
- Merge pull request
- Merge branch
dockers:
- goos: linux
goarch: amd64
goarm: ''
binaries:
- kfilt
image_templates:
- "ryane/{{.ProjectName}}:latest"
- "ryane/{{.ProjectName}}:{{ .Tag }}"
skip_push: false
dockerfile: Dockerfile
build_flag_templates:
- "--label=org.label-schema.schema-version=1.0"
- "--label=org.label-schema.version={{.Version}}"
- "--label=org.label-schema.name={{.ProjectName}}"
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: go

go:
- 1.12.x

env:
global:
- GO111MODULE=on

install: true

services:
- docker

after_success:
- test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"

deploy:
- provider: script
skip_cleanup: true
script: curl -sL https://git.io/goreleaser | bash
on:
tags: true
condition: $TRAVIS_OS_NAME = linux
20 changes: 3 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
FROM golang:1.12-alpine3.9 as builder

RUN apk --no-cache add make git gcc musl-dev && rm -rf /var/cache/apk/*
WORKDIR /go/src/github.com/ryane/kfilt
RUN GO111MODULE=off go get github.com/ahmetb/govvv
ENV GO111MODULE=on
COPY go.mod .
COPY go.sum .
RUN go mod download

COPY . .
RUN govvv install -pkg github.com/ryane/kfilt/cmd

FROM alpine:3.9
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
COPY --from=builder /go/bin/kfilt /bin/kfilt
ENTRYPOINT ["/bin/kfilt"]
FROM scratch
COPY kfilt /
ENTRYPOINT ["/kfilt"]
24 changes: 13 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
VERSION ?= $(shell cat VERSION)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "-dirty")
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "-dirty")
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)

.PHONY: all
all: build
all: test build

.PHONY: build
build: deps
govvv build -pkg github.com/ryane/kfilt/cmd
build:
go build

.PHONY: test
test:
go test -v ./...

.PHONY: docker
docker:
docker build -t ryane/kfilt:${VERSION}${GIT_DIRTY} .
CGO_ENABLED=0 GOOS=linux go build -a -tags netgo -ldflags "-w -X github.com/ryane/kfilt/cmd.Version=${GIT_BRANCH} -X github.com/ryane/kfilt/cmd.GitCommit=${GIT_SHA}${GIT_DIRTY}" .
docker build -t ryane/kfilt:${GIT_SHA}${GIT_DIRTY} .

push: build
docker push ryane/kfilt:${VERSION}${GIT_DIRTY}

.PHONY: deps
deps:
GO111MODULE=off go get github.com/ahmetb/govvv
docker push ryane/kfilt:${GIT_SHA}${GIT_DIRTY}
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/spf13/cobra"
)

var GitCommit, Version string

type root struct {
kind string
name string
Expand All @@ -31,13 +33,16 @@ func newRootCommand(args []string) *cobra.Command {
os.Exit(1)
}
},
Version: func() string {
return fmt.Sprintf("%s (%s)\n", Version, GitCommit)
}(),
}

rootCmd.Flags().StringVarP(&root.kind, "kind", "k", "", "Only include resources of kind")
rootCmd.Flags().StringVarP(&root.name, "name", "n", "", "Only include resources of name")
rootCmd.Flags().StringVarP(&root.filename, "filename", "f", "", "Read manifests from file")

rootCmd.AddCommand(newVersionCommand())
rootCmd.SetVersionTemplate(`{{.Version}}`)

return rootCmd
}
Expand Down
24 changes: 0 additions & 24 deletions cmd/version.go

This file was deleted.

3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsC
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be h1:AHimNtVIpiBjPUhEF5KNCkrUyqTSA5zWUl8sQ2bfGBE=
github.com/json-iterator/go v0.0.0-20180701071628-ab8a2e0c74be/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand Down Expand Up @@ -75,6 +77,7 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db h1:6/JqlYfC1CCaLnGceQTI+sDGhC9UBSPAsBqI0Gun6kU=
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o=
Expand Down

0 comments on commit 109c8bb

Please sign in to comment.