Skip to content

Commit 79ee829

Browse files
authored
Merge pull request #34 from cortexproject/release-to-quay
Use goreleaser for releases to quay.io
2 parents 33d08f7 + 1793ced commit 79ee829

File tree

8 files changed

+198
-5
lines changed

8 files changed

+198
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ docker-images/
99
.vscode
1010
compose
1111
compose-simple
12+
dist/

.goreleaser.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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: auth-gateway
7+
builds:
8+
- id: auth-gateway-darwin
9+
ldflags:
10+
-s -w -X github.com/cortexproject/auth-gateway/version.Version={{.Version}}
11+
binary: auth-gateway
12+
env:
13+
- CGO_ENABLED=0
14+
goos:
15+
- darwin
16+
goarch:
17+
- amd64
18+
- arm64
19+
- id: auth-gateway-linux
20+
ldflags:
21+
-s -w -X github.com/cortexproject/auth-gateway/version.Version={{.Version}}
22+
binary: auth-gateway
23+
env:
24+
- CGO_ENABLED=0
25+
goos:
26+
- linux
27+
goarch:
28+
- amd64
29+
- arm64
30+
- id: auth-gateway-windows
31+
ldflags:
32+
-s -w -X github.com/cortexproject/auth-gateway/version.Version={{.Version}}
33+
binary: auth-gateway
34+
env:
35+
- CGO_ENABLED=0
36+
goos:
37+
- windows
38+
goarch:
39+
- amd64
40+
- arm64
41+
archives:
42+
- format_overrides:
43+
- goos: windows
44+
format: zip
45+
files:
46+
- none*
47+
format: binary
48+
checksum:
49+
name_template: 'checksums.txt'
50+
snapshot:
51+
name_template: "{{ .Tag }}-next"
52+
changelog:
53+
sort: asc
54+
filters:
55+
exclude:
56+
- '^docs:'
57+
- '^test:'
58+
dockers:
59+
- goarch: amd64
60+
image_templates:
61+
- "quay.io/cortexproject/auth-gateway:{{ .Tag }}-amd64"
62+
build_flag_templates:
63+
- "--label=org.opencontainers.image.created={{.Date}}"
64+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
65+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
66+
- "--label=org.opencontainers.image.version={{.Version}}"
67+
- "--label=repository=https://github.com/cortexproject/auth-gateway"
68+
- "--label=homepage=https://cortexmetrics.io"
69+
- "--platform=linux/amd64"
70+
use: buildx
71+
- goarch: arm64
72+
image_templates:
73+
- "quay.io/cortexproject/auth-gateway:{{ .Tag }}-arm64"
74+
build_flag_templates:
75+
- "--label=org.opencontainers.image.created={{.Date}}"
76+
- "--label=org.opencontainers.image.name={{.ProjectName}}"
77+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
78+
- "--label=org.opencontainers.image.version={{.Version}}"
79+
- "--label=repository=https://github.com/cortexproject/auth-gateway"
80+
- "--label=homepage=https://cortexmetrics.io"
81+
- "--platform=linux/arm64"
82+
use: buildx
83+
docker_manifests:
84+
- name_template: "quay.io/cortexproject/auth-gateway:{{.Tag}}"
85+
image_templates:
86+
- "quay.io/cortexproject/auth-gateway:{{.Tag}}-amd64"
87+
- "quay.io/cortexproject/auth-gateway:{{.Tag}}-arm64"

Dockerfile

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

RELEASE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Release process
2+
3+
1. Create a new tag that follows semantic versioning:
4+
5+
```bash
6+
$ tag=v0.3.0
7+
$ git tag -s "${tag}" -m "${tag}"
8+
$ git push origin "${tag}"
9+
```
10+
11+
2. Make sure you are using goreleaser >= v1.19.2
12+
3. Run `$ goreleaser release --rm-dist`
13+

go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,32 @@ module github.com/cortexproject/auth-gateway
33
go 1.20
44

55
require (
6+
github.com/google/go-github/v53 v53.2.0
67
github.com/prometheus/client_golang v1.14.0
78
github.com/sirupsen/logrus v1.6.0
89
github.com/stretchr/testify v1.8.2
910
gopkg.in/yaml.v2 v2.4.0
1011
)
1112

