build: reduce taskfile backend complexity #60
7 changed files with 73 additions and 56 deletions
|
@ -1,82 +1,56 @@
|
|||
version: '3'
|
||||
|
||||
env:
|
||||
BE_BASE_PATH: "/{{ .TASKFILE_DIR }}/backend"
|
||||
VENV_PATH: "{{ .BE_BASE_PATH }}/.venv"
|
||||
VENV_PATH: "{{ .TASKFILE_DIR }}/.venv"
|
||||
VENV_BIN: "{{ .VENV_PATH }}/bin"
|
||||
VENV_ACTIVATE: "{{ .VENV_BIN }}/activate"
|
||||
DOTENV: "{{ .BE_BASE_PATH }}/.env"
|
||||
APP_CONTAINER_NAME: "rotini_app"
|
||||
DB_CONTAINER_NAME: "rotini_db"
|
||||
|
||||
tasks:
|
||||
bootstrap:
|
||||
internal: true
|
||||
cmds:
|
||||
- . script/bootstrap
|
||||
cmd: . script/bootstrap
|
||||
sources:
|
||||
- "{{ .BE_BASE_PATH }}/pyproject.toml"
|
||||
- ./pyproject.toml
|
||||
generates:
|
||||
- "{{ .VENV_PATH }}/*"
|
||||
dir: backend
|
||||
lint:
|
||||
desc: "Lints /backend using black + pylint."
|
||||
desc: "Checks /backend for linting and formatting problems."
|
||||
deps: [bootstrap]
|
||||
cmds:
|
||||
- "{{ .VENV_BIN }}/black . --check"
|
||||
- "{{ .VENV_BIN }}/pylint ./rotini"
|
||||
dir: backend
|
||||
cmd: . script/format.sh
|
||||
dotenv:
|
||||
- ../backend-test.env
|
||||
lintfix:
|
||||
desc: "Lints and fixes /backend using black + pylint."
|
||||
desc: "Resolves linting and formatting problems in /backend."
|
||||
deps: [bootstrap]
|
||||
cmds:
|
||||
- "{{ .VENV_BIN }}/black ."
|
||||
- "{{ .VENV_BIN }}/pylint ./rotini"
|
||||
dir: backend
|
||||
cmd: . script/format.sh
|
||||
env:
|
||||
FIX: 1
|
||||
dotenv:
|
||||
- ../backend-test.env
|
||||
test:
|
||||
desc: "Run the test suites."
|
||||
deps: [bootstrap]
|
||||
cmd: . script/test
|
||||
dir: backend
|
||||
dotenv:
|
||||
- ../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:
|
||||
desc: "Locks production and development dependencies"
|
||||
deps: [bootstrap]
|
||||
cmd: . script/requirements-lock
|
||||
dir: backend
|
||||
docker-build:
|
||||
docker:start:
|
||||
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"
|
||||
cmd: docker build --build-arg PYTHON_VERSION=$(cat .python-version) -t rotini:dev .
|
||||
dir: backend
|
||||
cmd: . script/build.sh
|
||||
|
||||
|
|
|
@ -3,5 +3,7 @@ version: '3'
|
|||
# See environment-specific taskfiles for commands about
|
||||
# that environment.
|
||||
includes:
|
||||
be: ./Taskfile.backend.yml
|
||||
be:
|
||||
taskfile: ./Taskfile.backend.yml
|
||||
dir: backend
|
||||
fe: ./Taskfile.frontend.yml
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
DJANGO_SECRET_KEY="notakey"
|
||||
JWT_SIGNING_SECRET="notasecret"
|
||||
DB_HOST="rotini_db"
|
||||
DB_USER="postgres"
|
||||
DB_PASSWORD="postgres"
|
||||
DB_PORT=5432
|
||||
DB_NAME="postgres"
|
||||
|
|
|
@ -64,11 +64,11 @@ WSGI_APPLICATION = "base.wsgi.application"
|
|||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
||||
"NAME": "postgres",
|
||||
"USER": "postgres",
|
||||
"PASSWORD": "test",
|
||||
"HOST": "docker.host.internal",
|
||||
"PORT": "5432",
|
||||
"NAME": os.environ["DB_NAME"],
|
||||
"USER": os.environ["DB_USER"],
|
||||
"PASSWORD": os.environ["DB_PASSWORD"],
|
||||
"HOST": os.environ["DB_HOST"],
|
||||
"PORT": os.environ["DB_PORT"],
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
backend/script/build.sh
Normal file
3
backend/script/build.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
docker build -t rotini:dev .
|
10
backend/script/format.sh
Normal file
10
backend/script/format.sh
Normal 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
23
backend/script/start.sh
Normal 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
|
Reference in a new issue