Fly again
This commit is contained in:
parent
75394c98a1
commit
f77103334a
4 changed files with 7 additions and 60 deletions
|
@ -12,11 +12,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "3002:3000"
|
- "3002:3000"
|
||||||
environment:
|
environment:
|
||||||
- POSTGRES_HOST=db
|
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/pollo
|
||||||
- POSTGRES_PORT=5432
|
|
||||||
- POSTGRES_DB=pollo
|
|
||||||
- POSTGRES_USER=${POSTGRES_USER}
|
|
||||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
|
||||||
- AUTH_SECRET=${AUTH_SECRET}
|
- AUTH_SECRET=${AUTH_SECRET}
|
||||||
- ENCRYPTION_KEY=${ENCRYPTION_KEY}
|
- ENCRYPTION_KEY=${ENCRYPTION_KEY}
|
||||||
- DEVMODE=${DEVMODE}
|
- DEVMODE=${DEVMODE}
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
services:
|
|
||||||
app:
|
|
||||||
image: ghcr.io/atridadl/pollo:latest
|
|
||||||
command: ["/app"]
|
|
||||||
depends_on:
|
|
||||||
db:
|
|
||||||
condition: service_healthy
|
|
||||||
ports:
|
|
||||||
- "3002:3000"
|
|
||||||
environment:
|
|
||||||
- POSTGRES_HOST=db
|
|
||||||
- POSTGRES_PORT=5432
|
|
||||||
- POSTGRES_DB=pollo
|
|
||||||
- POSTGRES_USER=${POSTGRES_USER}
|
|
||||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
|
||||||
- AUTH_SECRET=${AUTH_SECRET}
|
|
||||||
- ENCRYPTION_KEY=${ENCRYPTION_KEY}
|
|
||||||
- DEVMODE=${DEVMODE}
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: "postgres:16-alpine"
|
|
||||||
environment:
|
|
||||||
- POSTGRES_DB=pollo
|
|
||||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
|
||||||
- POSTGRES_USER=${POSTGRES_USER}
|
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
volumes:
|
|
||||||
- pgdata:/var/lib/postgresql/data
|
|
||||||
restart: on-failure:3
|
|
||||||
healthcheck:
|
|
||||||
test: ["CMD", "sh", "-c", "pg_isready -h db -p 5432 -U ${POSTGRES_USER}"]
|
|
||||||
interval: 10s
|
|
||||||
timeout: 5s
|
|
||||||
retries: 10
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
pgdata:
|
|
|
@ -27,10 +27,9 @@ func GenerateNewID(prefix string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the global database connection pool.
|
// Initializes the global database connection pool.
|
||||||
func InitializeDBPool(host, user, password, dbname string, port int) error {
|
func InitializeDBPool(databaseURL string) error {
|
||||||
connString := fmt.Sprintf("postgres://%s:%s@%s:%d/%s", user, password, host, port, dbname)
|
|
||||||
var err error
|
var err error
|
||||||
dbPool, err = pgxpool.Connect(context.Background(), connString)
|
dbPool, err = pgxpool.Connect(context.Background(), databaseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
18
main.go
18
main.go
|
@ -7,7 +7,6 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"pollo/api"
|
"pollo/api"
|
||||||
"pollo/api/webhooks"
|
"pollo/api/webhooks"
|
||||||
|
@ -27,21 +26,12 @@ func main() {
|
||||||
godotenv.Load(".env")
|
godotenv.Load(".env")
|
||||||
|
|
||||||
// Initialize the database connection pool
|
// Initialize the database connection pool
|
||||||
postgresHost := os.Getenv("POSTGRES_HOST")
|
databaseURL := os.Getenv("DATABASE_URL")
|
||||||
postgresPort := os.Getenv("POSTGRES_PORT")
|
if databaseURL == "" {
|
||||||
postgresUser := os.Getenv("POSTGRES_USER")
|
log.Fatal("DATABASE_URL environment variable not set")
|
||||||
postgresPassword := os.Getenv("POSTGRES_PASSWORD")
|
|
||||||
postgresDB := os.Getenv("POSTGRES_DB")
|
|
||||||
if postgresHost == "" || postgresPort == "" || postgresUser == "" || postgresPassword == "" || postgresDB == "" {
|
|
||||||
log.Fatal("DB environment variables not set")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
portNumber, err := strconv.Atoi(postgresPort)
|
if err := lib.InitializeDBPool(databaseURL); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Invalid database port: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := lib.InitializeDBPool(postgresHost, postgresUser, postgresPassword, postgresDB, portNumber); err != nil {
|
|
||||||
log.Fatalf("Failed to initialize DB pool: %v", err)
|
log.Fatalf("Failed to initialize DB pool: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue