Skip to content

Commit 7535fb3

Browse files
authored
Add /version endpoint (#7)
* add /version * fixup * fixup * add circleci config
1 parent ac8e9ff commit 7535fb3

File tree

7 files changed

+120
-10
lines changed

7 files changed

+120
-10
lines changed

.circleci/config.yml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/golang:1.12
6+
7+
environment:
8+
TEST_RESULTS: /tmp/test-results
9+
GO111MODULE: "on"
10+
11+
steps:
12+
- checkout
13+
- run: mkdir -p $TEST_RESULTS
14+
- restore_cache:
15+
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
16+
keys:
17+
- go-mod-v4-{{ checksum "go.sum" }}
18+
19+
- run: go get github.com/jstemmer/go-junit-report
20+
- run: go get ./...
21+
- run:
22+
name: Run unit tests
23+
24+
# store the results of our tests in the $TEST_RESULTS directory
25+
command: |
26+
PACKAGE_NAMES=$(go list ./... | circleci tests split --split-by=timings --timings-type=classname)
27+
gotestsum --junitfile ${TEST_RESULTS}/gotestsum-report.xml -- $PACKAGE_NAMES
28+
29+
- save_cache:
30+
key: go-mod-v4-{{ checksum "go.sum" }}
31+
paths:
32+
- "/go/pkg/mod"
33+
34+
- store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
35+
path: /tmp/test-results
36+
destination: raw-test-output
37+
38+
- store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
39+
path: /tmp/test-results
40+
41+
workflows:
42+
version: 2
43+
build-workflow:
44+
jobs:
45+
- build

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ node_modules/
88
.sass-cache/
99
*-packr.go
1010
public/assets/
11-
rds_api
1211
.vscode/
1312
.grifter/
1413
.env

actions/app.go

+24-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/YaleSpinup/rds-api/pkg/common"
88
"github.com/YaleSpinup/rds-api/pkg/rds"
9+
"github.com/YaleSpinup/rds-api/rdsapi"
910
"github.com/gobuffalo/buffalo"
1011
"github.com/gobuffalo/envy"
1112
paramlogger "github.com/gobuffalo/mw-paramlogger"
@@ -14,17 +15,31 @@ import (
1415
"github.com/rs/cors"
1516
)
1617

17-
// ENV is used to help switch settings based on where the
18-
// application is being run. Default is "development".
19-
var ENV = envy.Get("GO_ENV", "development")
18+
var (
19+
app *buffalo.App
2020

21-
// AppConfig holds the configuration information for the app
22-
var AppConfig common.Config
21+
// ENV is used to help switch settings based on where the
22+
// application is being run. Default is "development".
23+
ENV = envy.Get("GO_ENV", "development")
2324

24-
// RDS is a global map of RDS clients
25-
var RDS = make(map[string]rds.Client)
25+
// AppConfig holds the configuration information for the app
26+
AppConfig common.Config
2627

27-
var app *buffalo.App
28+
// RDS is a global map of RDS clients
29+
RDS = make(map[string]rds.Client)
30+
31+
// Version is the main version number
32+
Version = rdsapi.Version
33+
34+
// VersionPrerelease is a prerelease marker
35+
VersionPrerelease = rdsapi.VersionPrerelease
36+
37+
// BuildStamp is the timestamp the binary was built, it should be set at buildtime with ldflags
38+
BuildStamp = rdsapi.BuildStamp
39+
40+
// GitHash is the git sha of the built binary, it should be set at buildtime with ldflags
41+
GitHash = rdsapi.GitHash
42+
)
2843

2944
// App is where all routes and middleware for buffalo should be defined
3045
func App() *buffalo.App {
@@ -51,6 +66,7 @@ func App() *buffalo.App {
5166
}
5267

5368
app.GET("/v1/rds/ping", PingPong)
69+
app.GET("/v1/rds/version", VersionHandler)
5470

5571
rdsV1API := app.Group("/v1/rds/{account}")
5672
rdsV1API.Use(sharedTokenAuth(AppConfig.Token))

actions/version.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package actions
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/gobuffalo/buffalo"
7+
)
8+
9+
// VersionHandler returns the app version.
10+
func VersionHandler(c buffalo.Context) error {
11+
return c.Render(200, r.JSON(struct {
12+
Version string `json:"version"`
13+
GitHash string `json:"githash"`
14+
BuildStamp string `json:"buildstamp"`
15+
}{
16+
fmt.Sprintf("%s%s", Version, VersionPrerelease),
17+
GitHash,
18+
BuildStamp,
19+
}))
20+
}

docker/Dockerfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
33
FROM gobuffalo/buffalo:v0.14.3 as builder
44

5+
ARG version=0.0.0
6+
ARG prerelease
7+
ARG githash=""
8+
ARG buildstamp=""
9+
510
RUN mkdir /app
611
WORKDIR /app
712
ENV GO111MODULE=on
@@ -10,7 +15,8 @@ COPY go.sum .
1015
RUN go mod download
1116
ADD . .
1217
RUN go version
13-
RUN buffalo build --static -o /bin/api
18+
RUN buffalo build --static -o /bin/api --ldflags "-X github.com/YaleSpinup/rds-api/rdsapi.Version=$version -X github.com/YaleSpinup/rds-api/rdsapi.VersionPrerelease=$prerelease -X github.com/YaleSpinup/rds-api/rdsapi.GitHash=$githash -X github.com/YaleSpinup/rds-api/rdsapi.BuildStamp=$buildstamp"
19+
1420

1521
FROM alpine
1622
RUN apk add --no-cache bash

go.sum

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ
33
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
44
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
55
github.com/ajg/form v0.0.0-20160802194845-cc2954064ec9/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
6+
github.com/ajg/form v0.0.0-20160822230020-523a5da1a92f h1:zvClvFQwU++UpIUBGC8YmDlfhUrweEy1R1Fj1gu5iIM=
67
github.com/ajg/form v0.0.0-20160822230020-523a5da1a92f/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
78
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
89
github.com/aws/aws-sdk-go v1.16.26 h1:GWkl3rkRO/JGRTWoLLIqwf7AWC4/W/1hMOUZqmX0js4=
@@ -17,6 +18,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
1718
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
1819
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
1920
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
21+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2022
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2123
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
2224
github.com/dustin/go-humanize v0.0.0-20180713052910-9f541cc9db5d/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
@@ -163,6 +165,7 @@ github.com/gobuffalo/httptest v1.0.3/go.mod h1:7T1IbSrg60ankme0aDLVnEY0h056g9M1/
163165
github.com/gobuffalo/httptest v1.0.4/go.mod h1:7T1IbSrg60ankme0aDLVnEY0h056g9M1/ZvpVThtB7E=
164166
github.com/gobuffalo/httptest v1.0.5/go.mod h1:7T1IbSrg60ankme0aDLVnEY0h056g9M1/ZvpVThtB7E=
165167
github.com/gobuffalo/httptest v1.0.6/go.mod h1:7T1IbSrg60ankme0aDLVnEY0h056g9M1/ZvpVThtB7E=
168+
github.com/gobuffalo/httptest v1.1.0 h1:mOQXxhCL2moiDHIdNehj6XadD5xJWt92pH7UnvzmfrY=
166169
github.com/gobuffalo/httptest v1.1.0/go.mod h1:BIfCgiqCOotRc5xYwCcZN7IFYag4277Ynqjar/Ra3iI=
167170
github.com/gobuffalo/licenser v0.0.0-20180924033006-eae28e638a42/go.mod h1:Ubo90Np8gpsSZqNScZZkVXXAo5DGhTb+WYFIjlnog8w=
168171
github.com/gobuffalo/licenser v0.0.0-20181025145548-437d89de4f75/go.mod h1:x3lEpYxkRG/XtGCUNkio+6RZ/dlOvLzTI9M1auIwFcw=
@@ -202,6 +205,7 @@ github.com/gobuffalo/mw-basicauth v1.0.7/go.mod h1:xJ9/OSiOWl+kZkjaSun62srODr3Cx
202205
github.com/gobuffalo/mw-contenttype v0.0.0-20180802152300-74f5a47f4d56/go.mod h1:7EvcmzBbeCvFtQm5GqF9ys6QnCxz2UM1x0moiWLq1No=
203206
github.com/gobuffalo/mw-contenttype v0.0.0-20190129203934-2554e742333b/go.mod h1:7x87+mDrr9Peh7AqhOtESyJLanMd2zQNz2Hts+vtBoE=
204207
github.com/gobuffalo/mw-csrf v0.0.0-20180802151833-446ff26e108b/go.mod h1:sbGtb8DmDZuDUQoxjr8hG1ZbLtZboD9xsn6p77ppcHo=
208+
github.com/gobuffalo/mw-csrf v0.0.0-20190129204204-25460a055517 h1:pOOXwl1xPLLP8oZw3e3t2wwrc/KSzmlRBcaQwGpG9oo=
205209
github.com/gobuffalo/mw-csrf v0.0.0-20190129204204-25460a055517/go.mod h1:o5u+nnN0Oa7LBeDYH9QP36qeMPnXV9qbVnbZ4D+Kb0Q=
206210
github.com/gobuffalo/mw-forcessl v0.0.0-20180802152810-73921ae7a130/go.mod h1:JvNHRj7bYNAMUr/5XMkZaDcw3jZhUZpsmzhd//FFWmQ=
207211
github.com/gobuffalo/mw-i18n v0.0.0-20180802152014-e3060b7e13d6/go.mod h1:91AQfukc52A6hdfIfkxzyr+kpVYDodgAeT5cjX1UIj4=
@@ -237,6 +241,7 @@ github.com/gobuffalo/packr v1.21.0/go.mod h1:H00jGfj1qFKxscFJSw8wcL4hpQtPe1PfU2w
237241
github.com/gobuffalo/packr v1.21.5/go.mod h1:zCvDxrZzFmq5Xd7Jw4vaGe/OYwzuXnma31D2EbTHMWk=
238242
github.com/gobuffalo/packr v1.21.7/go.mod h1:73tmYjwi4Cvb1eNiAwpmrzZ0gxVA4KBqVSZ2FNeJodM=
239243
github.com/gobuffalo/packr v1.21.9/go.mod h1:GC76q6nMzRtR+AEN/VV4w0z2/4q7SOaEmXh3Ooa8sOE=
244+
github.com/gobuffalo/packr v1.22.0 h1:/YVd/GRGsu0QuoCJtlcWSVllobs4q3Xvx3nqxTvPyN0=
240245
github.com/gobuffalo/packr v1.22.0/go.mod h1:Qr3Wtxr3+HuQEwWqlLnNW4t1oTvK+7Gc/Rnoi/lDFvA=
241246
github.com/gobuffalo/packr/v2 v2.0.0-rc.5/go.mod h1:e6gmOfhf3KmT4zl2X/NDRSfBXk2oV4TXZ+NNOM0xwt8=
242247
github.com/gobuffalo/packr/v2 v2.0.0-rc.7/go.mod h1:BzhceHWfF3DMAkbPUONHYWs63uacCZxygFY1b4H9N2A=
@@ -291,6 +296,7 @@ github.com/gobuffalo/release v1.1.1/go.mod h1:Sluak1Xd6kcp6snkluR1jeXAogdJZpFFRz
291296
github.com/gobuffalo/release v1.1.3/go.mod h1:CuXc5/m+4zuq8idoDt1l4va0AXAn/OSs08uHOfMVr8E=
292297
github.com/gobuffalo/release v1.1.6/go.mod h1:18naWa3kBsqO0cItXZNJuefCKOENpbbUIqRL1g+p6z0=
293298
github.com/gobuffalo/shoulders v1.0.1/go.mod h1:V33CcVmaQ4gRUmHKwq1fiTXuf8Gp/qjQBUL5tHPmvbA=
299+
github.com/gobuffalo/suite v2.6.0+incompatible h1:3ZSHnZWhlMIdSMK9nxlC3H3KeC4fijoEIzMhl/8eZZc=
294300
github.com/gobuffalo/suite v2.6.0+incompatible/go.mod h1:VCaZ8EgrnJKbt0QGkrEKIMsJlWFxMXWYSHXqjH2UJJE=
295301
github.com/gobuffalo/syncx v0.0.0-20181120191700-98333ab04150/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
296302
github.com/gobuffalo/syncx v0.0.0-20181120194010-558ac7de985f h1:S5EeH1reN93KR0L6TQvkRpu9YggCYXrUqFh1iEgvdC0=
@@ -366,6 +372,7 @@ github.com/markbates/going v1.0.3/go.mod h1:fQiT6v6yQar9UD6bd/D4Z5Afbk9J6BBVBtLi
366372
github.com/markbates/grift v1.0.4/go.mod h1:wbmtW74veyx+cgfwFhlnnMWqhoz55rnHR47oMXzsyVs=
367373
github.com/markbates/grift v1.0.5 h1:GUHfm1Jb0ETaWcvvo9eESoqonnzM7DfcUn+5R/W9XNI=
368374
github.com/markbates/grift v1.0.5/go.mod h1:EHmVIjOQoj/OOBDzlZ8RW0ZkvOtQ4xRHjrPvmfoiFaU=
375+
github.com/markbates/hmax v1.0.0 h1:yo2N0gBoCnUMKhV/VRLHomT6Y9wUm+oQQENuWJqCdlM=
369376
github.com/markbates/hmax v1.0.0/go.mod h1:cOkR9dktiESxIMu+65oc/r/bdY4bE8zZw3OLhLx0X2c=
370377
github.com/markbates/inflect v1.0.0/go.mod h1:oTeZL2KHA7CUX6X+fovmK9OvIOFuqu0TwdQrZjLTh88=
371378
github.com/markbates/inflect v1.0.1/go.mod h1:uv3UVNBe5qBIfCm8O8Q+DW+S1EopeyINj+Ikhc7rnCk=
@@ -415,6 +422,7 @@ github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/9
415422
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
416423
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
417424
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
425+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
418426
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
419427
github.com/rogpeppe/go-internal v1.0.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
420428
github.com/rogpeppe/go-internal v1.1.0 h1:g0fH8RicVgNl+zVZDCDfbdWxAWoAEJyI7I3TZYXFiig=
@@ -461,6 +469,7 @@ github.com/spf13/viper v1.3.1/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
461469
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
462470
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
463471
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
472+
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
464473
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
465474
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
466475
github.com/unrolled/secure v0.0.0-20180918153822-f340ee86eb8b/go.mod h1:mnPT77IAdsi/kV7+Es7y+pXALeV3h7G6dQF6mNYjcLA=

rdsapi/version.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package rdsapi
2+
3+
// Version is the main version number that is being run at the moment.
4+
var Version = "No version set"
5+
6+
// VersionPrerelease is a pre-release marker for the version. If this is ""
7+
// then it means that it is a final release. Otherwise, this is a pre-release
8+
// such as "dev" (in development), "beta", "rc1", etc.
9+
var VersionPrerelease = ""
10+
11+
// BuildStamp is the build timestamp
12+
var BuildStamp = "No BuildStamp Provided"
13+
14+
// GitHash is the git hash ;)
15+
var GitHash = "No Git Commit Provided"

0 commit comments

Comments
 (0)