From 26e1d9b094ff9be903e42f69e302d51eca5cf790 Mon Sep 17 00:00:00 2001 From: FernandoJVideira <03.pleaser-minster@icloud.com> Date: Wed, 18 Mar 2026 14:08:21 +0000 Subject: [PATCH] feat: update Docker configuration and environment handling - Added PostgreSQL service to docker-compose.yml with health checks and persistent storage. - Updated bot service to use environment variable substitution for database connection string. - Upgraded Go version in Dockerfile to 1.26.1-alpine. - Modified config loading to ignore missing .env file for better compatibility with Docker. --- Dockerfile | 2 +- docker-compose.yml | 20 +++++++++++++++++++- internal/config/config.go | 5 ++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index d934204..b35e925 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Build stage -FROM golang:1.22-alpine AS builder +FROM golang:1.26.1-alpine AS builder WORKDIR /app diff --git a/docker-compose.yml b/docker-compose.yml index a42b76c..ba28e18 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,31 @@ version: "3.9" services: + db: + image: postgres:16 + container_name: velox-postgres + restart: unless-stopped + environment: + POSTGRES_USER: velox + POSTGRES_PASSWORD: velox_pwd + POSTGRES_DB: velox + ports: + - "5432:5432" + volumes: + - velox_pgdata:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U velox -d velox"] + interval: 10s + timeout: 5s + retries: 5 + bot: build: . container_name: velox-bot restart: unless-stopped env_file: .env environment: - DB_HOST: postgres://velox:velox_pwd@db:5432/velox?sslmode=disable + DB_HOST: ${DB_HOST:-postgres://velox:velox_pwd@db:5432/velox?sslmode=disable} LAVALINK_HOST: ${LAVALINK_HOST:-ws://lavalink:2333} LAVALINK_PASSWORD: ${LAVALINK_PASSWORD:-youshallnotpass} depends_on: diff --git a/internal/config/config.go b/internal/config/config.go index 2fd96fd..6d2b975 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -18,9 +18,8 @@ type Config struct { } func LoadConfig() (*Config, error) { - if err := godotenv.Load(); err != nil { - return nil, err - } + // Load .env if present (e.g. local dev). Ignore if missing (e.g. Docker injects env vars). + _ = godotenv.Load() token := os.Getenv("BOT_TOKEN") if token == "" { -- 2.54.0