Skip to content

Commit f21cce0

Browse files
authored
Use GoReleaser to release and publish cortextool (#84)
* Use GoReleaser to release and publish cortextools
1 parent 0a1e94d commit f21cce0

File tree

142 files changed

+44652
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+44652
-3
lines changed

.goreleaser.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
# you may remove this if you don't need go generate
5+
- go generate ./...
6+
project_name: cortextool
7+
builds:
8+
- id: cortextool-darwin
9+
ldflags:
10+
-s -w -X github.com/grafana/cortex-tools/pkg/version.Version={{.Version}}
11+
binary: cortextool
12+
env:
13+
- CGO_ENABLED=0
14+
main: ./cmd/cortextool/main.go
15+
goos:
16+
- darwin
17+
goarch:
18+
- amd64
19+
- id: cortextool-linux
20+
ldflags:
21+
-s -w -X github.com/grafana/cortex-tools/pkg/version.Version={{.Version}}
22+
binary: cortextool
23+
env:
24+
- CGO_ENABLED=0
25+
main: ./cmd/cortextool/main.go
26+
goos:
27+
- linux
28+
goarch:
29+
- amd64
30+
- id: cortextool-windows
31+
ldflags:
32+
-s -w -X github.com/grafana/cortex-tools/pkg/version.Version={{.Version}}
33+
binary: cortextool
34+
env:
35+
- CGO_ENABLED=0
36+
main: ./cmd/cortextool/main.go
37+
goos:
38+
- windows
39+
goarch:
40+
- amd64
41+
- 386
42+
archives:
43+
- replacements:
44+
darwin: mac-os
45+
linux: linux
46+
windows: windows
47+
386: i386
48+
amd64: x86_64
49+
format_overrides:
50+
- goos: windows
51+
format: zip
52+
files:
53+
- none*
54+
format: binary
55+
checksum:
56+
name_template: 'checksums.txt'
57+
snapshot:
58+
name_template: "{{ .Tag }}-next"
59+
changelog:
60+
sort: asc
61+
filters:
62+
exclude:
63+
- '^docs:'
64+
- '^test:'
65+
dockers:
66+
- goos: linux
67+
goarch: amd64
68+
binaries:
69+
- cortextool
70+
builds:
71+
- cortextool-linux
72+
dockerfile: cmd/cortextool/GR.Dockerfile
73+
image_templates:
74+
- "grafana/cortex-tools:latest"
75+
- "grafana/cortex-tools:{{ .Tag }}"
76+
build_flag_templates:
77+
- "--pull"
78+
- "--label=org.opencontainers.image.created={{.Date}}"
79+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
80+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
81+
- "--label=org.opencontainers.image.version={{.Version}}"
82+
- "--label=repository=https://github.com/grafana/cortex-tools"
83+
- "--label=homepage=https://grafana.com"

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
## unreleased / master
44

5-
* [FEATURE] Added loki backend support for the rules commands, configurable with `--backend=loki` (defaults to cortex).
5+
## v0.3.0
66

7+
* [FEATURE] Added loki backend support for the rules commands, configurable with `--backend=loki` (defaults to cortex).
78
## v0.2.4
89

910
* [BUGFIX] Fix alertmanager registration subcommand and path for the configuration API #72

RELEASE.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
# Steps to create the release:
1+
# Release processes
2+
3+
## GoReleaser (`cortextool` only)
4+
5+
1. Create a changelog file in `changelog/` with the name of the tag e.g. `changelog/v0.3.0.md`. This will be used as the template for the release page in GitHub.
6+
2. Create a new tag that follows semantic versioning:
7+
8+
```bash
9+
$ tag=v0.3.0
10+
$ git tag -s "${tag}" -m "${tag}"
11+
$ git push origin "${tag}"
12+
```
13+
14+
3. Run `$ goreleaser --release-notes=changelogs/v0.3.0.md --rm-dist` where the changelog file is the one created as part of step 1.
15+
4. The docker image will be pushed automatically.
16+
17+
18+
## Manual (all the other binaries)
219

320
1. Manually build and test the new additions
421
2. Create a new tag based on:

changelogs/v0.3.0.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changes
2+
3+
* [FEATURE] Added loki backend support for the rules commands, configurable with `--backend=loki` (defaults to cortex).
4+
* [FEATURE] Introduces a new `version` command. The command will also let you know if there's a new version available.
5+
6+
# Installation
7+
8+
## cortextool
9+
```
10+
# download the binary (adapt os and arch as needed)
11+
$ curl -fSL -o "/usr/local/bin/cortextool" "https://github.com/grafana/cortex-tools/releases/download/v0.3.0/cortextool_0.3.0_linux_x86_64"
12+
13+
# make it executable
14+
$ chmod a+x "/usr/local/bin/cortextool"
15+
16+
# have fun :)
17+
$ cortextool --help
18+
```

cmd/cortextool/GR.Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM alpine:3.9
2+
RUN apk add --update --no-cache ca-certificates
3+
COPY cortextool /usr/bin/cortextool
4+
EXPOSE 80
5+
ENTRYPOINT [ "/usr/bin/cortextool" ]

cmd/cortextool/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56

67
"gopkg.in/alecthomas/kingpin.v2"
78

89
"github.com/grafana/cortex-tools/pkg/commands"
10+
"github.com/grafana/cortex-tools/pkg/version"
911
)
1012

