dockerized newsite mariadb setup

This commit is contained in:
2024-08-03 08:37:27 -07:00
parent fe2dcd23f1
commit cdeb87184a
12 changed files with 332 additions and 104 deletions

3
backend/.dockerignore Normal file
View File

@ -0,0 +1,3 @@
venv
migrations

View File

@ -1,5 +1,7 @@
# syntax=docker/dockerfile:1.4
FROM python:3-alpine AS builder
FROM python:3-slim-bookworm AS builder
RUN apt update && apt install -y libmariadb-dev gcc
WORKDIR /code
COPY requirements.txt /code
@ -9,7 +11,7 @@ RUN target=/root/.cache/pip \
# Need to make this explicit as part of expansion, no migrations or venv
COPY . .
ENV FLASK_APP app.py
#ENV FLASK_APP app.py
# This might be scary to leave on
#ENV FLASK_ENV development

View File

@ -8,6 +8,7 @@
## pip:
mariadb may take extra work: gcc, libmariadb-dev
```
pip install flask
pip install python-dotenv
@ -17,6 +18,7 @@ pip install flask-migrate
pip install flask-login
pip install email-validator
pip install pydenticon
pip install mariadb
...
pip freeze > requirements.txt
```

View File

@ -1,42 +0,0 @@
## Workflow:
- should work with flask run and dockerfile build
- local dev
- local pip install
- record versionless pips manually here
- pip freeze snapshots into project requirements
- docker build copies frozen requirements
## pip:
```
pip install flask
pip install python-dotenv
pip install flask-wtf
pip install flask-sqlalchemy
pip install flask-migrate
pip install flask-login
pip install email-validator
pip freeze > requirements.txt
```
## db cheat:
```
flask db migrate -m "users table"
flask db upgrade
flask db downgrade [base]
flask db upgrade
```
## build:
Dockerfile needs explicitly defined copies for:
- app
- config
- project dir
- requirements
## notes:
- environment comes through project env passes through compose
- keep env untracked but templated
- no dotenv here, dotflaskenv goes into image

View File

@ -5,7 +5,7 @@ basedir = os.path.abspath(os.path.dirname(__file__))
class Config:
SECRET_KEY = os.environ.get('FLASK_SECRET_KEY') or 'flasksk'
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'zapp.db')
#SQLALCHEMY_DATABASE_URI = 'mysql://flasku:' + os.environ.get('MYSQL_PASSWORD') + '@db:3306/flask'
#SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'zapp.db')
SQLALCHEMY_DATABASE_URI = 'mariadb+mariadbconnector://flasku:' + os.environ.get('MYSQL_PASSWORD') + '@db:3306/flask'

View File

@ -21,3 +21,4 @@ SQLAlchemy==2.0.31
typing_extensions==4.12.2
Werkzeug==3.0.3
WTForms==3.1.2
mariadb