Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ COPY --from=bun /app/public/style.css /app/public/style.css

RUN go install github.com/a-h/templ/cmd/templ@v0.2.680

ENV CGO_ENABLED=1

RUN templ generate

RUN go build \
Expand Down
2 changes: 2 additions & 0 deletions admin.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ RUN go install github.com/a-h/templ/cmd/templ@v0.2.680

RUN templ generate

ENV CGO_ENABLED=1

RUN go build \
-ldflags="-linkmode external -extldflags -static -X 'main.BUILDTIME=$(date --iso-8601=seconds --utc)'" \
-o admin \
Expand Down
2 changes: 2 additions & 0 deletions api.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ RUN go mod download

COPY . .

ENV CGO_ENABLED=1

RUN go build \
-ldflags="-linkmode external -extldflags -static -X 'main.BUILDTIME=$(date --iso-8601=seconds --utc)'" \
-o api \
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand All @@ -36,7 +37,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/klauspost/compress v1.15.15 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 // indirect
github.com/libsql/sqlite-antlr4-parser v0.0.0-20240327125255-dbf53b6cbf06 // indirect
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -47,6 +48,7 @@ require (
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tursodatabase/go-libsql v0.0.0-20240916111504-922dfa87e1e6 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ github.com/a-h/templ v0.2.778 h1:VzhOuvWECrwOec4790lcLlZpP4Iptt5Q4K9aFxQmtaM=
github.com/a-h/templ v0.2.778/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9 h1:goHVqTbFX3AIo0tzGr14pgfAW2ZfPChKO21Z9MGf/gk=
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9/go.mod h1:pSwJ0fSY5KhvocuWSx4fz3BA8OrA1bQn+K1Eli3BRwM=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -78,6 +80,8 @@ github.com/libsql/libsql-client-go v0.0.0-20231212112702-ff51beb13681 h1:61Mudd5
github.com/libsql/libsql-client-go v0.0.0-20231212112702-ff51beb13681/go.mod h1:T+1lRvREkstNW7bmF1PTiDhV6hji0mrlfZkZuk/UPhw=
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475 h1:6PfEMwfInASh9hkN83aR0j4W/eKaAZt/AURtXAXlas0=
github.com/libsql/sqlite-antlr4-parser v0.0.0-20230802215326-5cb5bb604475/go.mod h1:20nXSmcf0nAscrzqsXeC2/tA3KkV2eCiJqYuyAgl+ss=
github.com/libsql/sqlite-antlr4-parser v0.0.0-20240327125255-dbf53b6cbf06 h1:JLvn7D+wXjH9g4Jsjo+VqmzTUpl/LX7vfr6VOfSWTdM=
github.com/libsql/sqlite-antlr4-parser v0.0.0-20240327125255-dbf53b6cbf06/go.mod h1:FUkZ5OHjlGPjnM2UyGJz9TypXQFgYqw6AFNO1UiROTM=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683 h1:7UMa6KCCMjZEMDtTVdcGu0B1GmmC7QJKiCCjyTAWQy0=
github.com/lufia/plan9stats v0.0.0-20240909124753-873cd0166683/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
Expand Down Expand Up @@ -114,6 +118,8 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
github.com/tursodatabase/go-libsql v0.0.0-20240916111504-922dfa87e1e6 h1:bFxO2fsY5mHZRrVvhmrAo/O8Agi9HDAIMmmOClZMrkQ=
github.com/tursodatabase/go-libsql v0.0.0-20240916111504-922dfa87e1e6/go.mod h1:TjsB2miB8RW2Sse8sdxzVTdeGlx74GloD5zJYUC38d8=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
Expand Down
2 changes: 1 addition & 1 deletion internal/data/event_slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

_ "modernc.org/sqlite"

_ "github.com/libsql/libsql-client-go/libsql"
_ "github.com/tursodatabase/go-libsql"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion internal/data/null_rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

_ "modernc.org/sqlite"

_ "github.com/libsql/libsql-client-go/libsql"
_ "github.com/tursodatabase/go-libsql"
)

type NullRows struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/data/quality_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

_ "modernc.org/sqlite"

_ "github.com/libsql/libsql-client-go/libsql"
_ "github.com/tursodatabase/go-libsql"
)

type AverageMRSizeByWeek struct {
Expand Down
3 changes: 1 addition & 2 deletions internal/data/teams.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

_ "modernc.org/sqlite"

_ "github.com/libsql/libsql-client-go/libsql"
_ "github.com/tursodatabase/go-libsql"
)

type Team struct {
Expand All @@ -16,7 +16,6 @@ type Team struct {

type TeamSlice []Team


func (s *Store) GetTeams() (TeamSlice, error) {
db, err := sql.Open(s.DriverName, s.DbUrl)

Expand Down
56 changes: 52 additions & 4 deletions internal/handler/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ package api
import (
"context"
"database/sql"
"fmt"
"net/http"
"os"
"path/filepath"
"strconv"
"sync"
"time"

"github.com/dxta-dev/app/internal/data"
"github.com/dxta-dev/app/internal/otel"
"github.com/labstack/echo/v4"

"github.com/tursodatabase/go-libsql"
)

type APIState struct {
Expand All @@ -24,6 +29,39 @@ var reposDBCache sync.Map

var dbPool sync.Map

func getDirPath() (string, error) {
dir := filepath.Join(os.TempDir(), "libsql-dir")
err := os.MkdirAll(dir, os.ModePerm)

if err != nil {
return "", err
}

return dir, nil

}

func getEmbeddedDB(dbUrl, org, repo string) (*libsql.Connector, error) {
dirPath, err := getDirPath()

if err != nil {
return nil, err
}

connector, err := libsql.NewEmbeddedReplicaConnector(
filepath.Join(dirPath, org+"_"+repo),
dbUrl,
libsql.WithAuthToken(os.Getenv("DXTA_DEV_GROUP_TOKEN")),
libsql.WithSyncInterval(time.Minute*5),
)
if err != nil {
return nil, err
}

return connector, nil

}

func getDB(ctx context.Context, org, repo string) (*sql.DB, error) {
cacheKey := org + "/" + repo

Expand All @@ -36,13 +74,23 @@ func getDB(ctx context.Context, org, repo string) (*sql.DB, error) {
return nil, err
}

driverName := otel.GetDriverName()
connector, err := getEmbeddedDB(dbUrl, org, repo)

fullDbUrl := dbUrl + "?authToken=" + os.Getenv("DXTA_DEV_GROUP_TOKEN")
var db *sql.DB

db, err := sql.Open(driverName, fullDbUrl)
if err != nil {
return nil, err
fmt.Println("Using normal db")
driverName := otel.GetDriverName()

fullDbUrl := dbUrl + "?authToken=" + os.Getenv("DXTA_DEV_GROUP_TOKEN")

db, err = sql.Open(driverName, fullDbUrl)
if err != nil {
return nil, err
}
} else {
fmt.Println("Using embedded db")
db = sql.OpenDB(connector)
}

if err := db.PingContext(ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

"github.com/donseba/go-htmx"
"github.com/labstack/echo/v4"
_ "github.com/libsql/libsql-client-go/libsql"
_ "github.com/tursodatabase/go-libsql"
"github.com/wcharczuk/go-chart/v2/drawing"
)

Expand Down