This commit is contained in:
@@ -25,9 +25,9 @@ jobs:
|
||||
|
||||
- name: Build and push postgres image
|
||||
uses: docker/build-push-action@v5
|
||||
if: |
|
||||
contains(github.event.commits[0].modified, 'infra/postgres-pg-cron') ||
|
||||
contains(github.event.commits[0].added, 'infra/postgres-pg-cron')
|
||||
# if: |
|
||||
# contains(github.event.commits[0].modified, 'infra/postgres') ||
|
||||
# contains(github.event.commits[0].added, 'infra/postgres')
|
||||
with:
|
||||
context: .
|
||||
file: infra/postgres/Dockerfile
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
DROP EXTENSION pg_cron;
|
||||
@@ -2,6 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@@ -33,7 +34,6 @@ func Load() (Config, error) {
|
||||
mode := os.Getenv("RUN_MODE")
|
||||
debugMode := os.Getenv("DEBUG_MODE") == "true"
|
||||
botToken := os.Getenv("BOT_TOKEN")
|
||||
dbConnectionString := os.Getenv("DB_PATH")
|
||||
ocrTokenPath := os.Getenv("GOOGLE_APPLICATION_CREDENTIALS")
|
||||
apiPort := os.Getenv("API_PORT")
|
||||
apiHost := os.Getenv("API_HOST")
|
||||
@@ -42,6 +42,7 @@ func Load() (Config, error) {
|
||||
openAPIEndpoint := os.Getenv("OPEN_API_ENDPOINT")
|
||||
|
||||
runMode, err := ParseRunMode(mode)
|
||||
dbConnectionString := buildConnectionString()
|
||||
if err != nil {
|
||||
warnings = append(warnings, err.Error())
|
||||
}
|
||||
@@ -61,9 +62,6 @@ func Load() (Config, error) {
|
||||
if apiSecret == "" {
|
||||
warnings = append(warnings, "Missing required environment variable: API_SECRET")
|
||||
}
|
||||
if dbConnectionString == "" {
|
||||
dbConnectionString = "sqlite://data/app.db"
|
||||
}
|
||||
if apiHost == "" {
|
||||
apiHost = "localhost"
|
||||
}
|
||||
@@ -92,3 +90,30 @@ func Load() (Config, error) {
|
||||
TelegramApi: "https://api.telegram.org",
|
||||
}, nil
|
||||
}
|
||||
|
||||
func buildConnectionString() string {
|
||||
// если задана готовая строка — используем её (удобно для локальной разработки через .env)
|
||||
if dsn := os.Getenv("DB_PATH"); dsn != "" {
|
||||
return dsn
|
||||
}
|
||||
|
||||
// собираем из отдельных переменных (для Kubernetes)
|
||||
host := os.Getenv("DB_HOST")
|
||||
port := os.Getenv("DB_PORT")
|
||||
user := os.Getenv("DB_USER")
|
||||
password := os.Getenv("DB_PASSWORD")
|
||||
dbName := os.Getenv("DB_NAME")
|
||||
|
||||
if host == "" || user == "" || password == "" || dbName == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
if port == "" {
|
||||
port = "5432"
|
||||
}
|
||||
|
||||
return fmt.Sprintf(
|
||||
"postgres://%s:%s@%s:%s/%s?sslmode=disable",
|
||||
user, password, host, port, dbName,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ metadata:
|
||||
namespace: family-hub
|
||||
data:
|
||||
DB_HOST: postgres
|
||||
DB_PORT: "6432"
|
||||
DB_PORT: "5432"
|
||||
DB_NAME: familyHubDB
|
||||
DB_USER: familyUser
|
||||
API_PORT: "8000"
|
||||
|
||||
Reference in New Issue
Block a user