Skip to content

Commit 38b0674

Browse files
committed
migrator, package atlas in dockerfile, fallback, set CGO in dockerfile, fix memory system id
1 parent 65b1016 commit 38b0674

File tree

27 files changed

+2646
-73
lines changed

27 files changed

+2646
-73
lines changed

taco/Dockerfile_statesman

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ COPY internal/ ./internal/
1111
COPY pkg/sdk/ ./pkg/sdk/
1212

1313
# Download dependencies and build
14+
# Note: CGO is required for SQLite support
1415
RUN cd cmd/statesman && \
1516
go mod tidy && \
16-
CGO_ENABLED=0 GOOS=linux go build \
17+
CGO_ENABLED=1 GOOS=linux go build \
1718
-ldflags="-X 'main.Version=${COMMIT_SHA}' -s -w" \
18-
-a -installsuffix cgo \
19+
-a \
1920
-o statesman .
2021

22+
# Install Atlas CLI for migrations
23+
RUN go install ariga.io/atlas/cmd/atlas@latest
24+
2125
# Multi-stage build - use a minimal image for runtime
2226
FROM ubuntu:24.04 AS runner
2327
ARG COMMIT_SHA
@@ -31,6 +35,9 @@ RUN apt-get update && \
3135

3236
RUN echo "commit sha: ${COMMIT_SHA}"
3337

38+
# Copy Atlas CLI from builder
39+
COPY --from=builder /go/bin/atlas /usr/local/bin/atlas
40+
3441
# Copy the binary from builder stage
3542
COPY --from=builder /go/src/github.com/diggerhq/digger/taco/cmd/statesman/statesman /app/statesman
3643

taco/Makefile

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,52 @@ docker-clean: ## Clean Docker images and containers
8686
docker rmi statesman:latest 2>/dev/null || true
8787

8888
help: ## Show this help
89-
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
89+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
90+
91+
# ============================================================================
92+
# Atlas Migration Targets
93+
# ============================================================================
94+
95+
# Migration name variable (use with: make atlas-diff-all name=add_new_feature)
96+
NAME ?= $(shell date +%Y%m%d%H%M%S)
97+
98+
.PHONY: atlas-install atlas-diff-all atlas-apply-all atlas-lint-all atlas-hash-all
99+
100+
# Install Atlas CLI and GORM provider
101+
atlas-install: ## Install Atlas CLI and GORM provider
102+
@echo "Installing Atlas CLI and GORM provider..."
103+
@go install ariga.io/atlas/cmd/atlas@latest
104+
@go install ariga.io/atlas-provider-gorm@latest
105+
@echo "✅ Atlas tools installed successfully"
106+
107+
# Generate migrations for all database dialects
108+
atlas-diff-all: ## Generate migrations for all databases (use: make atlas-diff-all name=my_change)
109+
@echo "Generating migrations for all databases..."
110+
@if [ -z "$(filter-out $(NAME),$(shell date +%Y%m%d%H%M%S))" ]; then \
111+
echo "⚠️ Using auto-generated name: $(NAME)"; \
112+
echo "💡 Tip: Use 'make atlas-diff-all name=descriptive_name' for better naming"; \
113+
fi
114+
@mkdir -p migrations/postgres migrations/mysql migrations/sqlite migrations/sqlserver
115+
@echo "\n📊 PostgreSQL..." && atlas migrate diff $(NAME) --env postgres
116+
@echo "\n📊 MySQL..." && atlas migrate diff $(NAME) --env mysql
117+
@echo "\n📊 SQLite..." && atlas migrate diff $(NAME) --env sqlite
118+
@echo "\n📊 SQL Server..." && atlas migrate diff $(NAME) --env sqlserver
119+
@$(MAKE) atlas-hash-all
120+
@echo "\n✅ All migrations generated successfully!"
121+
122+
123+
# Validate and lint all migrations
124+
atlas-lint-all: ## Validate and lint all migration files
125+
@echo "Validating and linting migrations..."
126+
@echo "PostgreSQL..." && atlas migrate validate --env postgres
127+
@echo "MySQL..." && atlas migrate validate --env mysql
128+
@echo "SQLite..." && atlas migrate validate --env sqlite
129+
@echo "SQL Server..." && atlas migrate validate --env sqlserver
130+
@echo "✅ All migrations validated successfully"
131+
132+
# Update migration directory hashes (called automatically by atlas-diff-all)
133+
atlas-hash-all:
134+
@atlas migrate hash --dir file://migrations/postgres 2>/dev/null || true
135+
@atlas migrate hash --dir file://migrations/mysql 2>/dev/null || true
136+
@atlas migrate hash --dir file://migrations/sqlite 2>/dev/null || true
137+
@atlas migrate hash --dir file://migrations/sqlserver 2>/dev/null || true

