diff --git a/.dev.env b/.dev.env new file mode 100644 index 0000000..901518b --- /dev/null +++ b/.dev.env @@ -0,0 +1,16 @@ +# 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 + +ABOUT_FUNDING=https://ko-fi.com/vylpes +ABOUT_REPO=https://github.com/vylpes/vylbot-app diff --git a/.env.template b/.prod.env similarity index 77% rename from .env.template rename to .prod.env index 7f24eab..cac0628 100644 --- a/.env.template +++ b/.prod.env @@ -9,8 +9,8 @@ BOT_TOKEN= BOT_VER=3.1 BOT_AUTHOR=Vylpes -BOT_DATE=04 Sep 2022 +BOT_DATE=05 Sep 2022 BOT_OWNERID=147392775707426816 -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..cac0628 --- /dev/null +++ b/.stage.env @@ -0,0 +1,16 @@ +# 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 + +ABOUT_FUNDING=https://ko-fi.com/vylpes +ABOUT_REPO=https://github.com/vylpes/vylbot-app 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..8e36b99 --- /dev/null +++ b/scripts/deploy_prod.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +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..09d2f00 --- /dev/null +++ b/scripts/deploy_stage.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +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