Fix mysql connection and run parsing on container startup
This commit is contained in:
parent
309e0358f8
commit
22798c851b
|
@ -2,6 +2,7 @@
|
|||
FROM python:3.7-alpine
|
||||
|
||||
COPY backend /app
|
||||
COPY parser /app/parser
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
|
@ -12,6 +13,8 @@ RUN set -ex \
|
|||
libc-dev \
|
||||
musl-dev \
|
||||
libffi-dev \
|
||||
mariadb-dev \
|
||||
&& apk add --no-cache mariadb-connector-c \
|
||||
&& pip install --no-cache-dir pipenv \
|
||||
&& pipenv install --system --clear \
|
||||
&& apk del .build-deps \
|
||||
|
|
|
@ -10,6 +10,8 @@ django = "*"
|
|||
djangorestframework = "*"
|
||||
markdown = "*"
|
||||
djangorestframework-simplejwt = "*"
|
||||
gunicorn = "*"
|
||||
mysqlclient = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "a08b9adab76e6720d013fec10cc335a3a771bc09d385694eecbe7fe9cbbaca6c"
|
||||
"sha256": "f3b787be7658e88a80f6cb88c212265407e1a63b3d4fb9590f95c84814c74f97"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
|
@ -40,6 +40,14 @@
|
|||
"index": "pypi",
|
||||
"version": "==4.1.0"
|
||||
},
|
||||
"gunicorn": {
|
||||
"hashes": [
|
||||
"sha256:aa8e0b40b4157b36a5df5e599f45c9c76d6af43845ba3b3b0efe2c70473c2471",
|
||||
"sha256:fa2662097c66f920f53f70621c6c58ca4a3c4d3434205e608e121b5b3b71f4f3"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==19.9.0"
|
||||
},
|
||||
"markdown": {
|
||||
"hashes": [
|
||||
"sha256:c00429bd503a47ec88d5e30a751e147dcb4c6889663cd3e2ba0afe858e009baa",
|
||||
|
@ -48,6 +56,15 @@
|
|||
"index": "pypi",
|
||||
"version": "==3.0.1"
|
||||
},
|
||||
"mysqlclient": {
|
||||
"hashes": [
|
||||
"sha256:425e733b05e359a714d6007c0fc44582be66b63e5a3df0a50949274ae16f4bc6",
|
||||
"sha256:62e4770b6a797b9416bcf70488365b7d6b9c9066878108499c559293bb464380",
|
||||
"sha256:f257d250f2675d0ef99bd318906f3cfc05cef4a2f385ea695ff32a3f04b9f9a7"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.4.2.post1"
|
||||
},
|
||||
"pyjwt": {
|
||||
"hashes": [
|
||||
"sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e",
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
# Distributed under terms of the BSD-3-Clause license.
|
||||
#
|
||||
|
||||
python parser/parser.py
|
||||
python manage.py migrate
|
||||
gunicorn -w 4 --bind 0.0.0.0:80 perktree.wsgi:application
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import os
|
||||
|
||||
from os import listdir
|
||||
from os.path import isfile, join
|
||||
|
@ -7,7 +8,10 @@ from rest_framework.response import Response
|
|||
from rest_framework import authentication, permissions
|
||||
|
||||
|
||||
PERKS_DIR = '../static/perks'
|
||||
PERKS_DIR = os.environ.get('PERKS_DIR')
|
||||
|
||||
if not PERKS_DIR:
|
||||
PERKS_DIR = '../static/perks'
|
||||
|
||||
|
||||
def get_tree_list():
|
||||
|
|
|
@ -7,6 +7,8 @@ services:
|
|||
environment:
|
||||
MYSQL_ROOT_PASSWORD: perktree-root-password
|
||||
MYSQL_DATABASE: perktree
|
||||
volumes:
|
||||
./storage/db:/var/lib/mysql
|
||||
|
||||
frontend:
|
||||
build:
|
||||
|
@ -35,6 +37,7 @@ services:
|
|||
DB_PASSWORD: perktree-root-password
|
||||
DB_HOST: db
|
||||
DB_PORT: 3306
|
||||
PERKS_DIR: /app/static/perks
|
||||
links:
|
||||
- db
|
||||
|
||||
|
|
|
@ -10,6 +10,13 @@ server {
|
|||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location /django-static {
|
||||
proxy_pass http://perktree-backend;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
location / {
|
||||
root /app;
|
||||
try_files $uri $uri/ /index.html;
|
||||
|
|
|
@ -14,7 +14,11 @@ import os
|
|||
import re
|
||||
|
||||
|
||||
OUTPUT_DIR = f'{os.path.abspath(os.path.dirname(__file__))}/../static/perks'
|
||||
PERKS_DIR = os.environ.get('PERKS_DIR')
|
||||
|
||||
if not PERKS_DIR:
|
||||
PERKS_DIR = '../static/perks'
|
||||
|
||||
INPUT_FILE = f'{os.path.abspath(os.path.dirname(__file__))}/perks_all.tsv'
|
||||
|
||||
ability_pattern = re.compile(r'Strength|Dexterity|Constitution|Intelligence|Wisdom|Charisma \d+\+', re.IGNORECASE)
|
||||
|
@ -128,9 +132,9 @@ def output_transform(trees):
|
|||
|
||||
|
||||
def write_json(trees, split):
|
||||
os.makedirs(OUTPUT_DIR, exist_ok=True)
|
||||
os.makedirs(PERKS_DIR, exist_ok=True)
|
||||
for tree, data in trees.items():
|
||||
with open(f'{OUTPUT_DIR}/{tree}.json', 'w') as jsonfile:
|
||||
with open(f'{PERKS_DIR}/{tree}.json', 'w') as jsonfile:
|
||||
json.dump(data, jsonfile)
|
||||
|
||||
|
||||
|
|
Reference in New Issue