From 461f8435c03c3395bdf8ff85f77bf3c0cb59487b Mon Sep 17 00:00:00 2001 From: FernandoJVideira <03.pleaser-minster@icloud.com> Date: Wed, 18 Mar 2026 13:39:31 +0000 Subject: [PATCH] feat: add Docker support and bot configuration - Introduced Dockerfile for building the bot application using Go. - Added .dockerignore to exclude unnecessary files from the Docker context. - Updated docker-compose.yml to define the bot service and its dependencies, including environment variables for database and Lavalink configuration. - Modified internal configuration to streamline environment variable handling. --- .dockerignore | 7 +++++++ Dockerfile | 21 +++++++++++++++++++++ docker-compose.yml | 33 ++++++++++++++++----------------- internal/config/config.go | 15 ++++++--------- 4 files changed, 50 insertions(+), 26 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c012acc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +.git +.gitignore +.env +*.md +Dockerfile +docker-compose*.yml +.dockerignore diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d934204 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,21 @@ +# Build stage +FROM golang:1.22-alpine AS builder + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o /velox-bot . + +# Run stage +FROM alpine:3.19 + +RUN apk add --no-cache ca-certificates tzdata + +WORKDIR /app + +COPY --from=builder /velox-bot . + +ENTRYPOINT ["./velox-bot"] diff --git a/docker-compose.yml b/docker-compose.yml index 79d4307..a42b76c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,23 +1,22 @@ version: "3.9" services: - db: - image: postgres:16 - container_name: velox-postgres + bot: + build: . + container_name: velox-bot restart: unless-stopped + env_file: .env 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 + 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: + db: + condition: service_healthy + networks: + - default + - lavalink -volumes: - velox_pgdata: \ No newline at end of file +networks: + lavalink: + external: true \ No newline at end of file diff --git a/internal/config/config.go b/internal/config/config.go index fcab283..2fd96fd 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,12 +8,12 @@ import ( ) type Config struct { - BotToken string - AppID string - GuildID string - DBHost string - LavalinkHost string - LavalinkPass string + BotToken string + AppID string + GuildID string + DBHost string + LavalinkHost string + LavalinkPass string TwitchClientID string } @@ -33,9 +33,6 @@ func LoadConfig() (*Config, error) { } guildID := os.Getenv("GUILD_ID") - if guildID == "" { - return nil, fmt.Errorf("GUILD_ID is not set") - } dbHost := os.Getenv("DB_HOST") if dbHost == "" {