1113
var (
@@ -18,14 +20,21 @@ var (
1820
)
1921

2022
func main() {
21-
kingpin.Version("0.1.3")
2223
app := kingpin.New("cortextool", "A command-line tool to manage cortex.")
2324
logConfig.Register(app)
2425
alertCommand.Register(app)
2526
alertmanagerCommand.Register(app)
2627
ruleCommand.Register(app)
2728
pushGateway.Register(app)
2829
loadgenCommand.Register(app)
30+
31+
app.Command("version", "Get the version of the cortextool CLI").Action(func(k *kingpin.ParseContext) error {
32+
fmt.Print(version.Template)
33+
version.CheckLatest()
34+
35+
return nil
36+
})
37+
2938
kingpin.MustParse(app.Parse(os.Args[1:]))
3039

3140
pushGateway.Stop()

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/gogo/protobuf v1.3.1
1313
github.com/golang/snappy v0.0.1
1414
github.com/google/go-cmp v0.4.0
15+
github.com/google/go-github/v32 v32.1.0
1516
github.com/grafana/loki v1.6.2-0.20200831213751-f905e77259f2
1617
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
1718
github.com/opentracing/opentracing-go v1.2.0

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,10 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
525525
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
526526
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
527527
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
528+
github.com/google/go-github v17.0.0+incompatible h1:N0LgJ1j65A7kfXrZnUDaYCs/Sf4rEjNlfyDHW9dolSY=
528529
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
530+
github.com/google/go-github/v32 v32.1.0 h1:GWkQOdXqviCPx7Q7Fj+KyPoGm4SwHRh8rheoPhd27II=
531+
github.com/google/go-github/v32 v32.1.0/go.mod h1:rIEpZD9CTDQwDK9GDrtMTycQNA4JU3qBsCizh3q2WCI=
529532
github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
530533
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
531534
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
@@ -1486,6 +1489,7 @@ google.golang.org/api v0.26.0 h1:VJZ8h6E8ip82FRpQl848c5vAadxlTXrUh8RzQzSRm08=
14861489
google.golang.org/api v0.26.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
14871490
google.golang.org/api v0.29.0 h1:BaiDisFir8O4IJxvAabCGGkQ6yCJegNQqSVoYUNAnbk=
14881491
google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
1492+
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
14891493
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
14901494
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
14911495
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=

pkg/version/version.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package version
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/google/go-github/v32/github"
9+
log "github.com/sirupsen/logrus"
10+
)
11+
12+
// Version defines the version for the binary, this is actually set by GoReleaser.
13+
var Version = "master"
14+
15+
// Template controls how the version is displayed
16+
var Template = fmt.Sprintf("version %s\n", Version)
17+
18+
// CheckLatest asks GitHub
19+
func CheckLatest() {
20+
if Version != "master" {
21+
latest := getLatestFromGitHub()
22+
version := Version
23+
if latest != "" && (strings.TrimPrefix(latest, "v") != strings.TrimPrefix(version, "v")) {
24+
fmt.Printf("A newer version of cortextool is available, please update to %s\n", latest)
25+
} else {
26+
fmt.Println("You are on the latest version")
27+
}
28+
}
29+
}
30+
31+
func getLatestFromGitHub() string {
32+
fmt.Print("checking latest version... ")
33+
c := github.NewClient(nil)
34+
resp, _, err := c.Repositories.GetLatestRelease(context.Background(), "grafana", "cortex-tools")
35+
36+
if err != nil {
37+
log.WithFields(log.Fields{"err": err}).Debugln("failed to retrieve latest version")
38+
}
39+
40+
return *resp.TagName
41+
}

0 commit comments

Comments
 (0)