1213
require (
14+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect
1315
github.com/beorn7/perks v1.0.1 // indirect
1416
github.com/cespare/xxhash/v2 v2.1.2 // indirect
17+
github.com/cloudflare/circl v1.3.3 // indirect
1518
github.com/davecgh/go-spew v1.1.1 // indirect
1619
github.com/golang/protobuf v1.5.2 // indirect
17-
github.com/google/go-cmp v0.5.9 // indirect
20+
github.com/google/go-querystring v1.1.0 // indirect
1821
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
1922
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
2023
github.com/pmezard/go-difflib v1.0.0 // indirect
2124
github.com/prometheus/client_model v0.3.0 // indirect
2225
github.com/prometheus/common v0.37.0 // indirect
2326
github.com/prometheus/procfs v0.8.0 // indirect
24-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
27+
golang.org/x/crypto v0.7.0 // indirect
28+
golang.org/x/net v0.10.0 // indirect
29+
golang.org/x/oauth2 v0.8.0 // indirect
30+
golang.org/x/sys v0.8.0 // indirect
31+
google.golang.org/appengine v1.6.7 // indirect
2532
google.golang.org/protobuf v1.28.1 // indirect
2633
gopkg.in/yaml.v3 v3.0.1 // indirect
2734
)

go.sum

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
3333
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
3434
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3535
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
36+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA=
37+
github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g=
3638
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3739
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3840
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -42,6 +44,7 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
4244
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
4345
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
4446
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
47+
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
4548
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4649
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
4750
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -50,6 +53,9 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
5053
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
5154
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
5255
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
56+
github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I=
57+
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
58+
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
5359
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
5460
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5561
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
@@ -108,10 +114,14 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
108114
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
109115
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
110116
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
117+
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
111118
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
112119
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
113120
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
114-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
121+
github.com/google/go-github/v53 v53.2.0 h1:wvz3FyF53v4BK+AsnvCmeNhf8AkTaeh2SoYu/XUvTtI=
122+
github.com/google/go-github/v53 v53.2.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao=
123+
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
124+
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
115125
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
116126
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
117127
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
@@ -217,6 +227,9 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
217227
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
218228
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
219229
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
230+
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
231+
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
232+
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
220233
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
221234
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
222235
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -275,16 +288,21 @@ golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/
275288
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
276289
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
277290
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
291+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
278292
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
279293
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
280294
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
295+
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
296+
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
281297
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
282298
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
283299
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
284300
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
285301
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
286302
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
287303
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
304+
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
305+
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
288306
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
289307
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
290308
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -330,10 +348,11 @@ golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7w
330348
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
331349
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
332350
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
351+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
333352
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
334353
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
335-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
336-
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
354+
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
355+
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
337356
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
338357
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
339358
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -412,6 +431,8 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
412431
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
413432
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
414433
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
434+
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
435+
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
415436
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
416437
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
417438
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import (
88
"github.com/cortexproject/auth-gateway/middleware"
99
"github.com/cortexproject/auth-gateway/server"
1010
"github.com/cortexproject/auth-gateway/utils"
11+
"github.com/cortexproject/auth-gateway/version"
1112
)
1213

1314
func main() {
15+
fmt.Print(version.Template)
16+
version.CheckLatest()
1417
if len(os.Args) < 2 {
1518
fmt.Println("No configuration file is provided")
1619
os.Exit(1)

version/version.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package version
2+
3+
import (
4+
"context"
5+
"errors"
6+
"fmt"
7+
"strings"
8+
9+
"github.com/google/go-github/v53/github"
10+
log "github.com/sirupsen/logrus"
11+
)
12+
13+
var (
14+
errUnableToRetrieveLatestVersion = errors.New("unable to fetch the latest version from GitHub")
15+
)
16+
17+
// Version defines the version for the binary, this is actually set by GoReleaser.
18+
var Version = "main"
19+
20+
// Template controls how the version is displayed
21+
var Template = fmt.Sprintf("version %s\n", Version)
22+
23+
// CheckLatest asks GitHub
24+
func CheckLatest() {
25+
if Version != "main" {
26+
latest, err := getLatestFromGitHub()
27+
if err != nil {
28+
fmt.Println(err)
29+
return
30+
}
31+
32+
version := Version
33+
if latest != "" && (strings.TrimPrefix(latest, "v") != strings.TrimPrefix(version, "v")) {
34+
fmt.Printf("A newer version of auth-gateway is available, please update to %s\n", latest)
35+
} else {
36+
fmt.Println("You are on the latest version")
37+
}
38+
}
39+
}
40+
41+
func getLatestFromGitHub() (string, error) {
42+
fmt.Print("checking latest version... ")
43+
c := github.NewClient(nil)
44+
repoRelease, resp, err := c.Repositories.GetLatestRelease(context.Background(), "cortexproject", "auth-gateway")
45+
if err != nil {
46+
log.WithFields(log.Fields{"err": err}).Debugln("error while retrieving the latest version")
47+
return "", errUnableToRetrieveLatestVersion
48+
}
49+
50+
if resp.StatusCode/100 != 2 {
51+
log.WithFields(log.Fields{"status": resp.StatusCode}).Debugln("non-2xx status code while contacting the GitHub API")
52+
return "", errUnableToRetrieveLatestVersion
53+
}
54+
55+
return *repoRelease.TagName, nil
56+
}

0 commit comments

Comments
 (0)