diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c3d561d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM golang:1.23-alpine as builder + +WORKDIR /app +RUN apk add --no-cache make nodejs npm git + +COPY . ./ +RUN make install +RUN make build-prod + +FROM scratch +COPY --from=builder /app/bin/roundest /roundest +COPY --from=builder /app/config/ /config/ + +ENTRYPOINT [ "./roundest" ] diff --git a/cmd/seed/main.go b/cmd/seed/main.go index f1765f8..fea093e 100644 --- a/cmd/seed/main.go +++ b/cmd/seed/main.go @@ -8,14 +8,9 @@ import ( "github.com/garrettladley/roundest/internal/services/pokeapi" "github.com/garrettladley/roundest/internal/settings" "github.com/garrettladley/roundest/internal/storage/postgres" - "github.com/joho/godotenv" ) func main() { - if err := godotenv.Load(".env"); err != nil { - log.Fatalf("Failed to load .env file: %v", err) - } - settings, err := settings.Load() if err != nil { log.Fatalf("Failed to load settings: %v", err) diff --git a/cmd/server/main.go b/cmd/server/main.go index 8208faa..b77adae 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -13,14 +13,9 @@ import ( "github.com/garrettladley/roundest/internal/settings" "github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2/middleware/filesystem" - "github.com/joho/godotenv" ) func main() { - if err := godotenv.Load(".env"); err != nil { - log.Fatalf("Failed to load .env file: %v", err) - } - settings, err := settings.Load() if err != nil { log.Fatalf("Failed to load settings: %v", err) diff --git a/go.mod b/go.mod index 2254736..7020a85 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,6 @@ require ( github.com/goccy/go-json v0.10.3 github.com/google/uuid v1.5.0 // indirect github.com/jmoiron/sqlx v1.4.0 - github.com/joho/godotenv v1.5.1 github.com/klauspost/compress v1.17.0 // indirect github.com/lib/pq v1.10.9 github.com/mattn/go-colorable v0.1.13 // indirect diff --git a/go.sum b/go.sum index 9da2232..9a9041b 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,6 @@ github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o= github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY= -github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= -github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM= github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= diff --git a/internal/server/server.go b/internal/server/server.go index a2b3e6b..ebe175a 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -33,7 +33,8 @@ func newApp(settings settings.Settings) *fiber.App { panic("internal/server: failed to create store: " + err.Error()) } - handlers.NewService(store).Routes(app) + roundest := app.Group("/roundest") + handlers.NewService(store).Routes(roundest) return app } diff --git a/internal/settings/database.go b/internal/settings/database.go index 74c9c81..68cfa49 100644 --- a/internal/settings/database.go +++ b/internal/settings/database.go @@ -3,7 +3,7 @@ package settings import "time" type Database struct { - DSN string `env:"URL" envDefault:"postgres://postgres:password@127.0.0.1:5432/roundest?sslmode=disable"` + DSN string `env:"DSN" envDefault:"postgres://postgres:password@127.0.0.1:5432/roundest?sslmode=disable"` MaxOpenConns uint `env:"MAX_OPEN_CONNS" envDefault:"25"` MaxIdleConns uint `env:"MAX_IDLE_CONNS" envDefault:"25"` ConnMaxLifetime time.Duration `env:"CONN_MAX_LIFETIME" envDefault:"5m"` diff --git a/internal/storage/postgres/schema.go b/internal/storage/postgres/schema.go index c99c94b..e524ed2 100644 --- a/internal/storage/postgres/schema.go +++ b/internal/storage/postgres/schema.go @@ -7,12 +7,13 @@ import ( func (db DB) Schema(ctx context.Context) error { const schema string = ` + DROP TABLE IF EXISTS pokemon; CREATE TABLE IF NOT EXISTS pokemon ( id BIGINT PRIMARY KEY, name VARCHAR(255) NOT NULL, dex_id INTEGER NOT NULL, - up_votes INTEGER DEFAULT 0, - down_votes INTEGER DEFAULT 0, + up_votes INTEGER NOT NULL DEFAULT 0, + down_votes INTEGER NOT NULL DEFAULT 0, inserted_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP );