From 7decd28dc9aea8f935464e7f2895eb0f0a3e757e Mon Sep 17 00:00:00 2001 From: Vylpes Date: Tue, 6 Sep 2022 19:24:40 +0100 Subject: [PATCH] Feature/182 setup actions (#186) * Create scripts * Create github workflows * Create initial DB migration script * Make default bot prefix configurable * Add bot token fetcher --- .dev.env | 17 +++++++++ .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++++ .github/ISSUE_TEMPLATE/epic.md | 16 ++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 ++++++++++ .github/ISSUE_TEMPLATE/user-story.md | 24 ++++++++++++ .github/pull_request_template.md | 30 +++++++++++++++ .github/workflows/deployment.yml | 28 ++++++++++++++ .github/workflows/integration.yml | 20 ++++++++++ .github/workflows/staging.yml | 28 ++++++++++++++ .github/workflows/testing.yml | 27 ------------- .env.template => .prod.env | 7 ++-- .stage.env | 17 +++++++++ .../Up/01-table/Audit.sql | 11 ++++++ .../Up/01-table/IgnoredChannel.sql | 5 +++ .../Up/01-table/Lobby.sql | 10 +++++ .../Up/01-table/Role.sql | 7 ++++ .../Up/01-table/Server.sql | 5 +++ .../Up/01-table/Setting.sql | 8 ++++ .../Up/02-key/Audit.sql | 2 + .../Up/02-key/IgnoredChannel.sql | 2 + .../Up/02-key/Lobby.sql | 2 + .../Up/02-key/Role.sql | 3 ++ .../Up/02-key/Server.sql | 2 + .../Up/02-key/Setting.sql | 3 ++ .../Up/03-constraint/Role.sql | 2 + .../Up/03-constraint/Setting.sql | 2 + docker-compose.prod.yml | 31 +++++++++++++++ docker-compose.stage.yml | 31 +++++++++++++++ docker-compose.yml | 11 +++++- ormconfig.json.template => ormconfig.dev.json | 2 +- ormconfig.prod.json | 24 ++++++++++++ ormconfig.stage.json | 24 ++++++++++++ scripts/deploy_prod.sh | 23 +++++++++++ scripts/deploy_stage.sh | 23 +++++++++++ src/client/client.ts | 4 +- src/constants/DefaultValues.ts | 6 +-- src/helpers/MigrationHelper.ts | 20 ++++++++++ src/migration/1652375907691-CreateRole.ts | 13 ------- .../1657647026816-CreateIgnoredChannel.ts | 13 ------- src/migration/1660754832945-CreateAudit.ts | 13 ------- src/migration/3.1/1662399171315-CreateBase.ts | 30 +++++++++++++++ src/vylbot.ts | 4 +- 42 files changed, 525 insertions(+), 83 deletions(-) create mode 100644 .dev.env create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/epic.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/ISSUE_TEMPLATE/user-story.md create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/deployment.yml create mode 100644 .github/workflows/integration.yml create mode 100644 .github/workflows/staging.yml delete mode 100644 .github/workflows/testing.yml rename .env.template => .prod.env (75%) create mode 100644 .stage.env create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/IgnoredChannel.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/Role.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/Server.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/01-table/Setting.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/Audit.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/IgnoredChannel.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/Lobby.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/Server.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/02-key/Setting.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/03-constraint/Role.sql create mode 100644 database/3.1/1662399171315-CreateBase/Up/03-constraint/Setting.sql create mode 100644 docker-compose.prod.yml create mode 100644 docker-compose.stage.yml rename ormconfig.json.template => ormconfig.dev.json (96%) create mode 100644 ormconfig.prod.json create mode 100644 ormconfig.stage.json create mode 100644 scripts/deploy_prod.sh create mode 100644 scripts/deploy_stage.sh create mode 100644 src/helpers/MigrationHelper.ts delete mode 100644 src/migration/1652375907691-CreateRole.ts delete mode 100644 src/migration/1657647026816-CreateIgnoredChannel.ts delete mode 100644 src/migration/1660754832945-CreateAudit.ts create mode 100644 src/migration/3.1/1662399171315-CreateBase.ts diff --git a/.dev.env b/.dev.env new file mode 100644 index 0000000..2d8cbd1 --- /dev/null +++ b/.dev.env @@ -0,0 +1,17 @@ +# Security Warning! Do not commit this file to any VCS! +# This is a local file to speed up development process, +# so you don't have to change your environment variables. +# +# This is not applied to `.env.template`! +# Template files must be committed to the VCS, but must not contain +# any secret values. + +BOT_TOKEN= +BOT_VER=DEV +BOT_AUTHOR=Vylpes +BOT_DATE=DEV +BOT_OWNERID=147392775707426816 +BOT_PREFIX=d! + +ABOUT_FUNDING=https://ko-fi.com/vylpes +ABOUT_REPO=https://github.com/vylpes/vylbot-app diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..f3d5c41 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/epic.md b/.github/ISSUE_TEMPLATE/epic.md new file mode 100644 index 0000000..8dfd3c5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/epic.md @@ -0,0 +1,16 @@ +--- +name: Epic +about: Agile Epic +title: '' +labels: epic +assignees: '' + +--- + +*Description here* + +## Stories +*Stories linked to this epic* + +## Bugs +*Bugs linked to this epic* diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..11fc491 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: enhancement +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/user-story.md b/.github/ISSUE_TEMPLATE/user-story.md new file mode 100644 index 0000000..644fad5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/user-story.md @@ -0,0 +1,24 @@ +--- +name: User Story +about: Agile User Story +title: '' +labels: needs criteria, story +assignees: '' + +--- + +Epic Link: N/A +Story Points: N/A + +--- + +*Description here* + +## Acceptance Criteria +*Add your ACs here* + +## Notes +*Any extra information* + +## Subtasks +*Add technical subtasks here* diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..a773253 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,30 @@ +# Description + +Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. + +Fixes # (issue) + +## Type of change + +Please delete options that are not relevant. + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] This change requires a documentation update + +# How Has This Been Tested? + +Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration + + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] I have made corresponding changes to the documentation +- [ ] My changes generate no new warnings +- [ ] I have added tests that prove my fix is effective or that my feature works +- [ ] New and existing unit tests pass locally with my changes +- [ ] Any dependent changes have been merged and published in downstream modules \ No newline at end of file diff --git a/.github/workflows/deployment.yml b/.github/workflows/deployment.yml new file mode 100644 index 0000000..d7e85be --- /dev/null +++ b/.github/workflows/deployment.yml @@ -0,0 +1,28 @@ +name: deployment + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Test + uses: actions/setup-node@v1 + with: + node-version: 16.x + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test + - name: Deploy Production + uses: D3rHase/ssh-command-action@v0.2.1 + with: + HOST: ${{secrets.HOST}} + PORT: ${{secrets.PORT}} + USER: ${{secrets.USER}} + PRIVATE_SSH_KEY: ${{secrets.PRIVATE_SSH_KEY}} + COMMAND: ${{secrets.PROD_COMMAND}} \ No newline at end of file diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml new file mode 100644 index 0000000..d74e7aa --- /dev/null +++ b/.github/workflows/integration.yml @@ -0,0 +1,20 @@ +name: integration + +on: + push: + branches: + - feature/* + - hotfix/* + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Test + uses: actions/setup-node@v1 + with: + node-version: 16.x + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test \ No newline at end of file diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml new file mode 100644 index 0000000..a441cc3 --- /dev/null +++ b/.github/workflows/staging.yml @@ -0,0 +1,28 @@ +name: staging + +on: + push: + branches: + - develop + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build and Test + uses: actions/setup-node@v1 + with: + node-version: 16.x + - run: yarn install --frozen-lockfile + - run: yarn build + - run: yarn test + - name: Deploy Staging + uses: D3rHase/ssh-command-action@v0.2.1 + with: + HOST: ${{secrets.HOST}} + PORT: ${{secrets.PORT}} + USER: ${{secrets.USER}} + PRIVATE_SSH_KEY: ${{secrets.PRIVATE_SSH_KEY}} + COMMAND: ${{secrets.STAGE_COMMAND}} \ No newline at end of file diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml deleted file mode 100644 index 1f76252..0000000 --- a/.github/workflows/testing.yml +++ /dev/null @@ -1,27 +0,0 @@ -name: Testing - -on: - pull_request: - branches: - - main - - develop - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [16.x] - - steps: - - uses: actions/checkout@v2 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v1 - with: - node-version: ${{ matrix.node-version }} - - run: yarn install - - run: yarn build - - run: yarn test - diff --git a/.env.template b/.prod.env similarity index 75% rename from .env.template rename to .prod.env index 7f24eab..f5efcb5 100644 --- a/.env.template +++ b/.prod.env @@ -9,8 +9,9 @@ BOT_TOKEN= BOT_VER=3.1 BOT_AUTHOR=Vylpes -BOT_DATE=04 Sep 2022 +BOT_DATE=05 Sep 2022 BOT_OWNERID=147392775707426816 +BOT_PREFIX=v! -ABOUT_FUNDING= -ABOUT_REPO= +ABOUT_FUNDING=https://ko-fi.com/vylpes +ABOUT_REPO=https://github.com/vylpes/vylbot-app diff --git a/.stage.env b/.stage.env new file mode 100644 index 0000000..0477d32 --- /dev/null +++ b/.stage.env @@ -0,0 +1,17 @@ +# Security Warning! Do not commit this file to any VCS! +# This is a local file to speed up development process, +# so you don't have to change your environment variables. +# +# This is not applied to `.env.template`! +# Template files must be committed to the VCS, but must not contain +# any secret values. + +BOT_TOKEN= +BOT_VER=3.1 +BOT_AUTHOR=Vylpes +BOT_DATE=05 Sep 2022 +BOT_OWNERID=147392775707426816 +BOT_PREFIX=s! + +ABOUT_FUNDING=https://ko-fi.com/vylpes +ABOUT_REPO=https://github.com/vylpes/vylbot-app diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql new file mode 100644 index 0000000..fa4db1b --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/Audit.sql @@ -0,0 +1,11 @@ +CREATE TABLE `audit` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL, + `AuditId` varchar(255) NOT NULL, + `UserId` varchar(255) NOT NULL, + `AuditType` int NOT NULL, + `Reason` varchar(255) NOT NULL, + `ModeratorId` varchar(255) NOT NULL, + `ServerId` varchar(255) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/IgnoredChannel.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/IgnoredChannel.sql new file mode 100644 index 0000000..93d919b --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/IgnoredChannel.sql @@ -0,0 +1,5 @@ +CREATE TABLE `ignored_channel` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql new file mode 100644 index 0000000..e8ec996 --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/Lobby.sql @@ -0,0 +1,10 @@ +CREATE TABLE `lobby` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL, + `ChannelId` varchar(255) NOT NULL, + `RoleId` varchar(255) NOT NULL, + `Cooldown` int NOT NULL, + `LastUsed` datetime NOT NULL, + `Name` varchar(255) NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/Role.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/Role.sql new file mode 100644 index 0000000..7c781db --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/Role.sql @@ -0,0 +1,7 @@ +CREATE TABLE `role` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL, + `RoleId` varchar(255) NOT NULL, + `serverId` varchar(255) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/Server.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/Server.sql new file mode 100644 index 0000000..c6c721f --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/Server.sql @@ -0,0 +1,5 @@ +CREATE TABLE `server` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/01-table/Setting.sql b/database/3.1/1662399171315-CreateBase/Up/01-table/Setting.sql new file mode 100644 index 0000000..dac609a --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/01-table/Setting.sql @@ -0,0 +1,8 @@ +CREATE TABLE `setting` ( + `Id` varchar(255) NOT NULL, + `WhenCreated` datetime NOT NULL, + `WhenUpdated` datetime NOT NULL, + `Key` varchar(255) NOT NULL, + `Value` varchar(255) NOT NULL, + `serverId` varchar(255) DEFAULT NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/Audit.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/Audit.sql new file mode 100644 index 0000000..b8411a1 --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/Audit.sql @@ -0,0 +1,2 @@ +ALTER TABLE `audit` + ADD PRIMARY KEY (`Id`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/IgnoredChannel.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/IgnoredChannel.sql new file mode 100644 index 0000000..1288be1 --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/IgnoredChannel.sql @@ -0,0 +1,2 @@ +ALTER TABLE `ignored_channel` + ADD PRIMARY KEY (`Id`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/Lobby.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/Lobby.sql new file mode 100644 index 0000000..e8e34ef --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/Lobby.sql @@ -0,0 +1,2 @@ +ALTER TABLE `lobby` + ADD PRIMARY KEY (`Id`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql new file mode 100644 index 0000000..5d0a591 --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/Role.sql @@ -0,0 +1,3 @@ +ALTER TABLE `role` + ADD PRIMARY KEY (`Id`), + ADD KEY `FK_d9e438d88cfb64f7f8e1ae593c3` (`serverId`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/Server.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/Server.sql new file mode 100644 index 0000000..951587f --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/Server.sql @@ -0,0 +1,2 @@ +ALTER TABLE `server` + ADD PRIMARY KEY (`Id`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/02-key/Setting.sql b/database/3.1/1662399171315-CreateBase/Up/02-key/Setting.sql new file mode 100644 index 0000000..8d03bec --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/02-key/Setting.sql @@ -0,0 +1,3 @@ +ALTER TABLE `setting` + ADD PRIMARY KEY (`Id`), + ADD KEY `FK_a3623ec541bdb12fa0f58bdfde7` (`serverId`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/03-constraint/Role.sql b/database/3.1/1662399171315-CreateBase/Up/03-constraint/Role.sql new file mode 100644 index 0000000..22ffbc0 --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/03-constraint/Role.sql @@ -0,0 +1,2 @@ +ALTER TABLE `role` + ADD CONSTRAINT `FK_d9e438d88cfb64f7f8e1ae593c3` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`); \ No newline at end of file diff --git a/database/3.1/1662399171315-CreateBase/Up/03-constraint/Setting.sql b/database/3.1/1662399171315-CreateBase/Up/03-constraint/Setting.sql new file mode 100644 index 0000000..d5172ac --- /dev/null +++ b/database/3.1/1662399171315-CreateBase/Up/03-constraint/Setting.sql @@ -0,0 +1,2 @@ +ALTER TABLE `setting` + ADD CONSTRAINT `FK_a3623ec541bdb12fa0f58bdfde7` FOREIGN KEY (`serverId`) REFERENCES `server` (`Id`); \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml new file mode 100644 index 0000000..ae37fc5 --- /dev/null +++ b/docker-compose.prod.yml @@ -0,0 +1,31 @@ +version: "3.9" + +volumes: + prod_database_data: + +services: + # discord: + # build: . + + database: + image: mysql/mysql-server + command: --default-authentication-plugin=mysql_native_password + restart: always + environment: + - MYSQL_DATABASE=vylbot + - MYSQL_USER=prod + - MYSQL_PASSWORD=prod + - MYSQL_ROOT_PASSWORD=root + - MYSQL_ROOT_HOST=0.0.0.0 + ports: + - "3121:3306" + volumes: + - prod_database_data:/var/lib/mysql + + phpmyadmin: + image: phpmyadmin + restart: always + ports: + - "3122:80" + environment: + - PMA_ARBITRARY=1 \ No newline at end of file diff --git a/docker-compose.stage.yml b/docker-compose.stage.yml new file mode 100644 index 0000000..e25a6f1 --- /dev/null +++ b/docker-compose.stage.yml @@ -0,0 +1,31 @@ +version: "3.9" + +volumes: + stage_database_data: + +services: + # discord: + # build: . + + database: + image: mysql/mysql-server + command: --default-authentication-plugin=mysql_native_password + restart: always + environment: + - MYSQL_DATABASE=vylbot + - MYSQL_USER=stage + - MYSQL_PASSWORD=stage + - MYSQL_ROOT_PASSWORD=root + - MYSQL_ROOT_HOST=0.0.0.0 + ports: + - "3111:3306" + volumes: + - stage_database_data:/var/lib/mysql + + phpmyadmin: + image: phpmyadmin + restart: always + ports: + - "3112:80" + environment: + - PMA_ARBITRARY=1 \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a10aebd..92ce70a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,8 @@ version: "3.9" + +volumes: + dev_database_data: + services: # discord: # build: . @@ -12,13 +16,16 @@ services: - MYSQL_USER=dev - MYSQL_PASSWORD=dev - MYSQL_ROOT_PASSWORD=root + - MYSQL_ROOT_HOST=0.0.0.0 ports: - - 3306:3306 + - "3101:3306" + volumes: + - dev_database_data:/var/lib/mysql phpmyadmin: image: phpmyadmin restart: always ports: - - 8080:80 + - "3102:80" environment: - PMA_ARBITRARY=1 \ No newline at end of file diff --git a/ormconfig.json.template b/ormconfig.dev.json similarity index 96% rename from ormconfig.json.template rename to ormconfig.dev.json index 0ada020..f6f80c1 100644 --- a/ormconfig.json.template +++ b/ormconfig.dev.json @@ -1,7 +1,7 @@ { "type": "mysql", "host": "localhost", - "port": 3306, + "port": 3101, "username": "dev", "password": "dev", "database": "vylbot", diff --git a/ormconfig.prod.json b/ormconfig.prod.json new file mode 100644 index 0000000..300cfe2 --- /dev/null +++ b/ormconfig.prod.json @@ -0,0 +1,24 @@ +{ + "type": "mysql", + "host": "localhost", + "port": 3121, + "username": "prod", + "password": "prod", + "database": "vylbot", + "synchronize": false, + "logging": false, + "entities": [ + "dist/entity/**/*.js" + ], + "migrations": [ + "dist/migration/**/*.js" + ], + "subscribers": [ + "dist/subscriber/**/*.js" + ], + "cli": { + "entitiesDir": "dist/entity", + "migrationsDir": "dist/migration", + "subscribersDir": "dist/subscriber" + } +} \ No newline at end of file diff --git a/ormconfig.stage.json b/ormconfig.stage.json new file mode 100644 index 0000000..a038f64 --- /dev/null +++ b/ormconfig.stage.json @@ -0,0 +1,24 @@ +{ + "type": "mysql", + "host": "localhost", + "port": 3111, + "username": "stage", + "password": "stage", + "database": "vylbot", + "synchronize": false, + "logging": false, + "entities": [ + "dist/entity/**/*.js" + ], + "migrations": [ + "dist/migration/**/*.js" + ], + "subscribers": [ + "dist/subscriber/**/*.js" + ], + "cli": { + "entitiesDir": "dist/entity", + "migrationsDir": "dist/migration", + "subscribersDir": "dist/subscriber" + } +} \ No newline at end of file diff --git a/scripts/deploy_prod.sh b/scripts/deploy_prod.sh new file mode 100644 index 0000000..dee258f --- /dev/null +++ b/scripts/deploy_prod.sh @@ -0,0 +1,23 @@ +#! /bin/bash + +source "$HOME/.ssh/environment" + +export PATH="$HOME/.yarn/bin:$PATH" +export PATH="$HOME/.nvm/versions/node/v16.17.0/bin/:$PATH" + +cd ~/apps/vylbot/vylbot_prod \ +&& git checkout main \ +&& git fetch \ +&& git pull \ +&& docker-compose --file docker-compose.prod.yml down \ +&& (pm2 stop vylbot_prod || true) \ +&& (pm2 delete vylbot_prod || true) \ +&& cp .prod.env .env \ +&& cp ormconfig.prod.json ormconfig.json \ +&& yarn install --frozen-lockfile \ +&& yarn build \ +&& docker-compose --file docker-compose.prod.yml up -d \ +&& echo "Sleeping for 10 seconds to let database load..." \ +&& sleep 10 \ +&& yarn run db:up \ +&& NODE_ENV=production BOT_TOKEN=$BOT_TOKEN_PROD pm2 start --name vylbot_prod dist/vylbot.js \ No newline at end of file diff --git a/scripts/deploy_stage.sh b/scripts/deploy_stage.sh new file mode 100644 index 0000000..75d664a --- /dev/null +++ b/scripts/deploy_stage.sh @@ -0,0 +1,23 @@ +#! /bin/bash + +source "$HOME/.ssh/environment" + +export PATH="$HOME/.yarn/bin:$PATH" +export PATH="$HOME/.nvm/versions/node/v16.17.0/bin/:$PATH" + +cd ~/apps/vylbot/vylbot_stage \ +&& git checkout develop \ +&& git fetch \ +&& git pull \ +&& docker-compose --file docker-compose.stage.yml down \ +&& (pm2 stop vylbot_stage || true) \ +&& (pm2 delete vylbot_stage || true) \ +&& cp .stage.env .env \ +&& cp ormconfig.stage.json ormconfig.json \ +&& yarn install --frozen-lockfile \ +&& yarn build \ +&& docker-compose --file docker-compose.stage.yml up -d \ +&& echo "Sleeping for 10 seconds to let database load..." \ +&& sleep 10 \ +&& yarn run db:up \ +&& NODE_ENV=production BOT_TOKEN=$BOT_TOKEN_STAGE pm2 start --name vylbot_stage dist/vylbot.js \ No newline at end of file diff --git a/src/client/client.ts b/src/client/client.ts index 36f738f..1f46d7e 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -25,12 +25,10 @@ export class CoreClient extends Client { return this._eventItems; } - constructor(intents: number[], devmode: boolean = false) { + constructor(intents: number[]) { super({ intents: intents }); dotenv.config(); - DefaultValues.useDevPrefix = devmode; - CoreClient._commandItems = []; CoreClient._eventItems = []; diff --git a/src/constants/DefaultValues.ts b/src/constants/DefaultValues.ts index ec2a4b3..3f5ba09 100644 --- a/src/constants/DefaultValues.ts +++ b/src/constants/DefaultValues.ts @@ -17,11 +17,7 @@ export default class DefaultValues { private static SetValues() { if (this.values.length == 0) { // Bot - if (this.useDevPrefix) { - this.values.push({ Key: "bot.prefix", Value: "d!" }); - } else { - this.values.push({ Key: "bot.prefix", Value: "v!" }); - } + this.values.push({ Key: "bot.prefix", Value: process.env.BOT_PREFIX || "v!" }) // Commands this.values.push({ Key: "commands.disabled", Value: "" }); diff --git a/src/helpers/MigrationHelper.ts b/src/helpers/MigrationHelper.ts new file mode 100644 index 0000000..69fee4a --- /dev/null +++ b/src/helpers/MigrationHelper.ts @@ -0,0 +1,20 @@ +import { readFileSync } from "fs"; +import { QueryRunner } from "typeorm"; + +export default class MigrationHelper { + public static Up(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) { + for (let path of queryFiles) { + const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Up/${path}.sql`).toString(); + + queryRunner.query(query); + } + } + + public static Down(migrationName: string, version: string, queryFiles: string[], queryRunner: QueryRunner) { + for (let path of queryFiles) { + const query = readFileSync(`${process.cwd()}/database/${version}/${migrationName}/Down/${path}.sql`).toString(); + + queryRunner.query(query); + } + } +} \ No newline at end of file diff --git a/src/migration/1652375907691-CreateRole.ts b/src/migration/1652375907691-CreateRole.ts deleted file mode 100644 index 255ed0f..0000000 --- a/src/migration/1652375907691-CreateRole.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class migration1652375907691 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - queryRunner.query(`CREATE TABLE role (Id varchar(255), WhenCreated datetime, WhenUpdated datetime, RoleId varchar(255), serverId varchar(255), PRIMARY KEY (Id), FOREIGN KEY (serverId) REFERENCES server(Id))`); - } - - public async down(queryRunner: QueryRunner): Promise { - queryRunner.query(`DROP TABLE role`); - } - -} diff --git a/src/migration/1657647026816-CreateIgnoredChannel.ts b/src/migration/1657647026816-CreateIgnoredChannel.ts deleted file mode 100644 index aac003a..0000000 --- a/src/migration/1657647026816-CreateIgnoredChannel.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class migration1657647026816 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - queryRunner.query(`CREATE TABLE ignored_channel (Id varchar(255), PRIMARY KEY (Id))`); - } - - public async down(queryRunner: QueryRunner): Promise { - queryRunner.query(`DROP TABLE ignored_channel`) - } - -} diff --git a/src/migration/1660754832945-CreateAudit.ts b/src/migration/1660754832945-CreateAudit.ts deleted file mode 100644 index 9dab091..0000000 --- a/src/migration/1660754832945-CreateAudit.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm" - -export class CreateAudit1660754832945 implements MigrationInterface { - - public async up(queryRunner: QueryRunner): Promise { - queryRunner.query(`CREATE TABLE audit (Id varchar(255), WhenCreated datetime, WhenUpdated datetime, auditId varchar(255), userId varchar(255), auditType int, reason varchar(255), moderatorId varchar(255), serverId varchar(255), PRIMARY KEY (Id))`); - } - - public async down(queryRunner: QueryRunner): Promise { - queryRunner.query(`DROP TABLE audit`); - } - -} diff --git a/src/migration/3.1/1662399171315-CreateBase.ts b/src/migration/3.1/1662399171315-CreateBase.ts new file mode 100644 index 0000000..cd4e696 --- /dev/null +++ b/src/migration/3.1/1662399171315-CreateBase.ts @@ -0,0 +1,30 @@ +import { MigrationInterface, QueryRunner } from "typeorm" +import MigrationHelper from "../../helpers/MigrationHelper" + +export class vylbot1662399171315 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + MigrationHelper.Up('1662399171315-CreateBase', '3.1', [ + "01-table/Audit", + "01-table/IgnoredChannel", + "01-table/Lobby", + "01-table/Role", + "01-table/Server", + "01-table/Setting", + + "02-key/Audit", + "02-key/IgnoredChannel", + "02-key/Lobby", + "02-key/Role", + "02-key/Server", + "02-key/Setting", + + "03-constraint/Role", + "03-constraint/Setting", + ], queryRunner); + } + + public async down(queryRunner: QueryRunner): Promise { + } + +} diff --git a/src/vylbot.ts b/src/vylbot.ts index 50f1d87..1d6a420 100644 --- a/src/vylbot.ts +++ b/src/vylbot.ts @@ -19,13 +19,11 @@ requiredConfigs.forEach(config => { } }); -const devmode = process.argv.find(x => x.toLowerCase() == "--dev") != null; - const client = new CoreClient([ Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS, -], devmode); +]); registry.RegisterCommands(); registry.RegisterEvents();