Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: implement PostgreSQL for storage of per-server settings #19

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
da78648
initial commit to pgtyped branch
RalphORama Dec 26, 2023
abbcb66
initial database development
RalphORama Dec 26, 2023
3ad402d
fix: re-add .eslintrc, configure prettier
RalphORama Dec 27, 2023
d75492a
style: formatted with prettier
RalphORama Dec 27, 2023
06c4e6f
pgtyped: renamed config and formatted with prettier
RalphORama Dec 27, 2023
4d4b41b
ci (linting): split prettier and eslint jobs
RalphORama Dec 27, 2023
ca06e39
style: add comments to .env.example
RalphORama Dec 27, 2023
4848926
Merge branch 'main' into feature-pgtyped
RalphORama Dec 27, 2023
7d7a2cb
use regular .ts extensions for queries
RalphORama Dec 28, 2023
1196aee
refactor: move getFromEnvOrFile to its own file
RalphORama Dec 28, 2023
938b57c
db: update sql schema
RalphORama Dec 28, 2023
38cc337
feat(docker-compose): add `links` to bot
RalphORama Dec 28, 2023
f395c31
refactor: drop PgTyped for raw Postgres queries
RalphORama Dec 28, 2023
2ff7410
refactor: docker secrets suck! + pgPool test
RalphORama Dec 28, 2023
1c6fa9b
refactor: move CustomPool to submodule
RalphORama Dec 28, 2023
4406bd9
style (eslint): enable eslint/sort-imports rule
RalphORama Dec 28, 2023
e11a627
refactor: oops I forgot we're using initdb
RalphORama Dec 28, 2023
58396d5
npm run format: use cache for eslint and prettier
RalphORama Dec 28, 2023
92617e2
feat: initial work on `/config` command
RalphORama Dec 28, 2023
63607e5
Merge branch 'main' into feature-postgresql
RalphORama Dec 29, 2023
637cf89
Merge branch 'main' into feature-postgresql
RalphORama Dec 29, 2023
20cee19
style: update prettierrc on our side
RalphORama Dec 29, 2023
b262c22
Merge branch 'main' into feature-postgresql
RalphORama Dec 29, 2023
3b93258
fix: run prettier first in npm format script
RalphORama Dec 29, 2023
6384dc2
feat: now we have the settings...
RalphORama Dec 30, 2023
d6e4b4f
ci: fix call to prettier linting task
RalphORama Dec 31, 2023
78877f3
refactor: move @types up one directory
RalphORama Dec 31, 2023
f23c388
feature: add missing pg types
RalphORama Dec 31, 2023
20d8fde
fix: refactor tsconfig.json after moving @types
RalphORama Dec 31, 2023
e82c9ad
feat: /configure reads from/writes to database
RalphORama Dec 31, 2023
f7aba51
feat: add `created` and `updated` fields to initdb
RalphORama Dec 31, 2023
7551929
Merge branch 'main' into feature-postgresql
RalphORama Dec 31, 2023
f78d4ed
Merge branch 'main' into feature-postgresql
RalphORama Dec 31, 2023
f765432
Merge branch 'main' into feature-postgresql
RalphORama Dec 31, 2023
3f66a15
Merge branch 'main' into feature-postgresql
RalphORama Jan 1, 2024
887d07f
fix: schema updates
RalphORama Jan 5, 2024
309dc49
docker: only expose postgres to localhost
RalphORama Jan 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
**/node_modules/*
**/.git/*
**/.github/*
**/.vscode/*
**/dist/*
**/media/*
**/node_modules/*
**/secrets/*

.git/
.github/
.vscode/
media/
src/util
**/.env*
**/.eslint*
**/.gitattributes
**/.gitignore
**/.pre-commit-config.yaml
**/.prettier*
**/docker-compose*.y*ml

