Support four database engines in Flask React template
This commit is contained in:
@@ -10,6 +10,6 @@ python3 templates/flask-react/generate.py "My Application" /tmp/my-application
|
||||
|
||||
Add `--git-init` to initialize a local `main` branch. GitHub is not required. The generator refuses existing destinations and destinations inside Forge. It installs no packages, contacts no provider, and performs no deployment. It leaves profile selection to `bortstack-context`/F007; F005 will later orchestrate template and profile selection together.
|
||||
|
||||
The generated project has safe local/example configuration: SQLite is the development default, email is disabled, branding and project name are neutral, and Compose has no mandatory external SWAG network. Resend code, MySQL, Docker/nginx, an optional SWAG sample, and a GitHub CI/deployment example remain available. The GitHub workflow stays under `optional/github/` in Forge and is not generated as an active workflow. Enabling external services requires separate project decisions and configuration. See `boilerplate/docs/OPTIONAL_SERVICES.md`.
|
||||
The generated project has safe local/example configuration: SQLite is the development and default Compose database, email is disabled, branding and project name are neutral, and Compose has no mandatory external database or SWAG network. PostgreSQL, MySQL, and MariaDB are selectable through `ops/databases/` overlays. Resend code, Docker/nginx, an optional SWAG sample, and a GitHub CI/deployment example remain available. The GitHub workflow stays under `optional/github/` in Forge and is not generated as an active workflow. Enabling external services requires separate project decisions and configuration. See `boilerplate/docs/OPTIONAL_SERVICES.md`.
|
||||
|
||||
Linux generation was exercised. The Python generator is platform-neutral, but Windows generation and the full generated-project runtime matrix remain to be verified on Windows. The source package is a migration snapshot, not a live dependency on `/home/rob/projects/flask-react-auth-base`.
|
||||
|
||||
@@ -26,7 +26,7 @@ cd react && npm run lint && npm test && npm run build
|
||||
docker compose --env-file .env.example config --quiet
|
||||
```
|
||||
|
||||
Playwright browser tests are optional and require `npx playwright install chromium` followed by `npm run test:e2e`. Docker is optional for local development. `.env.example` contains local/example values only; do not use its placeholder passwords in production or commit a populated `.env`.
|
||||
Playwright browser tests are optional and require `npx playwright install chromium` followed by `npm run test:e2e`. Docker is optional for local development. Default Compose uses a persistent SQLite volume; PostgreSQL, MySQL, and MariaDB are opt-in through `ops/databases/` overlays. `.env.example` contains local/example values only; do not use database example passwords in production or commit a populated `.env`.
|
||||
|
||||
## Project context
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
Local development needs no GitHub, production host, SWAG network, Resend account, or Cloudflare routing. Email delivery starts disabled. To enable it, choose and verify a project-specific sender/domain and contact destination, set `RESEND_API_KEY`, `EMAIL_FROM`, `CONTACT_EMAIL`, and `EMAIL_DELIVERY_ENABLED=true` in an untracked environment, then test account and contact flows. The code currently implements Resend outbound delivery; inbound routing is a separate operator choice.
|
||||
|
||||
`docker-compose.yml` provides MySQL, API, and nginx services with loopback diagnostic ports. It does not require an external reverse-proxy network. `ops/swag/` includes an optional Compose overlay and proxy sample for projects using SWAG; adapt networking and TLS separately before hosting. The Forge package retains a GitHub Actions CI/deployment example under `optional/github/`, but generation does not install an active workflow. Copying or enabling any deployment workflow is a separate project decision. Never use `.env.example` placeholder passwords or secrets in production.
|
||||
`docker-compose.yml` provides API and nginx services with loopback diagnostic ports and a persistent SQLite volume. It does not require an external database or reverse-proxy network. `ops/databases/` contains separate PostgreSQL, MySQL, and MariaDB Compose overlays plus safe example environment files. Select one engine per deployment; set `SQLALCHEMY_DATABASE_URI` explicitly outside Compose, or let the chosen overlay supply it. Replace example passwords in an untracked private env file and URL-encode reserved password characters in any database URL. Apply migrations against the selected engine before starting the API. `ops/swag/` includes an optional Compose overlay and proxy sample; adapt networking and TLS separately before hosting. The Forge package retains a GitHub Actions CI/deployment example under `optional/github/`, but generation does not install an active workflow. Copying or enabling any deployment workflow is a separate project decision. Never use example passwords or secrets in production.
|
||||
|
||||
Before production, choose a host and repository provider, configure external secrets, verify migrations/backup/rollback, review authentication and email policy, and run the project's required tests. Generation performs none of these actions.
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# Project overview
|
||||
|
||||
__PROJECT_NAME__ is a newly generated Flask/React application foundation. Product purpose, intended users, ownership, branding, and deployment target are not yet selected. React/Vite lives under `react/`; Flask/SQLAlchemy and migrations live under `api/`. Development defaults to SQLite and disabled email. MySQL, Docker/nginx, Resend outbound email, SWAG, and GitHub automation are optional project choices. Generated code has no Forge runtime dependency.
|
||||
__PROJECT_NAME__ is a newly generated Flask/React application foundation. Product purpose, intended users, ownership, branding, and deployment target are not yet selected. React/Vite lives under `react/`; Flask/SQLAlchemy and migrations live under `api/`. SQLite is the local/default database; PostgreSQL, MySQL, and MariaDB are supported through explicit SQLAlchemy URLs and optional Compose overlays. Email is disabled by default. Docker/nginx, Resend outbound email, SWAG, and GitHub automation are optional project choices. Generated code has no Forge runtime dependency.
|
||||
|
||||
@@ -9,7 +9,9 @@ from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parent
|
||||
TOKEN_FILES = (".env.example", "docker-compose.yml", "react/index.html",
|
||||
"react/src/config/site.js", "react/src/components/Logo/Logo.jsx")
|
||||
"react/src/config/site.js", "react/src/components/Logo/Logo.jsx",
|
||||
"ops/databases/postgres.env.example", "ops/databases/mysql.env.example",
|
||||
"ops/databases/mariadb.env.example")
|
||||
|
||||
|
||||
def generate(name, destination, git_init=False):
|
||||
|
||||
@@ -4,11 +4,7 @@ APP_SLUG=__APP_SLUG__
|
||||
REGISTRATION_MODE=open
|
||||
SECRET_KEY=replace-with-a-long-random-value
|
||||
|
||||
MYSQL_DATABASE=__DATABASE_NAME__
|
||||
MYSQL_USER=__DATABASE_NAME__
|
||||
MYSQL_PASSWORD=replace-with-a-strong-password
|
||||
MYSQL_ROOT_PASSWORD=replace-with-a-different-strong-password
|
||||
SQLALCHEMY_DATABASE_URI=mysql+pymysql://__DATABASE_NAME__:replace-with-a-strong-password@mysql:3306/__DATABASE_NAME__
|
||||
SQLALCHEMY_DATABASE_URI=sqlite:///mydatabase.sqlite
|
||||
SQLALCHEMY_ECHO=false
|
||||
SQLALCHEMY_TRACK_MODIFICATIONS=false
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ RUN pip install --no-cache-dir -r ./config/requirements.txt \
|
||||
&& groupadd --gid 10001 app \
|
||||
&& useradd --uid 10001 --gid app --create-home --shell /usr/sbin/nologin app
|
||||
COPY . /app
|
||||
RUN install -d -o app -g app /app/instance
|
||||
|
||||
ENV HOME=/home/app \
|
||||
PYTHONDONTWRITEBYTECODE=1 \
|
||||
|
||||
@@ -2,6 +2,7 @@ Flask==3.1.3
|
||||
Flask-Migrate==4.1.0
|
||||
Flask-SQLAlchemy==3.1.1
|
||||
PyMySQL==1.2.0
|
||||
psycopg[binary]==3.3.9
|
||||
flask-cors==6.0.5
|
||||
python-dotenv==1.2.3
|
||||
Flask-HTTPAuth==4.8.1
|
||||
|
||||
@@ -1,23 +1,4 @@
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.4
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:?MYSQL_DATABASE must be set}
|
||||
MYSQL_USER: ${MYSQL_USER:?MYSQL_USER must be set}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?MYSQL_PASSWORD must be set}
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?MYSQL_ROOT_PASSWORD must be set}
|
||||
volumes:
|
||||
- db:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "mysqladmin ping -h localhost -uroot -p$$MYSQL_ROOT_PASSWORD --silent"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 30s
|
||||
networks:
|
||||
- internal
|
||||
|
||||
api:
|
||||
image: ${API_IMAGE:-__APP_SLUG__-api:local}
|
||||
build:
|
||||
@@ -34,9 +15,8 @@ services:
|
||||
- ALL
|
||||
env_file:
|
||||
- ${APP_ENV_FILE:-.env.example}
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
volumes:
|
||||
- sqlite_data:/app/instance
|
||||
healthcheck:
|
||||
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:5000/api/health/ready')"]
|
||||
interval: 15s
|
||||
@@ -77,4 +57,4 @@ networks:
|
||||
internal: true
|
||||
|
||||
volumes:
|
||||
db:
|
||||
sqlite_data:
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# Opt-in MariaDB service. Supply ops/databases/mariadb.env.example or a private env file.
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb:11
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MARIADB_DATABASE: ${MARIADB_DATABASE:?set MARIADB_DATABASE}
|
||||
MARIADB_USER: ${MARIADB_USER:?set MARIADB_USER}
|
||||
MARIADB_PASSWORD: ${MARIADB_PASSWORD:?set MARIADB_PASSWORD}
|
||||
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:?set MARIADB_ROOT_PASSWORD}
|
||||
volumes:
|
||||
- mariadb_data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "healthcheck.sh --connect --innodb_initialized"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 30s
|
||||
networks:
|
||||
- internal
|
||||
api:
|
||||
depends_on:
|
||||
mariadb:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
SQLALCHEMY_DATABASE_URI: mysql+pymysql://${MARIADB_USER}:${MARIADB_PASSWORD}@mariadb:3306/${MARIADB_DATABASE}
|
||||
|
||||
volumes:
|
||||
mariadb_data:
|
||||
@@ -0,0 +1,4 @@
|
||||
MARIADB_DATABASE=__DATABASE_NAME__
|
||||
MARIADB_USER=__DATABASE_NAME__
|
||||
MARIADB_PASSWORD=replace-with-a-private-password
|
||||
MARIADB_ROOT_PASSWORD=replace-with-a-different-private-password
|
||||
@@ -0,0 +1,29 @@
|
||||
# Opt-in MySQL service. Supply ops/databases/mysql.env.example or a private env file.
|
||||
services:
|
||||
mysql:
|
||||
image: mysql:8.4
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MYSQL_DATABASE: ${MYSQL_DATABASE:?set MYSQL_DATABASE}
|
||||
MYSQL_USER: ${MYSQL_USER:?set MYSQL_USER}
|
||||
MYSQL_PASSWORD: ${MYSQL_PASSWORD:?set MYSQL_PASSWORD}
|
||||
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD:?set MYSQL_ROOT_PASSWORD}
|
||||
volumes:
|
||||
- mysql_data:/var/lib/mysql
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "mysqladmin ping -h localhost -uroot -p$$MYSQL_ROOT_PASSWORD --silent"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
start_period: 30s
|
||||
networks:
|
||||
- internal
|
||||
api:
|
||||
depends_on:
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
SQLALCHEMY_DATABASE_URI: mysql+pymysql://${MYSQL_USER}:${MYSQL_PASSWORD}@mysql:3306/${MYSQL_DATABASE}
|
||||
|
||||
volumes:
|
||||
mysql_data:
|
||||
@@ -0,0 +1,4 @@
|
||||
MYSQL_DATABASE=__DATABASE_NAME__
|
||||
MYSQL_USER=__DATABASE_NAME__
|
||||
MYSQL_PASSWORD=replace-with-a-private-password
|
||||
MYSQL_ROOT_PASSWORD=replace-with-a-different-private-password
|
||||
@@ -0,0 +1,27 @@
|
||||
# Opt-in PostgreSQL service. Supply ops/databases/postgres.env.example or a private env file.
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:15
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_DB: ${POSTGRES_DB:?set POSTGRES_DB}
|
||||
POSTGRES_USER: ${POSTGRES_USER:?set POSTGRES_USER}
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
|
||||
interval: 5s
|
||||
timeout: 3s
|
||||
retries: 12
|
||||
networks:
|
||||
- internal
|
||||
api:
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
SQLALCHEMY_DATABASE_URI: postgresql+psycopg://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB}
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
@@ -0,0 +1,3 @@
|
||||
POSTGRES_DB=__DATABASE_NAME__
|
||||
POSTGRES_USER=__DATABASE_NAME__
|
||||
POSTGRES_PASSWORD=replace-with-a-private-password
|
||||
@@ -13,7 +13,8 @@
|
||||
},
|
||||
"development_commands": ["cd api && flask --app api.py run", "cd react && npm run dev"],
|
||||
"validation_commands": ["cd api && pytest", "cd react && npm run lint && npm test && npm run build", "docker compose --env-file .env.example config --quiet"],
|
||||
"optional_capabilities": ["Resend outbound email", "MySQL production persistence", "Docker/nginx hosting", "SWAG integration", "GitHub Actions publishing/deployment"],
|
||||
"database_engines": ["SQLite", "PostgreSQL", "MySQL", "MariaDB"],
|
||||
"optional_capabilities": ["Resend outbound email", "PostgreSQL/MySQL/MariaDB production persistence", "Docker/nginx hosting", "SWAG integration", "GitHub Actions publishing/deployment"],
|
||||
"initial_context": "Fresh AGENTS.md and five docs records are generated; profile selection is delegated to bortstack-context/F007.",
|
||||
"platforms": ["Linux", "Windows via Python; application dependencies and Docker must be installed separately"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user