Skip to content

Commit

Permalink
Merge pull request #12 from tparker00/version
Browse files Browse the repository at this point in the history
Add version information
  • Loading branch information
tparker00 authored Sep 2, 2024
2 parents 86882d5 + c1e7126 commit f1753f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM golang:alpine AS builder

RUN apk add --no-cache musl-dev gcc
RUN apk add --no-cache musl-dev gcc git
COPY . .

RUN cd cmd/bws-cache && go build -ldflags='-s -w' -trimpath -o /dist/bws-cache
RUN go generate ./internal/pkg/config/config.go
RUN cd cmd/bws-cache && go build -ldflags='-s -w' -o /dist/bws-cache
RUN ldd /dist/bws-cache | tr -s [:blank:] '\n' | grep ^/ | xargs -I % install -D % /dist/%


Expand Down
5 changes: 3 additions & 2 deletions cmd/bws-cache/bws-cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"os"
"strings"

c "bws-cache/internal/pkg/config"
h "bws-cache/internal/pkg/http"
Expand Down Expand Up @@ -51,7 +52,7 @@ func main() {
}

func version() {
fmt.Println("0.1.0")
fmt.Println(c.Commit)
}

func start() {
Expand Down Expand Up @@ -89,7 +90,7 @@ func start() {
}

func getLoggerLevel(config string) slog.Level {
switch config {
switch strings.ToUpper(config) {
case "DEBUG":
return slog.LevelDebug
case "WARN":
Expand Down
24 changes: 6 additions & 18 deletions internal/pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"fmt"
"log/slog"
"net/http"
"runtime/debug"
"strings"
"time"

"bws-cache/internal/pkg/client"
"bws-cache/internal/pkg/config"
c "bws-cache/internal/pkg/config"
"bws-cache/internal/pkg/metrics"

"github.com/go-chi/chi/v5"
Expand All @@ -19,18 +18,6 @@ import (
"github.com/pkg/errors"
)

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}

return ""
}()

type API struct {
SecretTTL time.Duration
WebTTL time.Duration
Expand All @@ -39,7 +26,7 @@ type API struct {
Metrics *metrics.BwsMetrics
}

func New(config *config.Config) http.Handler {
func New(config *c.Config) http.Handler {
api := API{
SecretTTL: config.SecretTTL,
OrgID: config.OrgID,
Expand All @@ -50,12 +37,13 @@ func New(config *config.Config) http.Handler {
logger := httplog.NewLogger("bws-cache", httplog.Options{
JSON: true,
LogLevel: slog.LevelInfo,
Concise: true,
Concise: false,
RequestHeaders: true,
MessageFieldName: "message",
MessageFieldName: "msg",
TimeFieldFormat: time.RFC3339,
TimeFieldName: "time",
Tags: map[string]string{
"version": commit,
"version": c.Commit,
},
QuietDownRoutes: []string{
"/",
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/config/commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
placeholder
5 changes: 5 additions & 0 deletions internal/pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
_ "embed"
"strings"
"time"

Expand All @@ -19,6 +20,10 @@ type Config struct {
Connection client.Bitwarden
}

//go:generate sh -c "printf %s $(git rev-parse HEAD) > commit.txt"
//go:embed commit.txt
var Commit string

func LoadConfig(config *Config) {
v := viper.New()
v.SetEnvPrefix("bws_cache")
Expand Down

0 comments on commit f1753f1

Please sign in to comment.