Skip to content

Commit

Permalink
prepare configs for deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
scheibo committed Nov 6, 2023
1 parent 8edf54e commit 85e62be
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 27 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Tests
on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npm install
- run: npm test
- uses: actions/checkout@v3
- run: npm install
- run: npm test
2 changes: 2 additions & 0 deletions config/archive.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/archive.service /etc/systemd/system/pkmn.ai.archive.service

[Unit]
Description=Archive and cleanup old battle logs and tables
Requires=TODO
Expand Down
2 changes: 2 additions & 0 deletions config/archive.timer
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/archive.timer /etc/systemd/system/pkmn.ai.archive.timer

[Unit]
Description=Daily archive and cleanup old battle logs and tables

Expand Down
2 changes: 2 additions & 0 deletions config/backup.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/backup.service /etc/systemd/system/pkmn.ai.backup.service

[Unit]
Description=Archives, uploads, and cleans up old battle logs
Requires=TODO
Expand Down
2 changes: 2 additions & 0 deletions config/backup.timer
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/backup.timer /etc/systemd/system/pkmn.ai.backup.timer

[Unit]
Description=Monthly archive, upload, and cleanup of old battle logs

Expand Down
2 changes: 2 additions & 0 deletions config/monitor.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/monitor.service /etc/systemd/system/pkmn.ai.monitor.service

[Unit]
Description=pkmn.ai monitor service
Requires=network.target
Expand Down
15 changes: 12 additions & 3 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# TODO: https://www.nginx.com/blog/rate-limiting-nginx/
# ln -s pkmn/ai/config/nginx.conf /etc/nginx/sites-available/pkmn.ai

server {
listen 443 ssl;
listen [::]:443 ssl;
Expand All @@ -22,10 +23,18 @@ server {
expires 7d;
}

location /ws/ {
# TODO: https://www.nginx.com/blog/rate-limiting-nginx/
location /battles {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:1234;
}

location /ws {
internal;

proxy_pass http://localhost:1234/;
proxy_pass http://localhost:1234/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
16 changes: 0 additions & 16 deletions config/nginx.service

This file was deleted.

2 changes: 2 additions & 0 deletions config/ratings.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/ratings.service /etc/systemd/system/pkmn.ai.ratings.service

[Unit]
Description=Generates ratings history graphs
Requires=TODO
Expand Down
2 changes: 2 additions & 0 deletions config/ratings.timer
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/ratings.timer /etc/systemd/system/pkmn.ai.ratings.timer

[Unit]
Description=Daily generation of ratings history graphs

Expand Down
7 changes: 5 additions & 2 deletions config/server.service
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# ln -s pkmn/ai/config/server.service /etc/systemd/system/pkmn.ai.server.server

[Unit]
Description=pkmn.ai server
Requires=network.target
Expand All @@ -7,8 +9,9 @@ After=network.target
Type=simple
Restart=always
RestartSec=5s
ExecStart=TODO
WorkingDirectory=TODO
ExecStart=/usr/bin/npm start
WorkingDirectory=/home/pkmn/ai
StartLimitInterval=0
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=pkmn.ai.server
Expand Down
12 changes: 12 additions & 0 deletions deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Pull down latest code
git pull origin main
# Update dependencies in case they've changed
npm install --production
# Ensure any changes to unit files in config/ get picked up
systemctl daemon-reload
# Build and run the server
systemctl restart pkmn.ai.server
# Reload NGINX to pick up any changes to
systemctl reload nginx
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"compile": "tsc -p .",
"build": "npm run compile && node build/static/build",
"start": "npm run build && node build/server",
"test": "npm run build && npm run lint && hyperlink public --check-anchors"
"test": "npm run build && npm run lint && hyperlink public --check-anchors",
"deploy": "ssh [email protected] \"/home/pkmn/ai/deploy\""
},
"eslintConfig": {
"extends": "@pkmn"
Expand Down

0 comments on commit 85e62be

Please sign in to comment.