dev mode returned local

This commit is contained in:
Ravi Prasad
2025-07-03 21:09:09 -05:00
parent 31dfe054b5
commit fbae36e06e
7 changed files with 55 additions and 30 deletions
+2 -1
View File
@@ -4,7 +4,8 @@ FROM golang:1.24-bullseye AS builder
ENV CGO_ENABLED=1 ENV CGO_ENABLED=1
ENV GOOS=linux ENV GOOS=linux
# Changed from Apple Silicon arm64 config. # Changed from Apple Silicon arm64 config.
ENV GOARCH=amd64 # ENV GOARCH=amd64
ENV GOARCH=arm64
WORKDIR /app WORKDIR /app
+43 -20
View File
@@ -1,49 +1,72 @@
# docker-compose.local.yml version: '3.8'
#
# 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'.
services: services:
# This service runs the 'import-data' command against the remote database # NEW: Add a dedicated PostgreSQL database service
# specified in your '.env.local' file. It has no 'depends_on' since there postgres:
# is no local postgres container to wait for. 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: db-init:
build: . build: .
env_file: .env.local env_file: .env
command: ["/nba_go", "import-data"] command: ["/nba_go"]
depends_on:
postgres:
condition: service_healthy
networks: networks:
- api.network - api.network
restart: "no" restart: "no"
# API services now have no 'depends_on' section. # MODIFIED: All API services now depend on postgres being healthy.
# They will start and immediately try to connect to the DB_HOST in your .env file. # The volume mount for './data' is no longer needed.
api1: api1:
build: . build: .
env_file: .env.local env_file: .env
ports: ports:
- '5001:5000' - '5001:5000'
depends_on:
postgres:
condition: service_healthy
networks: networks:
- api.network - api.network
restart: always restart: always
api2: api2:
build: . build: .
env_file: .env.local env_file: .env
ports: ports:
- '5002:5000' - '5002:5000'
depends_on:
postgres:
condition: service_healthy
networks: networks:
- api.network - api.network
restart: always restart: always
api3: api3:
build: . build: .
env_file: .env.local env_file: .env
ports: ports:
- '5003:5000' - '5003:5000'
depends_on:
postgres:
condition: service_healthy
networks: networks:
- api.network - api.network
restart: always restart: always
@@ -57,7 +80,7 @@ services:
- api2 - api2
- api3 - api3
ports: ports:
- '8080:8080' - '8081:8080'
networks: networks:
- api.network - api.network
@@ -93,7 +116,7 @@ services:
restart: unless-stopped restart: unless-stopped
volumes: volumes:
# The 'postgres_data' volume is not needed in this configuration. postgres_data: # New volume for Postgres
prometheus_data: prometheus_data:
grafana_data: grafana_data:
+1 -1
View File
@@ -477,7 +477,7 @@ var SwaggerInfo = &swag.Spec{
Version: "1.0", Version: "1.0",
Host: "", Host: "",
BasePath: "/", BasePath: "/",
Schemes: []string{"https"}, Schemes: []string{"http"},
Title: "NBA_Go API", Title: "NBA_Go API",
Description: "Stats service, now with public access!", Description: "Stats service, now with public access!",
InfoInstanceName: "swagger", InfoInstanceName: "swagger",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"schemes": [ "schemes": [
"https" "http"
], ],
"swagger": "2.0", "swagger": "2.0",
"info": { "info": {
+1 -1
View File
@@ -303,7 +303,7 @@ paths:
- PlayerTotals - PlayerTotals
x-order: 1 x-order: 1
schemes: schemes:
- https - http
swagger: "2.0" swagger: "2.0"
tags: tags:
- name: PlayerTotals - name: PlayerTotals
+4 -4
View File
@@ -11,7 +11,7 @@ import (
// importPlayerAdvanced fetches and stores advanced stats for seasons 20172025 // importPlayerAdvanced fetches and stores advanced stats for seasons 20172025
func importPlayerAdvanced(db *gorm.DB) { 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 { if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, false); err != nil {
log.Printf("advanced import failed for %d: %v", season, err) 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 20232025 // importPlayerAdvancedPlayoffs fetches and stores advanced stats for playoffs seasons 20232025
func importPlayerAdvancedPlayoffs(db *gorm.DB) { 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 { if err := services.FetchAndStorePlayerAdvancedScrapedStats(db, season, true); err != nil {
log.Printf("advanced import failed for %d: %v", season, err) 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 // importPlayerTotalsScrape fetches & stores scraped regular-season total stats
func importPlayerTotalsScrape(db *gorm.DB) { 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 { if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, false); err != nil {
log.Printf("scraped totals import failed for %d: %v", season, err) 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 // importPlayerPlayoffsScrape fetches & stores scraped playoff total stats
func importPlayerTotalsPlayoffsScrape(db *gorm.DB) { 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 { if err := services.FetchAndStorePlayerTotalScrapedStats(db, season, true); err != nil {
log.Printf("scraped playoffs import failed for %d: %v", season, err) log.Printf("scraped playoffs import failed for %d: %v", season, err)
} }
+3 -2
View File
@@ -1,7 +1,8 @@
// @title NBA_Go API // @title NBA_Go API
// @version 1.0 // @version 1.0
// @description Stats service, now with public access! // @description Stats service, now with public access!
// @schemes https // //@schemes https
// @schemes http
// @BasePath / // @BasePath /
// //
// @tag.name PlayerTotals // @tag.name PlayerTotals
@@ -45,7 +46,7 @@ import (
func main() { func main() {
// ——— One-off import-data mode ——— // ——— One-off import-data mode ———
if len(os.Args) > 1 && os.Args[1] == "import-data" { 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) db := config.InitDB(true)
importPlayerAdvanced(db) importPlayerAdvanced(db)