Compare commits
1 Commits
main
...
prod-serve
Author | SHA1 | Date |
---|---|---|
Neil Parikh | 55c28ee8dc |
|
@ -1,15 +1,15 @@
|
||||||
### Steps to Deploy
|
### Steps to Deploy
|
||||||
- move contents of frontend/ to /srv/www-csc-links/
|
- move contents of static/ to /srv/www-csc-links/
|
||||||
- create a `.env` file in backend/ with following contents:
|
- create a `.env` file in server/ with following contents:
|
||||||
```
|
```
|
||||||
PASSWORD=...
|
PASSWORD=...
|
||||||
PORT=...
|
PORT=...
|
||||||
```
|
```
|
||||||
- run the following in backend/:
|
- Install the pip dependencies. One possible way to do so is to run the following in server/:
|
||||||
```
|
```
|
||||||
python3 -m venv venv
|
python3 -m venv venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
- run python app in backend/ (with the virtual env activated)
|
- run server.py in server/ (with the pip dependencies installed)
|
||||||
- edit the `.htaccess` file in /srv/www-csc-links/ to point to the running python application
|
- edit the `.htaccess` file in /srv/www-csc-links/ to point to the running python application
|
||||||
|
|
|
@ -18,5 +18,6 @@ types-Jinja2==0.1.0
|
||||||
types-MarkupSafe==0.1.3
|
types-MarkupSafe==0.1.3
|
||||||
types-typing-extensions==3.7.2
|
types-typing-extensions==3.7.2
|
||||||
types-Werkzeug==0.1.1
|
types-Werkzeug==0.1.1
|
||||||
|
waitress==2.0.0
|
||||||
Werkzeug==1.0.1
|
Werkzeug==1.0.1
|
||||||
wrapt==1.12.1
|
wrapt==1.12.1
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
from waitress import serve
|
||||||
|
from main import app, DB_PATH, regen_html, out_path
|
||||||
|
from setup_db import migrate_0
|
||||||
|
import os
|
||||||
|
|
||||||
|
if not os.path.exists(DB_PATH):
|
||||||
|
migrate_0()
|
||||||
|
|
||||||
|
with app.app_context():
|
||||||
|
regen_html(out_path)
|
||||||
|
|
||||||
|
port = int(os.environ.get("PORT") or 3000)
|
||||||
|
serve(app, host='0.0.0.0', port=port)
|
|
@ -1,27 +1,28 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import os
|
import os
|
||||||
|
|
||||||
DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
|
def migrate_0():
|
||||||
|
DB_PATH = os.path.join(os.path.dirname(__file__), 'links.db')
|
||||||
|
|
||||||
con = sqlite3.connect(DB_PATH)
|
con = sqlite3.connect(DB_PATH)
|
||||||
|
|
||||||
# array of links to store
|
# array of links to store
|
||||||
links = [
|
links = [
|
||||||
('http://csclub.uwaterloo.ca/','CS Club Website',0,0,1),
|
('http://csclub.uwaterloo.ca/','CS Club Website',0,0,1),
|
||||||
('https://www.instagram.com/uwcsclub/','Instagram',0,1,1),
|
('https://www.instagram.com/uwcsclub/','Instagram',0,1,1),
|
||||||
('https://www.facebook.com/uw.computerscienceclub','Facebook',0,2,1),
|
('https://www.facebook.com/uw.computerscienceclub','Facebook',0,2,1),
|
||||||
('http://twitch.tv/uwcsclub','Twitch',0,3,1),
|
('http://twitch.tv/uwcsclub','Twitch',0,3,1),
|
||||||
('http://bit.ly/uwcsclub-yt','YouTube',0,4,1),
|
('http://bit.ly/uwcsclub-yt','YouTube',0,4,1),
|
||||||
]
|
]
|
||||||
|
|
||||||
# SQLite setup
|
# SQLite setup
|
||||||
cur = con.cursor()
|
cur = con.cursor()
|
||||||
|
|
||||||
# test if table already exists
|
# test if table already exists
|
||||||
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='links'")
|
cur.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='links'")
|
||||||
if cur.fetchone():
|
if cur.fetchone():
|
||||||
raise Exception('Links table already exists.')
|
raise Exception('Links table already exists.')
|
||||||
else:
|
else:
|
||||||
cur.execute('''CREATE TABLE links (
|
cur.execute('''CREATE TABLE links (
|
||||||
url text NOT NULL,
|
url text NOT NULL,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
|
@ -33,4 +34,7 @@ else:
|
||||||
cur.executemany('INSERT INTO links VALUES (?,?,?,?,?)', links)
|
cur.executemany('INSERT INTO links VALUES (?,?,?,?,?)', links)
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
migrate_0()
|
||||||
|
|
14
build.bash
14
build.bash
|
@ -8,15 +8,11 @@ NODE_ENV=production npx tailwindcss-cli@latest build index.in.css -o index.out.c
|
||||||
cd ..
|
cd ..
|
||||||
npm run build && npm run export
|
npm run build && npm run export
|
||||||
cd ..
|
cd ..
|
||||||
mv frontend/out build/frontend
|
mv frontend/out build/static
|
||||||
|
|
||||||
# Backend
|
# Backend
|
||||||
cd backend
|
rsync -ax --exclude venv --exclude links.db --exclude .env backend/ build/server
|
||||||
source venv/bin/activate
|
|
||||||
if [ ! -f links.db ]; then
|
|
||||||
python3 setup_db.py
|
|
||||||
fi
|
|
||||||
cd ..
|
|
||||||
rsync -ax --exclude venv backend/ build/backend
|
|
||||||
|
|
||||||
cp README-deploy.md build
|
cp README-deploy.md build/README.md
|
||||||
|
|
||||||
|
tar -cf linklist.tar build
|
||||||
|
|
Loading…
Reference in New Issue