finish build script
This commit is contained in:
parent
a86ba4c1f5
commit
361b680354
|
@ -5,3 +5,5 @@ password.txt
|
|||
/.vscode
|
||||
data.json
|
||||
.env
|
||||
build/
|
||||
index.out.css
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
### Steps to Deploy
|
||||
- move contents of frontend/ to /srv/www-csc-links/
|
||||
- create a `.env` file in backend/ with following contents:
|
||||
```
|
||||
PASSWORD=...
|
||||
PORT=...
|
||||
```
|
||||
- run the following in backend/:
|
||||
```
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
- run python app in backend/ (with the virtual env activated)
|
||||
- edit the `.htaccess` file in /srv/www-csc-links/ to point to the running python application
|
|
@ -39,9 +39,9 @@ def get_data_from_query(query):
|
|||
con.close()
|
||||
return links_list
|
||||
|
||||
def regen_html():
|
||||
def regen_html(path):
|
||||
"""Gets links from DB and outputs them in HTML"""
|
||||
outfile = open(out_path, 'w')
|
||||
outfile = open(path, 'w')
|
||||
links_list = get_data_from_query('SELECT url, name FROM links WHERE active=1 ORDER BY position')
|
||||
html = render_template('template.html', links_list=links_list)
|
||||
print(html, file=outfile)
|
||||
|
@ -61,19 +61,21 @@ def get_links():
|
|||
@app.route('/editor/links', methods = ['POST'])
|
||||
@auth.login_required
|
||||
def update_links():
|
||||
|
||||
con = sqlite3.connect(DB_PATH)
|
||||
cur = con.cursor()
|
||||
try:
|
||||
cur.execute("begin")
|
||||
cur.execute('DELETE FROM links')
|
||||
|
||||
links = []
|
||||
data = request.json['links']
|
||||
|
||||
items = 'url', 'name', 'clicks', 'active'
|
||||
for i in range(len(data)):
|
||||
if not(all(e in data[i] for e in items)):
|
||||
return "Bad request, some items missing from link object", 400
|
||||
|
||||
links = []
|
||||
cur.execute("begin")
|
||||
cur.execute('DELETE FROM links')
|
||||
for i in range(len(data)):
|
||||
url = data[i]['url']
|
||||
name = data[i]['name']
|
||||
clicks = data[i]['clicks']
|
||||
|
@ -86,8 +88,7 @@ def update_links():
|
|||
cur.executemany('INSERT INTO links VALUES (?,?,?,?,?)', links)
|
||||
con.commit()
|
||||
con.close()
|
||||
regen_html()
|
||||
|
||||
regen_html(out_path)
|
||||
except Exception as e:
|
||||
cur.execute("rollback")
|
||||
con.close()
|
||||
|
|
|
@ -23,9 +23,9 @@ if cur.fetchone():
|
|||
raise Exception('Links table already exists.')
|
||||
else:
|
||||
cur.execute('''CREATE TABLE links (
|
||||
url text NOT NULL,
|
||||
name text NOT NULL,
|
||||
clicks int NOT NULL,
|
||||
url text NOT NULL,
|
||||
name text NOT NULL,
|
||||
clicks int NOT NULL,
|
||||
position int NOT NULL UNIQUE,
|
||||
active int NOT NULL,
|
||||
UNIQUE(url, name)
|
||||
|
|
14
build.bash
14
build.bash
|
@ -7,4 +7,16 @@ cd frontend/public
|
|||
NODE_ENV=production npx tailwindcss-cli@latest build index.in.css -o index.out.css
|
||||
cd ..
|
||||
npm run build && npm run export
|
||||
mv out ../build/frontend
|
||||
cd ..
|
||||
mv frontend/out build/frontend
|
||||
|
||||
# Backend
|
||||
cd backend
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue