Skip to content

Commit

Permalink
app: Update template-application-flask to version 0.2.0.post29.dev0…
Browse files Browse the repository at this point in the history
…+2dba7c0
  • Loading branch information
doshitan committed Jan 13, 2025
1 parent 9fc163b commit 2f24e18
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 83 deletions.
15 changes: 0 additions & 15 deletions .github/pull_request_template.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
paths:
- app/**
- Makefile
- .github/workflows/ci-openapi.yml
- .github/workflows/ci-app-openapi.yml

defaults:
run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-app.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI - App
name: CI - app

on:
push:
Expand Down
20 changes: 0 additions & 20 deletions .gitignore

This file was deleted.

5 changes: 4 additions & 1 deletion .template-application-flask/app.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
_commit: f715d8d
# Changes here will be overwritten by Copier
_commit: v0.2.0-29-g2dba7c0
_src_path: https://github.com/navapbc/template-application-flask
app_local_port: 8080
app_name: app
15 changes: 0 additions & 15 deletions README.md

This file was deleted.

File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# needs to be called `release` in order to integrate with the repo's
# top-level Makefile
FROM python:3.13-slim AS base
# See /docs/app/README.md#Upgrading Python
# for details on upgrading your Python version
# See docs for details on upgrading your Python version

# Install poetry, the package manager.
# https://python-poetry.org
Expand Down
6 changes: 3 additions & 3 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Constants
##################################################

APP_NAME := main-app
APP_NAME := app

# Adding this to the end of a script that outputs JSON will convert
# it to a readable format with timestamps and color-coding.
Expand Down Expand Up @@ -118,8 +118,8 @@ check: format-check lint test
init-db: start-db db-migrate

start-db:
docker compose up --detach main-db
./bin/wait-for-local-db.sh
docker compose up --detach $(APP_NAME)-db
DB_NAME=$(APP_NAME)-db ./bin/wait-for-local-db.sh

## Destroy current DB, setup new one
db-recreate: clean-volumes init-db
Expand Down
10 changes: 7 additions & 3 deletions app/bin/wait-for-local-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,23 @@ NO_COLOR='\033[0m'
MAX_WAIT_TIME=30 # seconds
WAIT_TIME=0

DB_NAME="${DB_NAME:=${PGDATABASE}}"

DOCKER_DB_SERVICE_NAME="${DOCKER_DB_SERVICE_NAME:=database}"

# Use pg_isready to wait for the DB to be ready to accept connections
# We check every 3 seconds and consider it failed if it gets to 30+
# https://www.postgresql.org/docs/current/app-pg-isready.html
until pg_isready -h localhost -d main-db -q;
until pg_isready -h localhost -d "${DB_NAME}" -q;
do
echo "waiting on Postgres DB to initialize..."
sleep 3

WAIT_TIME=$(($WAIT_TIME+3))
if [ $WAIT_TIME -gt $MAX_WAIT_TIME ]
then
echo -e "${RED}ERROR: Database appears to not be starting up, running \"docker logs main-db\" to troubleshoot.${NO_COLOR}"
docker logs main-db
echo -e "${RED}ERROR: Database appears to not be starting up, running \"docker logs ${DOCKER_DB_SERVICE_NAME}\" to troubleshoot.${NO_COLOR}"
docker logs "${DOCKER_DB_SERVICE_NAME}"
exit 1
fi
done
Expand Down
5 changes: 2 additions & 3 deletions app/docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# run with `docker compose -f`
# combines ports and env vars with the main docker-compose.yml main-app service
# combines ports and env vars with the main docker-compose.yml app service
services:
main-app:
app:
build:
context: ./
target: dev
args:
- RUN_UID=${RUN_UID:-4000}
- RUN_USER=${RUN_USER:-app}
container_name: main-app
env_file: local.env
command: [
"poetry", "run", "python", "-m", "debugpy",
Expand Down
3 changes: 1 addition & 2 deletions app/docker-compose.override.yml.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
services:

main-app:
app:
env_file:
- local.env
- .env
17 changes: 6 additions & 11 deletions app/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
services:

main-db:
app-db:
image: postgres:16-alpine
container_name: main-db
command: postgres -c "log_lock_waits=on" -N 1000 -c "fsync=off"
environment:
POSTGRES_PASSWORD: secret123
# Set user to app to match user from template-infra (https://github.com/navapbc/template-infra)
# This is also needed for the initial migration that alters defaut privileges to grant
# table privileges to the app user (see /app/src/db/migrations/versions/2023_08_10_default_table_privileges.py)
# table privileges to the app user (see src/db/migrations/versions/2023_08_10_default_table_privileges.py)
POSTGRES_USER: app
ports:
- "5432:5432"
volumes:
- dbdata:/var/lib/postgresql/data
- app-dbdata:/var/lib/postgresql/data

main-app:
app:
build:
context: ./
target: dev
args:
- RUN_UID=${RUN_UID:-4000}
- RUN_USER=${RUN_USER:-app}
command: ["poetry", "run", "flask", "--app", "src.app", "run", "--host", "0.0.0.0", "--port", "8080", "--reload"]
container_name: main-app
env_file:
- path: ./local.env
required: true
Expand All @@ -34,9 +31,7 @@ services:
volumes:
- ./:/app
depends_on:
- main-db
- app-db

volumes:
dbdata:


app-dbdata:
6 changes: 3 additions & 3 deletions app/local.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Local environment variables
# Used by docker-compose and it can be loaded
# by calling load_local_env_vars() from app/src/util/local.py
# by calling load_local_env_vars() from src/util/local.py
#
# To override values for your own personal local development
# create an override.env file in the same directory.
Expand Down Expand Up @@ -51,7 +51,7 @@ API_AUTH_TOKEN=LOCAL_AUTH_12345678
############################

# Set DB_HOST to localhost if accessing a non-dockerized database
DB_HOST=main-db
DB_HOST=app-db
DB_NAME=app
DB_USER=app
DB_SCHEMA=public
Expand All @@ -71,7 +71,7 @@ HIDE_SQL_PARAMETER_LOGS=TRUE
# committing them. Set these in your shell
# by doing `export AWS_ACCESS_KEY_ID=whatever`
# if you are running the app directly, or
# in your `app/.env` if you are running the
# in your `override.env` if you are running the
# app in a Docker container
AWS_ACCESS_KEY_ID=DO_NOT_SET_HERE
AWS_SECRET_ACCESS_KEY=DO_NOT_SET_HERE
Expand Down
3 changes: 1 addition & 2 deletions app/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ packages = [{ include = "src" }]
authors = ["Nava Engineering <[email protected]>"]

[tool.poetry.dependencies]
# See /docs/app/README.md#Upgrading Python
# for details on upgrading your Python version
# See docs for details on upgrading your Python version
python = "~3.13"
SQLAlchemy = {version = "^2.0.21", extras = ["mypy"]}
alembic = "^1.12.0"
Expand Down
2 changes: 1 addition & 1 deletion docs/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ The API can be run in debug mode that allows for remote attach debugging (curren
- First create a file `./vscode/launch.json` - as shown below. (Default name of `Python: Remote Attach`)

- Start the server in debug mode via `make start-debug` or `make start-debug run-logs`.
- This will start the `main-app` service with port 5678 exposed.
- This will start the `app` service with port 5678 exposed.

- The server will start in waiting mode, waiting for you to attach the debugger (see `/src/app.py`) before continuing to run.

Expand Down

0 comments on commit 2f24e18

Please sign in to comment.