Skip to content

Commit

Permalink
chore: add release scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao committed Apr 7, 2019
1 parent ea5bcbd commit 240fa90
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
vcheck
build
dist
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o /app/vcheck
ARG VERSION
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -ldflags="-X main.Version=$VERSION" -o /app/vcheck

FROM alpine
RUN apk update && apk add ca-certificates
Expand Down
40 changes: 36 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
VERSION:=$(shell git describe --tags --always --dirty)
IMAGE:=anjmao/vcheck:$(VERSION)
GHACCOUNT := anjmao
NAME := vcheck
VERSION := $(shell git describe --tags --always --dirty)
DOCKER_IMAGE_NAME := $(GHACCOUNT)/$(NAME):$(VERSION)
LATFORM := $(shell go env | grep GOHOSTOS | cut -d '"' -f 2)
ARCH := $(shell go env | grep GOARCH | cut -d '"' -f 2)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
LDFLAGS := -ldflags "-X main.Version=$(VERSION)"

container:
@docker build -t $(IMAGE) .
@docker build --build-arg VERSION=$(VERSION) -t $(DOCKER_IMAGE_NAME) .

push:
@docker push $(IMAGE)
@docker push $(DOCKER_IMAGE_NAME)

compile:
@rm -rf build/
@gox $(LDFLAGS) \
-osarch="darwin/amd64" \
-osarch="linux/amd64" \
-osarch="windows/amd64" \
-output "build/$(NAME)_$(VERSION)_{{.OS}}_{{.Arch}}/$(NAME)" \
./...

dist: compile
$(eval FILES := $(shell ls build))
@rm -rf dist && mkdir dist
@for f in $(FILES); do \
(cd $(shell pwd)/build/$$f && tar -cvzf ../../dist/$$f.tar.gz *); \
(cd $(shell pwd)/dist && shasum -a 512 $$f.tar.gz > $$f.sha512); \
echo $$f; \
done

release: dist
@latest_tag=$$(git describe --tags `git rev-list --tags --max-count=1`); \
comparison="$$latest_tag..HEAD"; \
if [ -z "$$latest_tag" ]; then comparison=""; fi; \
changelog=$$(git log $$comparison --oneline --no-merges --reverse); \
github-release $(GHACCOUNT)/$(NAME) $(VERSION) $(BRANCH) "**Changelog**<br/>$$changelog" 'dist/*'; \
git pull
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ vcheck \
--target=staging.my.grpcapi.net:443 \
--method=/version.Version/GetVersion \
--client=grpc \
--version=${MY_CI_BUILD_NUMBER} \
--expect=${MY_CI_BUILD_NUMBER} \
--count=12 \
--sleep=5
```
Expand All @@ -43,7 +43,7 @@ vcheck \
--target=http://staging.my.grpcapi.net \
--method=/api/version \
--client=http \
--version=${MY_CI_BUILD_NUMBER} \
--expect=${MY_CI_BUILD_NUMBER} \
--count=12 \
--sleep=5
```
Expand All @@ -55,3 +55,15 @@ vheck util is also available as a docker image
```bash
docker run --rm anjmao:vcheck --help
```

### Release

Before release install gox and github-release tools
```bash
go GO111MODULE=off go get github.com/mitchellh/gox
go GO111MODULE=off go get github.com/c4milo/github-release
```

```bash
make release
```
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d h1:g9qWBGx4puODJTMVyoPrpoxPF
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
36 changes: 23 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,33 @@ import (
)

var (
target = flag.String("target", "", "-target staging.mpost-api.guardtek.net:443")
expectedVersion = flag.String("version", "", "Expected version")
method = flag.String("method", "/version.Version/GetVersion", "Version check endpoint path")
clientType = flag.String("client", "grpc", "Version check client type")
checkCount = flag.Int("count", 12, "Check count")
sleepAfterCheck = flag.Int("sleep", 5, "Sleep after check in seconds")
showHelp = flag.Bool("help", false, "Show help")
target = flag.String("target", "", "Version check endpoint target")
expectedBuildVersion = flag.String("expect", "", "Expected version")
method = flag.String("method", "/version.Version/GetVersion", "Version check endpoint path")
clientType = flag.String("client", "grpc", "Version check client type")
checkCount = flag.Int("count", 12, "Check count")
sleepAfterCheck = flag.Int("sleep", 5, "Sleep after check in seconds")
printHelp = flag.Bool("help", false, "Print help")
printVersion = flag.Bool("version", false, "Print vcheck version")
)

var Version = "dev"

const checkTimeout = 10 * time.Second

const usageStr = `
Usage: vcheck [options]
Options:
--target <target> Target host including port. (e.g --target service.mydomain.com:443)
--version <version> Expected version (e.g -v 1.2.3)
--expect <version> Expected version (e.g -v 1.2.3)
--method <method> Version check endpoint (default: /debug.Debug/GetVersion)
--client <client> Client type (grpc, http)
--count <count> Check count (default: 12)
--sleep <sleep> Sleep duration after check in seconds (default: 5)
Other options:
--help
--help Print help
--version Print vcheck util version
`

func usage() {
Expand All @@ -43,7 +47,13 @@ func usage() {

func main() {
flag.Parse()
if *showHelp || *target == "" || *expectedVersion == "" {

if *printVersion {
fmt.Println(Version)
os.Exit(0)
}

if *printHelp || *target == "" || *expectedBuildVersion == "" {
usage()
}

Expand All @@ -59,16 +69,16 @@ func main() {
continue
}
actualVersion = v.BuildVersion
fmt.Printf("expected version %s, got %s\n", *expectedVersion, actualVersion)
if actualVersion == *expectedVersion {
fmt.Printf("expected version %s, got %s\n", *expectedBuildVersion, actualVersion)
if actualVersion == *expectedBuildVersion {
fmt.Println("deployment successful")
return
}

time.Sleep(sleep)
}

log.Fatalf("deployment failed: expected version %s, got %s\n", *expectedVersion, actualVersion)
log.Fatalf("deployment failed: expected version %s, got %s\n", *expectedBuildVersion, actualVersion)
}

func getVersion(c client.Client) (*client.GetVersionReply, error) {
Expand Down

0 comments on commit 240fa90

Please sign in to comment.