Compare commits
3 commits
78602c4ef9
...
58fac81dd9
Author | SHA1 | Date | |
---|---|---|---|
58fac81dd9 | |||
4eb0203b2d | |||
ea855dc311 |
7 changed files with 39 additions and 28 deletions
21
.env
21
.env
|
@ -1,17 +1,22 @@
|
|||
APP_HOST=0.0.0.0
|
||||
APP_PORT=8000
|
||||
|
||||
# Generate a strong secret key
|
||||
# Generate 2 strong secret keys
|
||||
#
|
||||
# On Linux: tr -dc A-Za-z0-9_- </dev/urandom | head -c 44
|
||||
# With Python: import secrets; secrets.token_urlsafe(32)
|
||||
# In Linux terminal:
|
||||
# tr -dc A-Za-z0-9_- </dev/urandom | head -c 44
|
||||
# Or in Python:
|
||||
# import secrets
|
||||
# print(secrets.token_urlsafe(32))
|
||||
#
|
||||
# If this variable is not set,
|
||||
# the key is generated automatically
|
||||
#SECRET_KEY=secret
|
||||
# If these variables are not set,
|
||||
# the keys are generated automatically
|
||||
#
|
||||
#SESSION_KEY=secret
|
||||
#CSRF_KEY=secret
|
||||
|
||||
DB_HOST=${REPO_NAME_SNAKE}_db
|
||||
DB_HOST=${REPO_NAME_KEBAB}-db
|
||||
DB_PORT=3306
|
||||
DB_USER=${REPO_NAME_SNAKE}
|
||||
DB_PASSWORD=password
|
||||
DB_PASSWORD=password # Generate a password using the same method
|
||||
DB_DATABASE=${REPO_NAME_SNAKE}
|
||||
|
|
2
.env_db
2
.env_db
|
@ -1,5 +1,5 @@
|
|||
MYSQL_PORT=3306
|
||||
MYSQL_RANDOM_ROOT_PASSWORD=true
|
||||
MYSQL_USER=${REPO_NAME_SNAKE}
|
||||
MYSQL_PASSWORD=password
|
||||
MYSQL_PASSWORD=password # Must be the same as in .env
|
||||
MYSQL_DATABASE=${REPO_NAME_SNAKE}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
DEBUG=true
|
||||
SECRET_KEY=debug
|
||||
SESSION_KEY=debug
|
||||
CSRF_KEY=debug
|
||||
|
||||
APP_HOST=127.0.0.1
|
||||
APP_PORT=8000
|
||||
|
|
8
Makefile
8
Makefile
|
@ -2,10 +2,12 @@ APP_HOST ?= 0.0.0.0
|
|||
APP_PORT ?= 8000
|
||||
|
||||
dev:
|
||||
python3 -m dotenv -f version_code run \
|
||||
python3 -m dotenv -f .env_debug run \
|
||||
make cmd-dev
|
||||
|
||||
prod:
|
||||
python3 -m dotenv -f version_code run \
|
||||
python3 -m gunicorn \
|
||||
-w 4 -k uvicorn.workers.UvicornWorker \
|
||||
-b $${APP_HOST}:$${APP_PORT} main:app
|
||||
|
@ -43,8 +45,8 @@ cmd-dev:
|
|||
|
||||
cmd-docker-build:
|
||||
docker build \
|
||||
-t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:latest \
|
||||
-t ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:$${VERSION} .
|
||||
-t ${REPO_OWNER_LOWER}/${REPO_NAME_KEBAB}:latest \
|
||||
-t ${REPO_OWNER_LOWER}/${REPO_NAME_KEBAB}:$${VERSION} .
|
||||
|
||||
cmd-docker-push:
|
||||
docker push -a ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}
|
||||
docker push -a ${REPO_OWNER_LOWER}/${REPO_NAME_KEBAB}
|
||||
|
|
|
@ -35,7 +35,9 @@ corresponding to your database structure
|
|||
as explained below ([Structure > Database](#database))
|
||||
7. Check if `Makefile`, `Dockerfile`, `docker-compose.yml` are correct
|
||||
8. Run the formatter and linters (`make format`, then `make check`)
|
||||
9. Edit the `version_code` file if needed,
|
||||
9. Open `.env` and `.env_db`, generate secret keys and the database password
|
||||
as explained in the comment above `SESSION_KEY=`
|
||||
10. Edit the `version_code` file if needed,
|
||||
build a docker image and [publish](#publishing-app) it
|
||||
|
||||
### Makefile
|
||||
|
@ -61,6 +63,8 @@ Make commands:
|
|||
loaded only in docker-compose by default
|
||||
- `.env_db` is a config for MySQL/MariaDB server,
|
||||
also loaded only in docker-compose for the mariadb container
|
||||
- `version` contains only one variable, your application version code;
|
||||
change it whatever you want or leave `1.0.0`
|
||||
#### The main config loaded by `app/common.py`:
|
||||
- `templates_dir`, `static_dir` contain the paths
|
||||
to templates and static files directories correspondingly
|
||||
|
|
|
@ -14,6 +14,7 @@ static_dir = str(file_dir.parent / 'static')
|
|||
|
||||
# Main configuration
|
||||
class Settings(BaseSettings):
|
||||
version: str = '1.0.0'
|
||||
debug: bool = False
|
||||
session_key: str = 'secret'
|
||||
csrf_key: str = 'secret'
|
||||
|
|
|
@ -3,35 +3,33 @@ version: "3"
|
|||
services:
|
||||
|
||||
app:
|
||||
image: ${REPO_OWNER_LOWER}/${REPO_NAME_SNAKE}:latest
|
||||
container_name: ${REPO_NAME_SNAKE}
|
||||
image: ${REPO_OWNER_LOWER}/${REPO_NAME_KEBAB}:latest
|
||||
container_name: ${REPO_NAME_KEBAB}-app
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "8080:8000"
|
||||
links:
|
||||
- database
|
||||
env_file: .env
|
||||
depends_on:
|
||||
database:
|
||||
condition: service_healthy
|
||||
|
||||
database:
|
||||
image: mariadb:latest
|
||||
container_name: ${REPO_NAME_SNAKE}_db
|
||||
image: linuxserver/mariadb:latest
|
||||
container_name: ${REPO_NAME_KEBAB}-db
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
#- "./database:/var/lib/mysql"
|
||||
- "db_data:/var/lib/mysql"
|
||||
- "database:/var/lib/mysql"
|
||||
env_file: .env_db
|
||||
healthcheck:
|
||||
test: sh -c "mysqladmin ping -u$$$$MYSQL_USER -p$$$$MYSQL_PASSWORD"
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 20
|
||||
# Uncomment if needed
|
||||
#healthcheck:
|
||||
# test: sh -c "mysqladmin ping -u$$$$MYSQL_USER -p$$$$MYSQL_PASSWORD"
|
||||
# interval: 2s
|
||||
# timeout: 3s
|
||||
# retries: 20
|
||||
|
||||
# Comment or remove these lines and
|
||||
# edit `volumes` in services->database
|
||||
# if you are going to store
|
||||
# your DB in a directory
|
||||
volumes:
|
||||
db_data:
|
||||
database:
|
||||
|
|
Loading…
Add table
Reference in a new issue