Compare commits
7 Commits
36f5d6b396
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
62ed1badc2 | ||
|
|
9801ba4ba6 | ||
|
|
f6fcf82eae | ||
|
|
cf3abe92f5 | ||
|
|
e1f7404c8d | ||
|
|
1dae591ad5 | ||
|
|
66eb266dd3 |
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
node_modules
|
||||
Dockerfile
|
||||
.git
|
||||
.gitignore
|
||||
dist/**
|
||||
README.md
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,8 +5,8 @@ __pycache__
|
||||
|
||||
# dist folders
|
||||
dist
|
||||
frontend/dist
|
||||
backend/dist
|
||||
app/frontend/dist
|
||||
app/backend/dist
|
||||
|
||||
# sqlite file
|
||||
*.db
|
||||
|
||||
43
app/Dockerfile
Normal file
43
app/Dockerfile
Normal file
@@ -0,0 +1,43 @@
|
||||
FROM node:23 AS frontend
|
||||
|
||||
RUN corepack enable
|
||||
|
||||
# build the frontend
|
||||
COPY ./frontend /frontend
|
||||
WORKDIR /frontend
|
||||
RUN npm install
|
||||
CMD ["npm", "run", "build"]
|
||||
# RUN mkdir -p /srv/cprush-stats/frontend
|
||||
# RUN cp -rf ./dist/* /srv/cprush-stats/frontend
|
||||
|
||||
FROM node:23 AS backend
|
||||
|
||||
RUN corepack enable
|
||||
|
||||
# build the backend
|
||||
COPY ./backend /backend
|
||||
WORKDIR /backend
|
||||
RUN npm install
|
||||
CMD ["npm", "run", "build"]
|
||||
# RUN mkdir -p /srv/cprush-stats
|
||||
# RUN cp -rf ./dist/* /srv/cprush-stats
|
||||
# RUN cp package.json /srv/cprush-stats/package.json
|
||||
|
||||
FROM node:23 AS server
|
||||
|
||||
RUN corepack enable
|
||||
|
||||
RUN mkdir -p /srv/cprush-stats/frontend
|
||||
COPY --from=frontend /frontend/dist /srv/cprush-stats/frontend
|
||||
COPY --from=backend /backend/dist /srv/cprush-stats
|
||||
COPY --from=backend /backend/package.json /srv/cprush-stats/package.json
|
||||
|
||||
VOLUME /srv/cprush-stats/data
|
||||
|
||||
EXPOSE 3001
|
||||
ENV NODE_ENV=production
|
||||
ENV MEMCACHE_ADDR="localhost:11211"
|
||||
|
||||
WORKDIR /srv/cprush-stats
|
||||
RUN npm install
|
||||
CMD ["sh", "-c", "node app.js -m $MEMCACHE_ADDR"]
|
||||
@@ -13,9 +13,13 @@ var Memcached = require('memcached')
|
||||
|
||||
const app = express()
|
||||
const jsonParser = json()
|
||||
const port = 3001
|
||||
// const memcache = new memcached('localhost:11211', {})
|
||||
const memcachep = new Memcache('localhost:11211')
|
||||
const port = process.argv[process.argv.indexOf('-p')]
|
||||
? process.argv[process.argv.indexOf('-p') + 1]
|
||||
: 3001
|
||||
const memcache_addr = process.argv[process.argv.indexOf('-m')]
|
||||
? process.argv[process.argv.indexOf('-m') + 1]
|
||||
: 'localhost:11211'
|
||||
const memcachep = new Memcache(memcache_addr)
|
||||
|
||||
addGameApis(app, jsonParser, memcachep)
|
||||
addCharacterApis(app, jsonParser, memcachep)
|
||||
@@ -29,5 +33,7 @@ app.use('/', (req, res) => {
|
||||
|
||||
app.listen(port, async () => {
|
||||
await database.authenticate()
|
||||
return console.log(`Express is listening at http://localhost:${port}`)
|
||||
console.log(`Using memcache at ${memcache_addr}`)
|
||||
console.log(`Express is listening at http://localhost:${port}`)
|
||||
return
|
||||
})
|
||||
@@ -25,7 +25,7 @@ export const roleNames: RoleName[] = [
|
||||
'Rocker'
|
||||
]
|
||||
|
||||
const databasePath = './testdb.db'
|
||||
const databasePath = './data/testdb.db'
|
||||
|
||||
export const database = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
|
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 526 B After Width: | Height: | Size: 526 B |
35
docker-compose.yaml
Normal file
35
docker-compose.yaml
Normal file
@@ -0,0 +1,35 @@
|
||||
version: "3"
|
||||
|
||||
networks:
|
||||
cprush-net:
|
||||
external: false
|
||||
|
||||
volumes:
|
||||
cprush-loader-data:
|
||||
|
||||
services:
|
||||
cprush:
|
||||
# image: potato
|
||||
build: ./app
|
||||
environment:
|
||||
- MEMCACHE_ADDR=memcache:11211
|
||||
volumes:
|
||||
- cprush-loader-data:/srv/cprush-stats/data
|
||||
networks:
|
||||
- cprush-net
|
||||
ports:
|
||||
- 3001:3001
|
||||
depends_on:
|
||||
- memcache
|
||||
- loader
|
||||
loader:
|
||||
build: ./loader
|
||||
environment:
|
||||
- REPLAY_TIME=600
|
||||
volumes:
|
||||
- cprush-loader-data:/loader/data
|
||||
|
||||
memcache:
|
||||
image: memcached
|
||||
networks:
|
||||
- cprush-net
|
||||
68
install.sh
68
install.sh
@@ -1,68 +0,0 @@
|
||||
#!/bin/bash
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
|
||||
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Creating user rushstats"
|
||||
echo "---"
|
||||
if [id rushstats >/dev/null 2>&1]; then
|
||||
echo "rushstats user already exists, skipping."
|
||||
else
|
||||
useradd -s /sbin/nologin rushstats
|
||||
echo "User rushstats created with /sbin/nologin"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Moving the distributable folder into /srv/gamestats"
|
||||
echo "---"
|
||||
if [ -d /srv/gamestats ]; then
|
||||
echo "/srv/gamestats already exists; removing"
|
||||
rm -r /srv/rushstats
|
||||
fi
|
||||
mkdir /srv/gamestats
|
||||
cp -r "$parent_path"/dist/* /srv/gamestats
|
||||
cp -r "$parent_path"/loader/* /srv/gamestats
|
||||
chown -R rushstats:rushstats /srv/gamestats
|
||||
|
||||
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Creating the systemd services."
|
||||
echo "---"
|
||||
SYSTEMD_SERVICE_FILE=/etc/systemd/system/rushstats.service
|
||||
if [ -f $SYSTEMD_SERVICE_FILE ]; then
|
||||
echo "Service already exists; removing."
|
||||
rm $SYSTEMD_SERVICE_FILE
|
||||
fi
|
||||
touch $SYSTEMD_SERVICE_FILE
|
||||
echo "[Unit]" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "Description=Stats Server for Cyberpunk Rush" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "After=network.target" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "[Service]" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "Type=simple" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "WorkingDirectory=/srv/gamestats"
|
||||
echo "ExecStart=node /srv/gamestats/app.js" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "Restart=on-failure" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "[Install]" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "WantedBy=multi-user.target" >> $SYSTEMD_SERVICE_FILE
|
||||
echo "" >> $SYSTEMD_SERVICE_FILE
|
||||
|
||||
echo "Created new service."
|
||||
echo cat $SYSTEMD_SERVICE_FILE
|
||||
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Reloading daemons and starting service"
|
||||
echo "---"
|
||||
systemctl daemon-reload
|
||||
systemctl enable rushstats.service
|
||||
systemctl start rushstats.service
|
||||
|
||||
echo ""
|
||||
echo "---"
|
||||
echo "Creating the cron job to refresh the database."
|
||||
echo "---"
|
||||
15
loader/Dockerfile
Normal file
15
loader/Dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
# Setup the loader
|
||||
FROM python:3.12 AS loader
|
||||
|
||||
COPY . /loader
|
||||
|
||||
VOLUME /loader/data
|
||||
|
||||
WORKDIR /loader
|
||||
RUN python -m pip install --upgrade pip
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
ENV REPLAY_TIME=0
|
||||
|
||||
|
||||
CMD ["sh", "-c", "python3 createrushdatabase.py -r $REPLAY_TIME"]
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
|
||||
PYTHON_VEN="$parent_path"/venv/bin/python
|
||||
if [ ! -f $PYTHON_VEN ]; then
|
||||
echo "Setting up new VENV"
|
||||
python3 -m venv venv
|
||||
echo "Installing requirements."
|
||||
source ./venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
deactivate
|
||||
fi
|
||||
|
||||
echo "Start DB Creation"
|
||||
$parent_path/venv/bin/python createrushdatabase.py
|
||||
@@ -1,14 +1,27 @@
|
||||
import time
|
||||
import argparse
|
||||
|
||||
from databasesync import createDatabase
|
||||
from sheetloader import downloadGamesCSV, downloadCharactersCSV
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-r", "--replay_time", type=int)
|
||||
args = parser.parse_args()
|
||||
|
||||
CHARACTER_DATA_OUT_FILE = "CharacterData.csv"
|
||||
GAME_DATA_OUT_FILE = "GameData.csv"
|
||||
DATABASE_NAME = "testdb.db"
|
||||
|
||||
DATABASE_NAME = "data/testdb.db"
|
||||
|
||||
def execute():
|
||||
downloadCharactersCSV(CHARACTER_DATA_OUT_FILE)
|
||||
downloadGamesCSV(GAME_DATA_OUT_FILE)
|
||||
createDatabase(DATABASE_NAME, GAME_DATA_OUT_FILE, CHARACTER_DATA_OUT_FILE)
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("starting up loader.")
|
||||
print("replay time: ", args.replay_time)
|
||||
execute()
|
||||
while args.replay_time and args.replay_time > 0:
|
||||
print("re-run in ", args.replay_time, "seconds", flush=True)
|
||||
time.sleep(args.replay_time)
|
||||
execute()
|
||||
|
||||
31
setup.sh
31
setup.sh
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
|
||||
mkdir "$parent_path"/dist
|
||||
|
||||
# Build and move the front end distribution into the output dist folder
|
||||
cd "$parent_path"/frontend
|
||||
npm install
|
||||
npm run build
|
||||
cd ../
|
||||
cp -rf ./frontend/dist ./dist/frontend
|
||||
|
||||
# Build and move the back end distribution into the output dist folder
|
||||
cd "$parent_path"/backend
|
||||
npm install
|
||||
npm run build
|
||||
cd ../
|
||||
cp -f ./backend/dist/* ./dist
|
||||
|
||||
|
||||
# Build and move the database into the output dist folder
|
||||
cd "$parent_path"/loader
|
||||
python3 createrushdatabase.py
|
||||
cd ../
|
||||
cp -r ./loader/* ./dist
|
||||
|
||||
# Move the package into the dist folder and install the needed modules
|
||||
cd "$parent_path"
|
||||
cp ./backend/package.json ./dist/package.json
|
||||
cd "$parent_path"/dist
|
||||
npm install
|
||||
Reference in New Issue
Block a user