mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-15 02:29:28 +03:00
feat: bootstrap containerisation
insane laughter ensues
This commit is contained in:
+2
-1
@@ -7,6 +7,7 @@ node_modules
|
||||
|
||||
# PNPM noise
|
||||
.pnpm-debug.log
|
||||
.pnpm-store
|
||||
|
||||
# Compiled output
|
||||
js
|
||||
@@ -39,4 +40,4 @@ failed-tests.log
|
||||
.tsbuildinfo
|
||||
|
||||
# bootstrap flag
|
||||
_scripts/I_HAVE_BOOTSTRAPPED_OK
|
||||
I_HAVE_BOOTSTRAPPED_OK
|
||||
@@ -0,0 +1,15 @@
|
||||
# Yes, I've made an entire docker container just to run a bash script
|
||||
# instead of rewriting the script in a ~~real~~ cross-platform scripting language.
|
||||
# This docker container **depends** on an external volume being mounted
|
||||
# (see how it's used in docker-compose-dev.yml)
|
||||
# and *intentionally* mutates state outside of its container.
|
||||
|
||||
# I really do not care.
|
||||
# Want it better? Do it yourself.
|
||||
FROM node:16 as base
|
||||
|
||||
RUN npm install --silent -g pnpm
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
CMD ["bash", "_scripts/bootstrap.sh"]
|
||||
+33
-3
@@ -2,6 +2,7 @@
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/59895/how-can-i-get-the-directory-where-a-bash-script-is-located-from-within-the-scrip
|
||||
# if you actually think bash is a good programming language you are
|
||||
# *straight up delusional*
|
||||
@@ -10,6 +11,11 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
||||
cd "$SCRIPT_DIR";
|
||||
cd ..;
|
||||
|
||||
if [ -e I_HAVE_BOOTSTRAPPED_OK ]; then
|
||||
echo "Already bootstrapped."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
function mvExampleFiles {
|
||||
echo "Moving example config files into usable places..."
|
||||
|
||||
@@ -54,12 +60,26 @@ function pnpmInstall {
|
||||
echo "Installed dependencies."
|
||||
}
|
||||
|
||||
function setIndexes {
|
||||
echo "Setting indexes..."
|
||||
|
||||
(
|
||||
cd server
|
||||
pnpm run set-indexes
|
||||
)
|
||||
|
||||
echo "Set."
|
||||
|
||||
}
|
||||
|
||||
function syncDatabaseWithSeeds {
|
||||
echo "Syncing database with seeds..."
|
||||
|
||||
cd server
|
||||
(
|
||||
cd server
|
||||
|
||||
pnpm run sync-database-local
|
||||
pnpm run sync-database-local
|
||||
)
|
||||
|
||||
echo "Synced."
|
||||
}
|
||||
@@ -67,6 +87,16 @@ function syncDatabaseWithSeeds {
|
||||
mvExampleFiles
|
||||
selfSignHTTPS
|
||||
pnpmInstall
|
||||
setIndexes
|
||||
syncDatabaseWithSeeds
|
||||
touch I_HAVE_BOOTSTRAPPED_OK
|
||||
|
||||
cat << EOF > I_HAVE_BOOTSTRAPPED_OK
|
||||
Tachi was bootstrapped here on $(date).
|
||||
|
||||
The existence of this file stops Tachi from bootstrapping again.
|
||||
There's nothing harmful about this -- you can bootstrap as much as you want!
|
||||
We just don't want to necessarily bootstrap *each* time we boot Tachi.
|
||||
|
||||
To bootstrap again (incase you think something has gone wrong)
|
||||
Delete this file and re-run npm start.
|
||||
EOF
|
||||
|
||||
@@ -51,6 +51,23 @@ services:
|
||||
dockerfile: Dockerfile.seeds
|
||||
volumes:
|
||||
- ./:/app
|
||||
bootstrap:
|
||||
container_name: tachi-bootstrap
|
||||
build:
|
||||
dockerfile: Dockerfile.bootstrap
|
||||
volumes:
|
||||
- ./:/app
|
||||
depends_on:
|
||||
- redis
|
||||
- mongo
|
||||
links:
|
||||
- redis
|
||||
- mongo
|
||||
environment:
|
||||
REDIS_URL: redis
|
||||
MONGO_URL: mongo
|
||||
PORT: 8080
|
||||
NODE_ENV: "dev"
|
||||
volumes:
|
||||
tachi:
|
||||
driver: local
|
||||
+2
-1
@@ -22,7 +22,8 @@
|
||||
"recalc-everything": "ts-node src/scripts/state-sync/sync-state.ts",
|
||||
"make-user-admin": "ts-node src/scripts/make-user-admin.ts $@",
|
||||
"validate-database": "ts-node src/scripts/validate-database",
|
||||
"dev": "NODE_PATH=js/ nodemon"
|
||||
"dev": "NODE_PATH=js/ nodemon",
|
||||
"set-indexes": "ts-node src/scripts/set-indexes"
|
||||
},
|
||||
"author": "zkldi",
|
||||
"license": "AGPL3",
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
import { SetIndexes } from "../external/mongo/indexes";
|
||||
import { Command } from "commander";
|
||||
import CreateLogCtx from "lib/logger/logger";
|
||||
import { ServerConfig } from "lib/setup/config";
|
||||
import { WrapScriptPromise } from "utils/misc";
|
||||
|
||||
const program = new Command();
|
||||
|
||||
const logger = CreateLogCtx(__filename);
|
||||
|
||||
program.requiredOption("-d, --db <database>", "The database to index.");
|
||||
program.option("-d, --db <database>", "The database to index.");
|
||||
program.option(
|
||||
"-r, --reset",
|
||||
"Whether to reset all indexes on this database before indexing or not."
|
||||
@@ -17,6 +18,10 @@ program.option(
|
||||
program.parse(process.argv);
|
||||
const options: { db: string; reset?: boolean } = program.opts();
|
||||
|
||||
if (!options.db) {
|
||||
options.db = ServerConfig.MONGO_DATABASE_NAME;
|
||||
}
|
||||
|
||||
if (require.main === module) {
|
||||
WrapScriptPromise(SetIndexes(options.db, options.reset === true), logger);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user