taco/atlas.hcl

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# SQLite configuration
2+
data "external_schema" "gorm_sqlite" {
3+
program = [
4+
"sh",
5+
"-c",
6+
"cd internal && go run ./atlas_loader.go",
7+
]
8+
}
9+
10+
env "sqlite" {
11+
src = data.external_schema.gorm_sqlite.url
12+
dev = "sqlite://file?mode=memory"
13+
migration {
14+
dir = "file://internal/query/migration/atlas/migrations/sqlite"
15+
}
16+
format {
17+
migrate {
18+
diff = "{{ sql . \" \" }}"
19+
}
20+
}
21+
}
22+
23+
# PostgreSQL configuration
24+
data "external_schema" "gorm_postgres" {
25+
program = [
26+
"atlas-provider-gorm",
27+
"load",
28+
"--path", "./internal/query/types",
29+
"--dialect", "postgres",
30+
]
31+
}
32+
33+
env "postgres" {
34+
src = data.external_schema.gorm_postgres.url
35+
dev = "docker://postgres/16.1"
36+
migration {
37+
dir = "file://internal/query/migration/atlas/migrations/postgres"
38+
}
39+
format {
40+
migrate {
41+
diff = "{{ sql . \" \" }}"
42+
}
43+
}
44+
}
45+
46+
# MySQL configuration
47+
data "external_schema" "gorm_mysql" {
48+
program = [
49+
"atlas-provider-gorm",
50+
"load",
51+
"--path", "./internal/query/types",
52+
"--dialect", "mysql",
53+
]
54+
}
55+
56+
env "mysql" {
57+
src = data.external_schema.gorm_mysql.url
58+
dev = "docker://mysql/8"
59+
migration {
60+
dir = "file://internal/query/migration/atlas/migrations/mysql"
61+
}
62+
format {
63+
migrate {
64+
diff = "{{ sql . \" \" }}"
65+
}
66+
}
67+
}
68+
69+
# SQL Server configuration
70+
data "external_schema" "gorm_sqlserver" {
71+
program = [
72+
"atlas-provider-gorm",
73+
"load",
74+
"--path", "./internal/query/types",
75+
"--dialect", "sqlserver",
76+
]
77+
}
78+
79+
env "sqlserver" {
80+
src = data.external_schema.gorm_sqlserver.url
81+
dev = "docker://sqlserver/2022-latest"
82+
migration {
83+
dir = "file://internal/query/migration/atlas/migrations/sqlserver"
84+
}
85+
format {
86+
migrate {
87+
diff = "{{ sql . \" \" }}"
88+
}
89+
}
90+
}

taco/atlas_loader.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"io"
7+
"os"
8+
9+
"ariga.io/atlas-provider-gorm/gormschema"
10+
"github.com/diggerhq/digger/opentaco/internal/query/types"
11+
)
12+
13+
func main() {
14+
stmts, err := gormschema.New("sqlite").Load(types.DefaultModels...)
15+
if err != nil {
16+
os.Stderr.WriteString(err.Error())
17+
os.Exit(1)
18+
}
19+
io.WriteString(os.Stdout, stmts)
20+
}
21+

taco/cmd/statesman/go.mod

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/diggerhq/digger/opentaco/cmd/statesman
22

