Merge pull request #60 from mcataford/build/reduce-taskfile-backend-complexity

build: reduce taskfile backend complexity
This commit is contained in:
Marc 2023-12-18 00:05:39 -05:00 committed by GitHub
commit 5874c00685
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 56 deletions

View file

@ -1,82 +1,56 @@
version: '3' version: '3'
env: env:
BE_BASE_PATH: "/{{ .TASKFILE_DIR }}/backend" VENV_PATH: "{{ .TASKFILE_DIR }}/.venv"
VENV_PATH: "{{ .BE_BASE_PATH }}/.venv"
VENV_BIN: "{{ .VENV_PATH }}/bin" VENV_BIN: "{{ .VENV_PATH }}/bin"
VENV_ACTIVATE: "{{ .VENV_BIN }}/activate"
DOTENV: "{{ .BE_BASE_PATH }}/.env"
APP_CONTAINER_NAME: "rotini_app" APP_CONTAINER_NAME: "rotini_app"
DB_CONTAINER_NAME: "rotini_db"
tasks: tasks:
bootstrap: bootstrap:
internal: true internal: true
cmds: cmd: . script/bootstrap
- . script/bootstrap
sources: sources:
- "{{ .BE_BASE_PATH }}/pyproject.toml" - ./pyproject.toml
generates: generates:
- "{{ .VENV_PATH }}/*" - "{{ .VENV_PATH }}/*"
dir: backend
lint: lint:
desc: "Lints /backend using black + pylint." desc: "Checks /backend for linting and formatting problems."
deps: [bootstrap] deps: [bootstrap]
cmds: cmd: . script/format.sh
- "{{ .VENV_BIN }}/black . --check"
- "{{ .VENV_BIN }}/pylint ./rotini"
dir: backend
dotenv: dotenv:
- ../backend-test.env - ../backend-test.env
lintfix: lintfix:
desc: "Lints and fixes /backend using black + pylint." desc: "Resolves linting and formatting problems in /backend."
deps: [bootstrap] deps: [bootstrap]
cmds: cmd: . script/format.sh
- "{{ .VENV_BIN }}/black ." env:
- "{{ .VENV_BIN }}/pylint ./rotini" FIX: 1
dir: backend
dotenv: dotenv:
- ../backend-test.env - ../backend-test.env
test: test:
desc: "Run the test suites." desc: "Run the test suites."
deps: [bootstrap] deps: [bootstrap]
cmd: . script/test cmd: . script/test
dir: backend
dotenv: dotenv:
- ../backend-test.env - ../backend-test.env
start:
desc: "Starts the backend application."
deps: [docker-build]
cmd: docker run -d -p 8000:8000 --name {{ .APP_CONTAINER_NAME }} {{ .CLI_ARGS }} --add-host docker.host.internal:host-gateway --env-file ../../backend.env rotini:dev
dir: backend/rotini
stop:
desc: "Stops the backend application."
cmd: docker rm -f {{ .APP_CONTAINER_NAME }}
logs:
desc: "Shortcut to Docker container logs"
cmd: docker logs {{ .APP_CONTAINER_NAME }} -f
start-db:
desc: "Provisions a local Postgres database."
dotenv:
- "{{ .DOTENV }}"
cmd: . script/provision-db
dir: backend
migrate:
desc: "Applies migrations. Usage: be:migrate -- <up|down>"
deps: [bootstrap]
env:
PYTHONPATH: '..'
ROTINI_MIGRATE: 1
dotenv:
- "{{ .DOTENV }}"
cmd: "{{ .VENV_BIN }}/python migrate.py {{ .CLI_ARGS }}"
dir: backend/rotini/migrations
lock-deps: lock-deps:
desc: "Locks production and development dependencies" desc: "Locks production and development dependencies"
deps: [bootstrap] deps: [bootstrap]
cmd: . script/requirements-lock cmd: . script/requirements-lock
dir: backend docker:start:
docker-build: desc: "Starts the backend application."
deps: [build]
cmd: . script/start.sh
dotenv:
- ../backend.env
docker:stop:
desc: "Stops the backend application."
cmd: docker rm -f {{ .APP_CONTAINER_NAME }} {{ .DB_CONTAINER_NAME }}
docker:logs:
desc: "Shortcut to Docker container logs"
cmd: docker logs {{ .APP_CONTAINER_NAME }} -f
docker:build:
desc: "Builds a docker image from /backend" desc: "Builds a docker image from /backend"
cmd: docker build --build-arg PYTHON_VERSION=$(cat .python-version) -t rotini:dev . cmd: . script/build.sh
dir: backend

View file

@ -3,5 +3,7 @@ version: '3'
# See environment-specific taskfiles for commands about # See environment-specific taskfiles for commands about
# that environment. # that environment.
includes: includes:
be: ./Taskfile.backend.yml be:
taskfile: ./Taskfile.backend.yml
dir: backend
fe: ./Taskfile.frontend.yml fe: ./Taskfile.frontend.yml

View file

@ -1,2 +1,7 @@
DJANGO_SECRET_KEY="notakey" DJANGO_SECRET_KEY="notakey"
JWT_SIGNING_SECRET="notasecret" JWT_SIGNING_SECRET="notasecret"
DB_HOST="rotini_db"
DB_USER="postgres"
DB_PASSWORD="postgres"
DB_PORT=5432
DB_NAME="postgres"

View file

@ -64,11 +64,11 @@ WSGI_APPLICATION = "base.wsgi.application"
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.postgresql_psycopg2", "ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": "postgres", "NAME": os.environ["DB_NAME"],
"USER": "postgres", "USER": os.environ["DB_USER"],
"PASSWORD": "test", "PASSWORD": os.environ["DB_PASSWORD"],
"HOST": "docker.host.internal", "HOST": os.environ["DB_HOST"],
"PORT": "5432", "PORT": os.environ["DB_PORT"],
} }
} }

3
backend/script/build.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
docker build -t rotini:dev .

10
backend/script/format.sh Normal file
View file

@ -0,0 +1,10 @@
#!/bin/bash
if [ "$FIX" != "1" ]; then
$VENV_BIN/black . --check
$VENV_BIN/pylint ./rotini
return
fi
$VENV_BIN/black .
$VENV_BIN/pylint ./rotini

23
backend/script/start.sh Normal file
View file

@ -0,0 +1,23 @@
#!/bin/bash
docker run \
--name $DB_CONTAINER_NAME \
-e POSTGRES_PASSWORD=$DATABASE_PASSWORD \
-e POSTGRES_USER=$DATABASE_USER \
-e POSTGRES_DB=$DATABASE_NAME \
-v $DATABASE_STORAGE_PATH:/var/lib/postgresql/data \
-p 5432:5432 \
-d \
postgres:15.4
until [ -n "$(docker exec $DB_CONTAINER_NAME pg_isready | grep accepting)" ]; do
echo "Waiting for DB to come alive..."
sleep 0.1;
done;
docker run \
--detach \
--publish 8000:8000 \
--name $APP_CONTAINER_NAME \
--env-file ../backend.env \
rotini:dev