Skip to content

Commit

Permalink
refactor: replace util/version with versioninfo dep (#406)
Browse files Browse the repository at this point in the history
this should fix version metadata being missing or incorrect for several
tools.

the old mechanism required pushing through a linker variable at build
time (eg, in dockerfile). this package pulls the info a different way
which works more reliably. note that it doesn't work with `go run`, but
it does with `go build`. because we don't have tags/versions in this
repo, we'll get versions like `rev-42f80c4`, which seems fine.
  • Loading branch information
bnewbold authored Oct 31, 2023
2 parents 88a7f1a + 42f80c4 commit b761d05
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cmd/beemo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR /dockerbuild
# timezone data for alpine builds
ENV GOEXPERIMENT=loopvar
RUN GIT_VERSION=$(git describe --tags --long --always) && \
go build -tags timetzdata -ldflags="-X github.com/bluesky-social/indigo/version.Version=$GIT_VERSION" -o /beemo ./cmd/beemo
go build -tags timetzdata -o /beemo ./cmd/beemo

### Run stage
FROM alpine:3.18
Expand Down
4 changes: 2 additions & 2 deletions cmd/beemo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (

comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/version"
"github.com/bluesky-social/indigo/xrpc"

_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/urfave/cli/v2"
)
Expand All @@ -38,7 +38,7 @@ func run(args []string) error {
app := cli.App{
Name: "beemo",
Usage: "bluesky moderation reporting bot",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/bigsky/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR /dockerbuild
# timezone data for alpine builds
ENV GOEXPERIMENT=loopvar
RUN GIT_VERSION=$(git describe --tags --long --always) && \
go build -tags timetzdata -ldflags="-X github.com/bluesky-social/indigo/version.Version=$GIT_VERSION" -o /bigsky ./cmd/bigsky
go build -tags timetzdata -o /bigsky ./cmd/bigsky

### Build Frontend stage
FROM node:18-alpine as web-builder
Expand Down
4 changes: 2 additions & 2 deletions cmd/bigsky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/bluesky-social/indigo/repomgr"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"
"github.com/bluesky-social/indigo/xrpc"
_ "go.uber.org/automaxprocs"

Expand All @@ -31,6 +30,7 @@ import (

_ "github.com/joho/godotenv/autoload"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel"
Expand Down Expand Up @@ -58,7 +58,7 @@ func run(args []string) {
app := cli.App{
Name: "bigsky",
Usage: "atproto BGS/firehose daemon",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/fakermaker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import (
comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/fakedata"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"

_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
"github.com/urfave/cli/v2"
"golang.org/x/sync/errgroup"
)
Expand All @@ -32,7 +32,7 @@ func run(args []string) {
app := cli.App{
Name: "fakermaker",
Usage: "bluesky fake account/content generator",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/gosky/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/bluesky-social/indigo/repo"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"
"github.com/bluesky-social/indigo/xrpc"

"github.com/gorilla/websocket"
Expand All @@ -37,6 +36,7 @@ import (
_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/polydawn/refmt/cbor"
rejson "github.com/polydawn/refmt/json"
Expand All @@ -55,7 +55,7 @@ func run(args []string) {
app := cli.App{
Name: "gosky",
Usage: "client CLI for atproto and bluesky",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/labelmaker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR /dockerbuild
# timezone data for alpine builds
ENV GOEXPERIMENT=loopvar
RUN GIT_VERSION=$(git describe --tags --long --always) && \
go build -tags timetzdata -ldflags="-X github.com/bluesky-social/indigo/version.Version=$GIT_VERSION" -o /labelmaker ./cmd/labelmaker
go build -tags timetzdata -o /labelmaker ./cmd/labelmaker

### Run stage
FROM alpine:3.18
Expand Down
4 changes: 2 additions & 2 deletions cmd/labelmaker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/bluesky-social/indigo/carstore"
"github.com/bluesky-social/indigo/labeler"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"
"github.com/urfave/cli/v2"

_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/whyrusleeping/go-did"
"gorm.io/plugin/opentelemetry/tracing"
Expand All @@ -32,7 +32,7 @@ func run(args []string) error {
app := cli.App{
Name: "labelmaker",
Usage: "atproto content labeling daemon",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/laputa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"github.com/bluesky-social/indigo/pds"
"github.com/bluesky-social/indigo/plc"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"

_ "github.com/joho/godotenv/autoload"
_ "go.uber.org/automaxprocs"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/urfave/cli/v2"
"go.opentelemetry.io/otel"
Expand All @@ -36,7 +36,7 @@ func run(args []string) {
app := cli.App{
Name: "laputa",
Usage: "bluesky PDS in golang",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/netsync/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"golang.org/x/time/rate"

"github.com/bluesky-social/indigo/util/version"
"github.com/carlmjohnson/versioninfo"
"github.com/urfave/cli/v2"
)

Expand All @@ -32,7 +32,7 @@ func main() {
app := cli.App{
Name: "netsync",
Usage: "atproto network cloning tool",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
2 changes: 1 addition & 1 deletion cmd/palomar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR /dockerbuild
# timezone data for alpine builds
ENV GOEXPERIMENT=loopvar
RUN GIT_VERSION=$(git describe --tags --long --always) && \
go build -tags timetzdata -ldflags="-X github.com/bluesky-social/indigo/version.Version=$GIT_VERSION" -o /palomar ./cmd/palomar
go build -tags timetzdata -o /palomar ./cmd/palomar

### Run stage
FROM alpine:3.18
Expand Down
4 changes: 2 additions & 2 deletions cmd/palomar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/bluesky-social/indigo/search"
"github.com/bluesky-social/indigo/util/cliutil"

"github.com/bluesky-social/indigo/util/version"
"github.com/carlmjohnson/versioninfo"
es "github.com/opensearch-project/opensearch-go/v2"
cli "github.com/urfave/cli/v2"
)
Expand All @@ -42,7 +42,7 @@ func run(args []string) error {
app := cli.App{
Name: "palomar",
Usage: "search indexing and query service (using ES or OS)",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
3 changes: 2 additions & 1 deletion cmd/querycheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"

"github.com/carlmjohnson/versioninfo"
"github.com/urfave/cli/v2"
)

func main() {
app := cli.App{
Name: "querycheck",
Usage: "a postgresql query plan checker",
Version: "0.0.1",
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/sonar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ import (
"github.com/bluesky-social/indigo/events"
"github.com/bluesky-social/indigo/events/schedulers/autoscaling"
"github.com/bluesky-social/indigo/sonar"
"github.com/bluesky-social/indigo/util/version"
"github.com/gorilla/websocket"
"github.com/prometheus/client_golang/prometheus/promhttp"
_ "go.uber.org/automaxprocs"
"go.uber.org/zap"

"github.com/carlmjohnson/versioninfo"
"github.com/urfave/cli/v2"
)

func main() {
app := cli.App{
Name: "sonar",
Usage: "atproto firehose monitoring tool",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
4 changes: 2 additions & 2 deletions cmd/stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/bluesky-social/indigo/repo"
"github.com/bluesky-social/indigo/testing"
"github.com/bluesky-social/indigo/util/cliutil"
"github.com/bluesky-social/indigo/util/version"
"github.com/bluesky-social/indigo/xrpc"

"github.com/ipfs/go-cid"
Expand All @@ -26,6 +25,7 @@ import (

_ "github.com/joho/godotenv/autoload"

"github.com/carlmjohnson/versioninfo"
logging "github.com/ipfs/go-log"
"github.com/ipld/go-car"
cli "github.com/urfave/cli/v2"
Expand All @@ -41,7 +41,7 @@ func run(args []string) {
app := cli.App{
Name: "stress",
Usage: "load generation tool for PDS instances",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Commands = []*cli.Command{
Expand Down
5 changes: 2 additions & 3 deletions cmd/supercollider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/bluesky-social/indigo/indexer"
"github.com/bluesky-social/indigo/models"
"github.com/bluesky-social/indigo/plc"
"github.com/bluesky-social/indigo/util/version"
petname "github.com/dustinkirkland/golang-petname"
"github.com/icrowley/fake"
"github.com/labstack/echo-contrib/pprof"
Expand All @@ -48,8 +47,8 @@ import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"

"github.com/carlmjohnson/versioninfo"
cbg "github.com/whyrusleeping/cbor-gen"

"go.uber.org/zap"
)

Expand Down Expand Up @@ -88,7 +87,7 @@ func main() {
app := cli.App{
Name: "supercollider",
Usage: "atproto event noise-maker for BGS load testing",
Version: version.Version,
Version: versioninfo.Short(),
}

app.Flags = []cli.Flag{
Expand Down
5 changes: 3 additions & 2 deletions fakedata/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

comatproto "github.com/bluesky-social/indigo/api/atproto"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/version"
"github.com/bluesky-social/indigo/xrpc"

"github.com/carlmjohnson/versioninfo"
)

type AccountCatalog struct {
Expand Down Expand Up @@ -77,7 +78,7 @@ func ReadAccountCatalog(path string) (*AccountCatalog, error) {

func AccountXrpcClient(pdsHost string, ac *AccountContext) (*xrpc.Client, error) {
httpClient := util.RobustHTTPClient()
ua := "IndigoFakerMaker/" + version.Version
ua := "IndigoFakerMaker/" + versioninfo.Short()
xrpcc := &xrpc.Client{
Client: httpClient,
Host: pdsHost,
Expand Down
5 changes: 3 additions & 2 deletions labeler/hiveai.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

lexutil "github.com/bluesky-social/indigo/lex/util"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/version"

"github.com/carlmjohnson/versioninfo"
)

type HiveAILabeler struct {
Expand Down Expand Up @@ -117,7 +118,7 @@ func (hal *HiveAILabeler) LabelBlob(ctx context.Context, blob lexutil.LexBlob, b
req.Header.Set("Authorization", fmt.Sprintf("Token %s", hal.ApiToken))
req.Header.Add("Content-Type", writer.FormDataContentType())
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "labelmaker/"+version.Version)
req.Header.Set("User-Agent", "labelmaker/"+versioninfo.Short())

res, err := hal.Client.Do(req)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions labeler/micro_nsfw_img.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

lexutil "github.com/bluesky-social/indigo/lex/util"
util "github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/version"

"github.com/carlmjohnson/versioninfo"
)

type MicroNSFWImgLabeler struct {
Expand Down Expand Up @@ -75,7 +76,7 @@ func (mnil *MicroNSFWImgLabeler) LabelBlob(ctx context.Context, blob lexutil.Lex
return nil, err
}
req.Header.Add("Content-Type", writer.FormDataContentType())
req.Header.Set("User-Agent", "labelmaker/"+version.Version)
req.Header.Set("User-Agent", "labelmaker/"+versioninfo.Short())

res, err := mnil.Client.Do(req)
if err != nil {
Expand Down
5 changes: 3 additions & 2 deletions labeler/sqrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import (

appbsky "github.com/bluesky-social/indigo/api/bsky"
"github.com/bluesky-social/indigo/util"
"github.com/bluesky-social/indigo/util/version"

"github.com/carlmjohnson/versioninfo"
)

type SQRLLabeler struct {
Expand Down Expand Up @@ -66,7 +67,7 @@ func (sl *SQRLLabeler) submitEvent(sqlrReq SQRLRequest) (*SQRLResponse, error) {

req.Header.Add("Content-Type", "application/json")
req.Header.Set("Accept", "application/json")
req.Header.Set("User-Agent", "labelmaker/"+version.Version)
req.Header.Set("User-Agent", "labelmaker/"+versioninfo.Short())

res, err := sl.Client.Do(req)
if err != nil {
Expand Down
Loading

0 comments on commit b761d05

Please sign in to comment.