3-
go 1.24
3+
go 1.24.6
44

55
require (
66
github.com/diggerhq/digger/opentaco/internal v0.0.0
@@ -9,8 +9,12 @@ require (
99
)
1010

1111
require (
12+
ariga.io/atlas v0.37.0 // indirect
13+
ariga.io/atlas-go-sdk v0.7.2 // indirect
1214
filippo.io/edwards25519 v1.1.0 // indirect
1315
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
16+
github.com/agext/levenshtein v1.2.3 // indirect
17+
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
1418
github.com/aws/aws-sdk-go-v2 v1.38.1 // indirect
1519
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.0 // indirect
1620
github.com/aws/aws-sdk-go-v2/config v1.31.2 // indirect
@@ -29,15 +33,19 @@ require (
2933
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.33.2 // indirect
3034
github.com/aws/aws-sdk-go-v2/service/sts v1.38.0 // indirect
3135
github.com/aws/smithy-go v1.22.5 // indirect
36+
github.com/bmatcuk/doublestar v1.3.4 // indirect
3237
github.com/coreos/go-oidc/v3 v3.11.0 // indirect
33-
github.com/go-jose/go-jose/v4 v4.0.2 // indirect
38+
github.com/go-jose/go-jose/v4 v4.1.2 // indirect
39+
github.com/go-openapi/inflect v0.19.0 // indirect
3440
github.com/go-sql-driver/mysql v1.8.1 // indirect
3541
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
3642
github.com/golang-jwt/jwt/v5 v5.3.0 // indirect
3743
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
3844
github.com/golang-sql/sqlexp v0.1.0 // indirect
45+
github.com/google/go-cmp v0.7.0 // indirect
3946
github.com/google/jsonapi v1.0.0 // indirect
4047
github.com/google/uuid v1.6.0 // indirect
48+
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
4149
github.com/jackc/pgpassfile v1.0.0 // indirect
4250
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
4351
github.com/jackc/pgx/v5 v5.6.0 // indirect
@@ -47,18 +55,22 @@ require (
4755
github.com/labstack/gommon v0.4.2 // indirect
4856
github.com/mattn/go-colorable v0.1.13 // indirect
4957
github.com/mattn/go-isatty v0.0.20 // indirect
50-
github.com/mattn/go-sqlite3 v1.14.22 // indirect
58+
github.com/mattn/go-sqlite3 v1.14.28 // indirect
5159
github.com/microsoft/go-mssqldb v1.8.2 // indirect
60+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
5261
github.com/mr-tron/base58 v1.2.0 // indirect
5362
github.com/valyala/bytebufferpool v1.0.0 // indirect
5463
github.com/valyala/fasttemplate v1.2.2 // indirect
55-
golang.org/x/crypto v0.32.0 // indirect
56-
golang.org/x/net v0.34.0 // indirect
57-
golang.org/x/oauth2 v0.24.0 // indirect
58-
golang.org/x/sync v0.10.0 // indirect
59-
golang.org/x/sys v0.29.0 // indirect
60-
golang.org/x/text v0.21.0 // indirect
61-
golang.org/x/time v0.7.0 // indirect
64+
github.com/zclconf/go-cty v1.14.4 // indirect
65+
github.com/zclconf/go-cty-yaml v1.1.0 // indirect
66+
golang.org/x/crypto v0.41.0 // indirect
67+
golang.org/x/net v0.43.0 // indirect
68+
golang.org/x/oauth2 v0.30.0 // indirect
69+
golang.org/x/sync v0.16.0 // indirect
70+
golang.org/x/sys v0.35.0 // indirect
71+
golang.org/x/text v0.28.0 // indirect
72+
golang.org/x/time v0.12.0 // indirect
73+
gopkg.in/yaml.v3 v3.0.1 // indirect
6274
gorm.io/driver/mysql v1.6.0 // indirect
6375
gorm.io/driver/postgres v1.6.0 // indirect
6476
gorm.io/driver/sqlite v1.6.0 // indirect

0 commit comments

Comments
 (0)