diff --git a/Dockerfile b/.Dockerfile similarity index 100% rename from Dockerfile rename to .Dockerfile diff --git a/.env.example b/.env.example index c6b92e9..35b6ae0 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?sslmode=disable +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/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 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..831f24e --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,54 @@ +services: + statuspages_bot: + build: + 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: + - '${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