Skip to content

Commit

Permalink
feat: deployment preparations
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettladley committed Nov 27, 2024
1 parent 473aba8 commit 96696ed
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 17 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
5 changes: 0 additions & 5 deletions cmd/seed/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/settings/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 3 additions & 2 deletions internal/storage/postgres/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down

0 comments on commit 96696ed

Please sign in to comment.