feat: improve deployment

This commit is contained in:
2024-08-05 20:03:24 +03:00
parent caab066ff8
commit 414cc001ec
8 changed files with 36 additions and 10 deletions

View File

@@ -13,7 +13,12 @@ export DISCORD_TOKEN=
# mongodb
export MONGODB_URI=mongodb://localhost:27017
export MONGODB_VOLUME_PATH=data/db
# deployment
# where the bot code is located (root folder - absolute path)
export APP_ROOT=
# where the DB data is saved - absolute path, or relative to APP_ROOT
export DB_PATH=data
# logging
export LOG_LEVEL=debug

3
.gitignore vendored
View File

@@ -131,7 +131,6 @@ dist
# CUSTOM
src/scripts/outputs
data/brain.dat
.DS_Store
build
data/db
data/

View File

@@ -13,6 +13,6 @@ export default [
},
},
{
ignores: ['node_modules/', 'build/', 'dist/', 'gen/'],
ignores: ['node_modules/', 'build/', 'dist/', 'gen/', 'scaffold.config.js'],
},
]

View File

@@ -3,7 +3,7 @@ Description=Venom Bot
After=network.target
[Service]
WorkingDirectory=/root/apps/venom
WorkingDirectory={{appRoot}}
ExecStart=/usr/local/bin/pnpm start
ExecStop=/bin/kill -SIGINT $MAINPID
Restart=on-failure

View File

@@ -4,6 +4,7 @@ After=docker.service
Requires=docker.service
[Service]
WorkingDirectory={{appRoot}}
Environment="DOCKER_RUN_CMD=docker run \
--name venom-mongo \
--hostname=2d2cb1232ad1 \
@@ -16,8 +17,8 @@ Environment="DOCKER_RUN_CMD=docker run \
--env=MONGO_MAJOR=7.0 \
--env=MONGO_VERSION=7.0.12 \
--env=HOME=/data/db \
--volume=./data/db:{{dbPath}}/db \
--volume=./data/configdb:/{{dbPath}}/configdb \
--volume=./{{dbPath}}/db:/data/db \
--volume=./{{dbPath}}/configdb:/data/configdb \
--volume=./data/configdb \
--volume=/data/db \
--network=bridge -p 27017:27017 \

View File

@@ -9,7 +9,7 @@
"logs": "journalctl -f -u venom-bot.service",
"build": "tsc && tsc-alias",
"gen": "simple-scaffold -c scaffold.config.js -k",
"install-services": "scripts/install-services.zsh",
"install-services": "src/scripts/install-services.zsh",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {

View File

@@ -1,3 +1,11 @@
const path = require('node:path')
const dotenv = require('dotenv')
dotenv.config({ path: path.resolve(process.cwd(), '.env.local') })
dotenv.config({ path: path.resolve(process.cwd(), '.env') })
console.log(process.env)
module.exports = {
command: {
templates: ['gen/command'],
@@ -11,8 +19,9 @@ module.exports = {
templates: ['gen/services'],
subdir: false,
data: {
// eslint-disable-next-line no-undef
dbPath: process.env.MONGODB_VOLUME_PATH,
dbPath: process.env.DB_PATH,
appRoot: process.env.APP_ROOT,
},
name: '-',
},
}

12
src/scripts/install-services.zsh Normal file → Executable file
View File

@@ -1,11 +1,23 @@
#!/usr/bin/env zsh
if [[ "$1" == "--dry-run" || "$1" == "-d" ]]; then
dry=1
fi
echo 'Installing dependencies...'
pnpm install
tmp=$(mktemp -d)
echo 'Generating systemd services...'
pnpm simple-scaffold -c scaffold.config.js -k services -o $tmp
echo 'Installing systemd services...'
if [[ $dry -eq 1 ]]; then
echo 'Dry run. Exiting'
echo
tail -n +1 $tmp/*
exit 0
fi
sudo mv $tmp/* /etc/systemd/system/
systemctl daemon-reload
systemctl enable venom-bot