Skip to content

Commit

Permalink
Improve usage of docker.up
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSuperiorStanislav committed Aug 9, 2024
1 parent 4124224 commit afcd373
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
11 changes: 10 additions & 1 deletion .vscode/project-related-words.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
alembicbackup
alembicload
alembicwait
autoupdate
buildpack
buildpacks
celeryrun
celerysend
charliermarsh
compilemessages
createsuperuser
dbshell
djangobackup
djangoload
djangowait
fastapirun
FURB
htmlcov
Khlud
Expand All @@ -18,10 +27,10 @@ paketobuildpacks
Pylance
Renderable
resetdb
RUF
runserver
saritasa
snok
Stanislav
startapp
TASKNUMBER
RUF
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ We follow [Semantic Versions](https://semver.org/).

## unreleased

- Make wait_for_database as task
- Make `docker.up` check for compose file
- Make `pytest.run`, `celery.run` use `docker.up`

## 1.1.1

- Make default for `default_entry` for `K8SDefaultSettings` use absolute path
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Collection of [invoke](https://www.pyinvoke.org/) commands used by Saritasa
* [django.backup-local-db](#djangobackup-local-db)
* [django.backup-remote-db](#djangobackup-remote-db)
* [django.load-remote-db](#djangoload-remote-db)
* [django.wait-for-database](#djangowait-for-database)
* [fastapi](#fastapi)
* [fastapi.run](#fastapirun)
* [alembic](#alembic)
Expand All @@ -67,6 +68,7 @@ Collection of [invoke](https://www.pyinvoke.org/) commands used by Saritasa
* [alembic.backup-local-db](#alembicbackup-local-db)
* [alembic.backup-remote-db](#alembicbackup-remote-db)
* [alembic.load-remote-db](#alembicload-remote-db)
* [alembic.wait-for-database](#alembicwait-for-database)
* [celery](#celery)
* [celery.run](#celeryrun)
* [celery.send-task](#celerysend-task)
Expand Down Expand Up @@ -260,10 +262,10 @@ Clone repo or pull latest changes to specified repo

Command for creating copies of a file with git blame history saving.

Original script written in bash:
https://dev.to/deckstar/how-to-git-copy-copying-files-while-keeping-git-history-1c9j
Original script written in bash [here](https://dev.to/deckstar/how-to-git-copy-copying-files-while-keeping-git-history-1c9j)

Usage:

```shell
inv git.blame-copy <path to original file> <path to copy>,<path to copy>...
```
Expand Down Expand Up @@ -301,14 +303,18 @@ The `action` variable stores the header of the intermediate action.
If no task found in branch, then will be empty

Default values for templates:

* `copy_commit_template`:

```python
"[automated-commit]: {action}\n\n"
"copy: {original_path}\n"
"to:\n* {destination_paths}\n\n"
"{project_task}"
```

* `copy_init_message_template`:

```python
"Copy {original_path} to:\n"
"* {destination_paths}\n\n"
Expand Down Expand Up @@ -567,6 +573,10 @@ Settings:
* `app_template_directory` path to app template in project template (Default: `.`)
* `apps_path` path to apps folder in project (Default: `apps`)

#### django.wait-for-database

Launch docker compose and wait for database connection.

### fastapi

#### fastapi.run
Expand Down Expand Up @@ -727,6 +737,10 @@ Settings:
}
```

#### alembic.wait-for-database

Launch docker compose and wait for database connection.

### celery

#### celery.run
Expand Down
1 change: 1 addition & 0 deletions saritasa_invocations/alembic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import _config, db, db_k8s, docker, k8s, printing, python


@invoke.task
def wait_for_database(context: invoke.Context) -> None:
"""Ensure that database is up and ready to accept connections.
Expand Down
1 change: 1 addition & 0 deletions saritasa_invocations/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def run(
config = _config.Config.from_context(context).celery
match python.get_python_env():
case python.PythonEnv.LOCAL:
docker.up(context)
context.run(
config.local_cmd.format(
app=config.app,
Expand Down
1 change: 1 addition & 0 deletions saritasa_invocations/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from . import _config, db, db_k8s, docker, k8s, printing, python, system


@invoke.task
def wait_for_database(context: invoke.Context) -> None:
"""Ensure that database is up and ready to accept connections.
Expand Down
10 changes: 9 additions & 1 deletion saritasa_invocations/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,15 @@ def stop_containers(
def up(context: invoke.Context) -> None:
"""Bring up main containers and start them."""
config = _config.Config.from_context(context)
if not config.docker.main_containers:
if not any(
pathlib.Path(compose_file).exists()
for compose_file in (
"compose.yaml",
"compose.yml",
"docker-compose.yaml",
"docker-compose.yml",
)
):
return
up_containers(
context,
Expand Down
3 changes: 2 additions & 1 deletion saritasa_invocations/pytest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import invoke

from . import _config, printing, python
from . import _config, docker, printing, python


@invoke.task
Expand All @@ -10,6 +10,7 @@ def run(
params: str = "",
) -> None:
"""Run pytest in `path` with `params`."""
docker.up(context)
printing.print_success("Running PyTest")
pytest_entry = _config.Config.from_context(context).python.pytest_entry
python.run(context, f"{pytest_entry} {path} {params}")

0 comments on commit afcd373

Please sign in to comment.