diff --git a/Dockerfile b/Dockerfile index d8d3a18..0700431 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,8 @@ FROM golang:1.24-bullseye AS builder ENV CGO_ENABLED=1 ENV GOOS=linux # Changed from Apple Silicon arm64 config. -ENV GOARCH=amd64 +# ENV GOARCH=amd64 +ENV GOARCH=arm64 WORKDIR /app diff --git a/docker-compose.local.yml b/docker-compose.local.yml index 5c32137..b88f1ee 100644 --- a/docker-compose.local.yml +++ b/docker-compose.local.yml @@ -1,49 +1,72 @@ -# docker-compose.local.yml -# -# Use this file to run local services (API, Nginx, etc.) while -# connecting to a REMOTE database. -# -# This version includes the 'db-init' service. Note that this service -# will attempt to run its 'import-data' command every time you execute -# 'docker-compose up'. +version: '3.8' services: - # This service runs the 'import-data' command against the remote database - # specified in your '.env.local' file. It has no 'depends_on' since there - # is no local postgres container to wait for. + # NEW: Add a dedicated PostgreSQL database service + postgres: + image: postgres:15-alpine + environment: + POSTGRES_USER: ${DB_USER} + POSTGRES_PASSWORD: ${DB_PASSWORD} + POSTGRES_DB: ${DB_NAME} + ports: + - '${DB_PORT}:5432' # Expose DB port to host machine for local tools + volumes: + - postgres_data:/var/lib/postgresql/data # Persist data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ${DB_USER} -d ${DB_NAME}"] + interval: 10s + timeout: 5s + retries: 5 + networks: + - api.network + + # MODIFIED: This service now runs migrations and imports against the live Postgres DB + # "import-data" on initial run to migrate and import data. db-init: build: . - env_file: .env.local - command: ["/nba_go", "import-data"] + env_file: .env + command: ["/nba_go"] + depends_on: + postgres: + condition: service_healthy networks: - api.network restart: "no" - # API services now have no 'depends_on' section. - # They will start and immediately try to connect to the DB_HOST in your .env file. + # MODIFIED: All API services now depend on postgres being healthy. + # The volume mount for './data' is no longer needed. api1: build: . - env_file: .env.local + env_file: .env ports: - '5001:5000' + depends_on: + postgres: + condition: service_healthy networks: - api.network restart: always api2: build: . - env_file: .env.local + env_file: .env ports: - '5002:5000' + depends_on: + postgres: + condition: service_healthy networks: - api.network restart: always api3: build: . - env_file: .env.local + env_file: .env ports: - '5003:5000' + depends_on: + postgres: + condition: service_healthy networks: - api.network restart: always @@ -57,7 +80,7 @@ services: - api2 - api3 ports: - - '8080:8080' + - '8081:8080' networks: - api.network @@ -93,7 +116,7 @@ services: restart: unless-stopped volumes: - # The 'postgres_data' volume is not needed in this configuration. + postgres_data: # New volume for Postgres prometheus_data: grafana_data: diff --git a/docs/docs.go b/docs/docs.go index 2992c7b..22f31b5 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -477,7 +477,7 @@ var SwaggerInfo = &swag.Spec{ Version: "1.0", Host: "", BasePath: "/", - Schemes: []string{"https"}, + Schemes: []string{"http"}, Title: "NBA_Go API", Description: "Stats service, now with public access!", InfoInstanceName: "swagger", diff --git a/docs/swagger.json b/docs/swagger.json index 6ee7f8c..7555ca2 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1,6 +1,6 @@ { "schemes": [ - "https" + "http" ], "swagger": "2.0", "info": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 8988b31..21705c3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -303,7 +303,7 @@ paths: - PlayerTotals x-order: 1 schemes: -- https +- http swagger: "2.0" tags: - name: PlayerTotals diff --git a/import.go b/import.go index d994189..91ca099 100644 --- a/import.go +++ b/import.go @@ -11,7 +11,7 @@ import ( // importPlayerAdvanced fetches and stores advanced stats for seasons 2017–2025 func importPlayerAdvanced(db *gorm.DB) { - for season := 1991; season <= 2002; season++ { + for season := 2024; season <= 2025; season++ { if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, false); err != nil { log.Printf("advanced import failed for %d: %v", season, err) } @@ -23,7 +23,7 @@ func importPlayerAdvanced(db *gorm.DB) { // importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons 2023–2025 func importPlayerAdvancedPlayoffs(db *gorm.DB) { - for season := 1991; season <= 2002; season++ { + for season := 2024; season <= 2025; season++ { if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, true); err != nil { log.Printf("advanced import failed for %d: %v", season, err) } @@ -35,7 +35,7 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) { // importPlayerTotalsScrape fetches & stores scraped regular-season total stats func importPlayerTotalsScrape(db *gorm.DB) { - for season := 1991; season <= 2002; season++ { + for season := 2024; season <= 2025; season++ { if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil { log.Printf("scraped totals import failed for %d: %v", season, err) } @@ -47,7 +47,7 @@ func importPlayerTotalsScrape(db *gorm.DB) { // importPlayerPlayoffsScrape fetches & stores scraped playoff total stats func importPlayerTotalsPlayoffsScrape(db *gorm.DB) { - for season := 1991; season <= 2002; season++ { + for season := 2024; season <= 2025; season++ { if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil { log.Printf("scraped playoffs import failed for %d: %v", season, err) } diff --git a/main.go b/main.go index ef24fab..49672bf 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,8 @@ // @title NBA_Go API // @version 1.0 // @description Stats service, now with public access! -// @schemes https +// //@schemes https +// @schemes http // @BasePath / // // @tag.name PlayerTotals @@ -45,7 +46,7 @@ import ( func main() { // ——— One-off import-data mode ——— if len(os.Args) > 1 && os.Args[1] == "import-data" { - // Run all migrations + import steps exactly once + // Run all DB migrations + import steps exactly once db := config.InitDB(true) importPlayerAdvanced(db)