From a0a41919b65523c5273307e602ccdc585fffa621 Mon Sep 17 00:00:00 2001 From: Chaos Date: Fri, 4 Jul 2025 15:52:39 +0200 Subject: [PATCH 1/3] untested docker-compose file --- .env.example | 38 ++++++++++++++++++++++++++++++- docker-compose.yaml | 55 +++++++++++++++++++++++++++++++++++++++++++++ init.sql | 1 + 3 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 docker-compose.yaml create mode 100644 init.sql diff --git a/.env.example b/.env.example index c6b92e9..a8781c8 100644 --- a/.env.example +++ b/.env.example @@ -1,10 +1,46 @@ +# Discord Bot config - Required DISCORD_TOKEN= DISCORD_PUBLIC_KEY= + +# Discord Server Config - Required DISCORD_GUILD_ID= DISCORD_CHANNEL_ID= DISCORD_UPDATE_ROLE_ID= +## Default=true +DISCORD_SHOULD_CROSSPOST= +# Statuspage Config - Required STATUSPAGE_API_KEY= STATUSPAGE_PAGE_ID= +## Default=status.ticketsbot.cloud +STATUSPAGE_URL= + +# Discord gateway port -Required +## Default=8080 +SERVER_ADDR= + +# Database Config - Required +## Leave Vars empty when using Database included in the provided docker-compose.yaml file! +## Default=postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres +DATABASE_URI= +## Default=null +DATABASE_PASSWORD= + + + +# Optional Configurations: + +# Daemon Config - optional +## Default=false +DAEMON_ENABLED= +## Default=30s +DAEMON_FREQUENCY= +## Default=30m +DAEMON_EXECUTION_TIMEOUT= + -DATABASE_URI=postgres://postgres:postgres@localhost/postgres?sslmode=disable \ No newline at end of file +# Debug Config - ONLY TOUCH THESE WHEN YOU KNOW WHAT YOUR DOING! +## Default=false +JSON_LOGS= +## Default=info +LOG_LEVEL= \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..926b9b1 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,55 @@ +services: + statuspages_bot: + build: + dockerfile: './dockerfile' + args: + DAEMON_ENABLED: ${DAMEON_ENABLED:-false} + DAEMON_FREQUENCY: ${DAEMON_FREQUENCY:-30s} + DAEMON_EXECUTION_TIMEOUT: ${DAEMON_EXECUTION_TIMEOUT:-30m} + DISCORD_TOKEN: ${DISCORD_TOKEN} + DISCORD_PUBLIC_KEY: ${DISCORD_PUBLIC_KEY} + DISCORD_GUILD_ID: ${DISCORD_GUILD_ID} + DISCORD_CHANNEL_ID: ${DISCORD_CHANNEL_ID} + DISCORD_UPDATE_ROLE_ID: ${DISCORD_UPDATE_ROLE_ID} + DISCORD_SHOULD_CROSSPOST: ${DISCORD_SHOULD_CROSSPOST:-true} + STATUSPAGE_API_KEY: ${STATUSPAGE_API_KEY} + STATUSPAGE_PAGE_ID: ${STATUSPAGE_PAGE_ID} + STATUSPAGE_URL: ${STATUSPAGE_URL:-status.ticketsbot.cloud} + SERVER_ADDR: ${SERVER_ADDR:-8080} + DATABASE_PASSWORD: ${DATABASE_PASSWORD:-null} + DATABASE_URI: ${DATABASE_URI:-postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres} + JSON_LOGS: ${JSON_LOGS:-false} + LOG_LEVEL: ${LOG_LEVEL:-info} + ports: + # change the ports below to reflect your SERVER_ADDR env variable! + - '${SERVER_ADDR:-8080}:${SERVER_ADDR:-8080}' + depends_on: + postgres: + condition: service_healthy + restart: true + networks: + - app-network + + postgres: + image: postgres:15 + container_name: postgres-statusbot + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: ${DATABASE_PASSWORD:-null} + POSTGRES_DB: statusbot + ports: # Uncomment this line and the following line to access the main postgres on port 5433. Do not change the second port (5432) otherwise you cannot access the DB + - "5433:5432" + volumes: + - ./pgstatusbotdb:/var/lib/postgresql/data + - ./init.sql:/docker-entrypoint-initdb.d/init.sql + networks: + - app-network + healthcheck: + test: ["CMD-SHELL", "psql -U postgres -d statusbot -c 'SELECT 1' > /dev/null 2>&1 || exit 1"] + interval: 10s + timeout: 5s + retries: 10 + +networks: + app-network: + driver: bridge diff --git a/init.sql b/init.sql new file mode 100644 index 0000000..04e018c --- /dev/null +++ b/init.sql @@ -0,0 +1 @@ +CREATE TABLE IF NOT EXISTS incidents (id TEXT PRIMARY KEY, role_id BIGINT NOT NULL, message_id BIGINT NOT NULL, thread_id BIGINT NOT NULL, created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), updated_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(), status TEXT NOT NULL ) \ No newline at end of file From da57d5effc3fdece48b53b73bc3bd8bda63f4430 Mon Sep 17 00:00:00 2001 From: Chaos Date: Fri, 4 Jul 2025 18:13:13 +0200 Subject: [PATCH 2/3] docker-compose file works --- Dockerfile => .Dockerfile | 0 .env.example | 2 +- docker-compose.yaml | 39 +++++++++++++++++++-------------------- 3 files changed, 20 insertions(+), 21 deletions(-) rename Dockerfile => .Dockerfile (100%) diff --git a/Dockerfile b/.Dockerfile similarity index 100% rename from Dockerfile rename to .Dockerfile diff --git a/.env.example b/.env.example index a8781c8..35b6ae0 100644 --- a/.env.example +++ b/.env.example @@ -21,7 +21,7 @@ SERVER_ADDR= # Database Config - Required ## Leave Vars empty when using Database included in the provided docker-compose.yaml file! -## Default=postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres +## Default=postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres?sslmode=disable DATABASE_URI= ## Default=null DATABASE_PASSWORD= diff --git a/docker-compose.yaml b/docker-compose.yaml index 926b9b1..831f24e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,27 +1,26 @@ services: statuspages_bot: build: - dockerfile: './dockerfile' - args: - DAEMON_ENABLED: ${DAMEON_ENABLED:-false} - DAEMON_FREQUENCY: ${DAEMON_FREQUENCY:-30s} - DAEMON_EXECUTION_TIMEOUT: ${DAEMON_EXECUTION_TIMEOUT:-30m} - DISCORD_TOKEN: ${DISCORD_TOKEN} - DISCORD_PUBLIC_KEY: ${DISCORD_PUBLIC_KEY} - DISCORD_GUILD_ID: ${DISCORD_GUILD_ID} - DISCORD_CHANNEL_ID: ${DISCORD_CHANNEL_ID} - DISCORD_UPDATE_ROLE_ID: ${DISCORD_UPDATE_ROLE_ID} - DISCORD_SHOULD_CROSSPOST: ${DISCORD_SHOULD_CROSSPOST:-true} - STATUSPAGE_API_KEY: ${STATUSPAGE_API_KEY} - STATUSPAGE_PAGE_ID: ${STATUSPAGE_PAGE_ID} - STATUSPAGE_URL: ${STATUSPAGE_URL:-status.ticketsbot.cloud} - SERVER_ADDR: ${SERVER_ADDR:-8080} - DATABASE_PASSWORD: ${DATABASE_PASSWORD:-null} - DATABASE_URI: ${DATABASE_URI:-postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres} - JSON_LOGS: ${JSON_LOGS:-false} - LOG_LEVEL: ${LOG_LEVEL:-info} + dockerfile: './.Dockerfile' + environment: + DAEMON_ENABLED: ${DAMEON_ENABLED:-false} + DAEMON_FREQUENCY: ${DAEMON_FREQUENCY:-30s} + DAEMON_EXECUTION_TIMEOUT: ${DAEMON_EXECUTION_TIMEOUT:-30m} + DISCORD_TOKEN: ${DISCORD_TOKEN} + DISCORD_PUBLIC_KEY: ${DISCORD_PUBLIC_KEY} + DISCORD_GUILD_ID: ${DISCORD_GUILD_ID} + DISCORD_CHANNEL_ID: ${DISCORD_CHANNEL_ID} + DISCORD_UPDATE_ROLE_ID: ${DISCORD_UPDATE_ROLE_ID} + DISCORD_SHOULD_CROSSPOST: ${DISCORD_SHOULD_CROSSPOST:-true} + STATUSPAGE_API_KEY: ${STATUSPAGE_API_KEY} + STATUSPAGE_PAGE_ID: ${STATUSPAGE_PAGE_ID} + STATUSPAGE_URL: ${STATUSPAGE_URL:-status.ticketsbot.cloud} + SERVER_ADDR: :${SERVER_ADDR:-8080} + DATABASE_PASSWORD: ${DATABASE_PASSWORD:-null} + DATABASE_URI: ${DATABASE_URI:-postgres://postgres:${DATABASE_PASSWORD:-null}@postgres-statusbot:5432/postgres?sslmode=disable} + JSON_LOGS: ${JSON_LOGS:-false} + LOG_LEVEL: ${LOG_LEVEL:-info} ports: - # change the ports below to reflect your SERVER_ADDR env variable! - '${SERVER_ADDR:-8080}:${SERVER_ADDR:-8080}' depends_on: postgres: From 8dd14a3080450454258da4cbbccc93f7c170e3a1 Mon Sep 17 00:00:00 2001 From: Chaos Date: Fri, 4 Jul 2025 18:37:09 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9677b1f..69c29ff 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,30 @@ Status Updates is a backend service that keeps your Discord community informed b --- -## Installation +# Installation + +## Using Docker + + +1. **Clone the repository:** + ```sh + git clone https://github.com/TicketsBot-cloud/status-updates.git + cd status-updates + ``` +2. **Create a .env file by copying the provided [.env.example](./.env.example) file.** + Fill out all Env Variables in the sections that are Required. +3. **Start the Bot** + Run the following command in the directory the Bot's files were copied to: + `docker compose up -d` +4. **Set the Interaction Endpoint URL** + Go to the [Discord Developer Portal](https://discord.com/developers/applications) and click on the Application you made for this bot. + Set the Interaction Ednpoint URL to your Proxied domain with `/interactions` added behind it. (e.g. `https://{YOUR-CUSTOM-DOMAIN}/interactions`) + * You will need to proxy the port you set as your SERVER_ADDR (e.g. 8080) to a Publicly Accessible URL. + * Replace `{YOUR-CUSTOM-DOMAIN}` with your proxied URL (e.g. `gateway.example.com`) + + +## Manual + 1. **Clone the repository:** ```sh @@ -67,7 +90,7 @@ Status Updates is a backend service that keeps your Discord community informed b go build -o status-updates ./cmd/status-updates ``` -## Configuration +### Configuration Configuration is managed via environment variables or a config file. See `internal/config/config.go` for all options. @@ -85,7 +108,7 @@ STATUSPAGE_PAGE_ID=statuspage_page_id DATABASE_URI=postgres://postgres:postgres@localhost/postgres?sslmode=disable ``` -## Usage +### Usage To run the service locally: ```sh