docs/*
src/cli/*

*.gz
*.log
*.sql
*.tar
*.gz

.env*
docker-compose*.y*ml

.gitattributes
.gitignore

.pre-commit-config.yaml
.prettierrc
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
DISCORD_BOT_TOKEN=put.your.token.here
DISCORD_APP_ID=385950397493280805
# Note this should be set to /run/secrets/discord-bot-token for Docker instances
DISCORD_BOT_TOKEN_FILE=./secrets/discord-bot-token.txt

POSTGRES_USER=linkfix
# Note this should be set to /run/secrets/postgres-password for Docker instances
POSTGRES_PASSWORD_FILE=./secrets/postgres-password.txt

LINKFIX_DEBUG=0

Expand Down
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
},
root: true,
ignorePatterns: ["/dist"],
rules: {
"sort-imports": "error",
},
overrides: [
{
files: ["*.ts"],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- run: npm ci

- run: npm run prettier
- run: npm run prettier-check

eslint:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
rev: v3.1.0
hooks:
- id: prettier
exclude: \.(json|md|mts|sql)$
exclude: \.(json|md|sql)$

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down
4 changes: 0 additions & 4 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# ignore folders
.vscode
dist
media
secrets

# ignore files
**/*.json
**/*.md
# .mts files are generated by PgTyped. Shouldn't be touched otherwise.
**/*.mts
**/*.sql
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ RUN [ "npm", "ci", "--omit=dev" ]
COPY . .
RUN [ "npm", "run", "build-prod" ]

# Fire 'er up!
CMD [ "node", "dist/index.js" ]
ENV RUNNING_IN_DOCKER "true"

CMD [ "/usr/local/bin/node", "./dist/bot/index.js" ]
63 changes: 49 additions & 14 deletions docker-compose.example.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,54 @@
# 1) Copy this file from docker-compose.example.yml to docker-compose.yml
# 2) Edit the `environment` section to use your bot's token
# i.e. `DISCORD_BOT_TOKEN=123456.789.10`
# 3) execute `docker compose up` to start the bot
# 1. Copy this file from docker-compose.example.yml to docker-compose.yml
# 2. In the 'secrets/' directory, create two files:
# - discord-bot-token.txt
# - postgres-password.txt
# 3. Populate files with the following:
# - discord-bot-token.txt: your bot's Discord token
# - postgres-password.txt: a secure password for Postgres
# 4. execute `docker compose up [-d]` to start the bot

version: "3.8"

x-db-config: &db-config
POSTGRES_USER: linkfix
POSTGRES_PASSWORD: change.me.please

services:
linkfix_bot:
# replace `image: <image>` with `build: .` for local dev environments
image: ghcr.io/podaboutlist/linkfix-for-discord:latest
# Use SIGKILL to emulate Ctrl+C (discord.js does not handle SIGTERM)
stop_signal: SIGKILL
environment:
- DISCORD_BOT_TOKEN=your.bot.token.here
- LINKFIX_DEBUG=0
- INSTAGRAM_FIX_URL=ddinstagram.com
- PIXIV_FIX_URL=phixiv.net
- REDDIT_FIX_URL=vxreddit.com
- TIKTOK_FIX_URL=vxtiktok.com
- TWITTER_FIX_URL=fxtwitter.com
- YOUTUBE_FIX_URL=youtu.be
<<: *db-config
DISCORD_BOT_TOKEN: your.token.here
LINKFIX_DEBUG: 0
INSTAGRAM_FIX_URL: ddinstagram.com
PIXIV_FIX_URL: phixiv.net
REDDIT_FIX_URL: vxreddit.com
TIKTOK_FIX_URL: vxtiktok.com
TWITTER_FIX_URL: fxtwitter.com
YOUTUBE_FIX_URL: youtu.be
depends_on:
postgres:
condition: service_healthy
links:
- "postgres:postgres.docker"

postgres:
image: postgres:16-alpine
restart: always
environment:
<<: *db-config
volumes:
- pgdata:/var/lib/postgresql/data
- ./src/bot/database/initdb/:/docker-entrypoint-initdb.d
ports:
- "127.0.0.1:15432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_USER} -U $${POSTGRES_USER}"]
interval: 5s
timeout: 2s
retries: 3
start_period: 5s

volumes:
pgdata:
Loading
Loading