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:
|
||||
- "3002:3000"
|
||||
environment:
|
||||
- POSTGRES_HOST=db
|
||||
- POSTGRES_PORT=5432
|
||||
- POSTGRES_DB=pollo
|
||||
- POSTGRES_USER=${POSTGRES_USER}
|
||||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/pollo
|
||||
- AUTH_SECRET=${AUTH_SECRET}
|
||||
- ENCRYPTION_KEY=${ENCRYPTION_KEY}
|
||||
- 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.
|
||||
func InitializeDBPool(host, user, password, dbname string, port int) error {
|
||||
connString := fmt.Sprintf("postgres://%s:%s@%s:%d/%s", user, password, host, port, dbname)
|
||||
func InitializeDBPool(databaseURL string) error {
|
||||
var err error
|
||||
dbPool, err = pgxpool.Connect(context.Background(), connString)
|
||||
dbPool, err = pgxpool.Connect(context.Background(), databaseURL)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
18
main.go
18
main.go
|
@ -7,7 +7,6 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"pollo/api"
|
||||
"pollo/api/webhooks"
|
||||
|
@ -27,21 +26,12 @@ func main() {
|
|||
godotenv.Load(".env")
|
||||
|
||||
// Initialize the database connection pool
|
||||
postgresHost := os.Getenv("POSTGRES_HOST")
|
||||
postgresPort := os.Getenv("POSTGRES_PORT")
|
||||
postgresUser := os.Getenv("POSTGRES_USER")
|
||||
postgresPassword := os.Getenv("POSTGRES_PASSWORD")
|
||||
postgresDB := os.Getenv("POSTGRES_DB")
|
||||
if postgresHost == "" || postgresPort == "" || postgresUser == "" || postgresPassword == "" || postgresDB == "" {
|
||||
log.Fatal("DB environment variables not set")
|
||||
databaseURL := os.Getenv("DATABASE_URL")
|
||||
if databaseURL == "" {
|
||||
log.Fatal("DATABASE_URL environment variable not set")
|
||||
}
|
||||
|
||||
portNumber, err := strconv.Atoi(postgresPort)
|
||||
if err != nil {
|
||||
log.Fatalf("Invalid database port: %v", err)
|
||||
}
|
||||
|
||||
if err := lib.InitializeDBPool(postgresHost, postgresUser, postgresPassword, postgresDB, portNumber); err != nil {
|
||||
if err := lib.InitializeDBPool(databaseURL); err != nil {
|
||||
log.Fatalf("Failed to initialize DB pool: %v", err)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue