Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed db start from dev-tools and removed py-docker-gadgets #393

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jobbergate-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This file keeps track of all notable changes to jobbergate-api
## Unreleased
- Changed internals to avoid committing to the database when a GET request is made
- Added extra settings to allow profiling and tracing on sentry
- Removed db-start from dev-tools


## 4.1.0a2 -- 2023-10-10
Expand Down
41 changes: 1 addition & 40 deletions jobbergate-api/dev_tools/db.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Provide commands for interacting with local databases."""
import json

import subprocess

import docker_gadgets
import typer
from loguru import logger

from alembic.command import revision as sqla_migrate
from alembic.command import upgrade as sqla_upgrade
from alembic.config import Config
from jobbergate_api.config import settings
from jobbergate_api.storage import build_db_url

app = typer.Typer()
Expand All @@ -23,43 +21,6 @@ def login(test: bool = typer.Option(False, help="Log into the test database.")):
subprocess.run(["pgcli", url])


@app.command()
def start(test: bool = typer.Option(False, help="Start a test database.")):
"""Start a local postgres database for local development."""
name = "dev-jobbergate-postgres"
kwargs = dict(
image="postgres:14.1",
env=dict(
POSTGRES_PASSWORD=settings.DATABASE_PSWD,
POSTGRES_DB=settings.DATABASE_NAME,
POSTGRES_USER=settings.DATABASE_USER,
),
ports={"5432/tcp": settings.DATABASE_PORT},
)
if test:
kwargs.update(
env=dict(
POSTGRES_PASSWORD=settings.TEST_DATABASE_PSWD,
POSTGRES_DB=settings.TEST_DATABASE_NAME,
POSTGRES_USER=settings.TEST_DATABASE_USER,
),
ports={"5432/tcp": settings.TEST_DATABASE_PORT},
tmpfs={"/var/lib/postgresql/data": "rw"},
)
name = "test-jobbergate-postgres"

logger.debug(f"Starting {name} with:\n {json.dumps(kwargs, indent=2)}")

docker_gadgets.start_service(name, **kwargs)


@app.command()
def start_all():
"""Start all local databases."""
start()
start(test=True)


@app.command()
def migrate(
message: str = typer.Option("Unlabeled migration", help="The message to attach to the migration."),
Expand Down
82 changes: 1 addition & 81 deletions jobbergate-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion jobbergate-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ nest_asyncio = "^1.3.3"
pgcli = "^3.1.0"
pre-commit = "^2.9.2"
psycopg2 = "^2.9.5"
py-docker-gadgets = "^0.1.3"
pyproject-flake8 = "^5.0.4"
pytest = "^7"
pytest-asyncio = "^0.21"
Expand Down
68 changes: 2 additions & 66 deletions jobbergate-docs/docs/source/developer_guide/dev_tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,71 +52,6 @@ poetry run dev-tools db --help
```


### The `start` subcommand

This command is used to start up a database in docker that is configured using the
values found in the execution environment for Jobbergate.

To start a development database, invoke this command:

```shell
poetry run dev-tools db start
```

Note that the values for the database name, host, port, and password will all be
gathered from the environment that the API is configured to use. The script should
produce some logging output that will indicate the status of the db:

```
2022-09-07 15:44:56.634 | DEBUG | dev_tools.db:start:57 - Starting dev-jobbergate-postgres with:
{
"image": "postgres:14.1",
"env": {
"POSTGRES_PASSWORD": "compose-db-pswd",
"POSTGRES_DB": "compose-db-name",
"POSTGRES_USER": "compose-db-user"
},
"ports": {
"5432/tcp": 5432
}
}
2022-09-07 15:44:56.634 | DEBUG | docker_gadgets.gadgets:start_service:19 - Starting service 'dev-jobbergate-postgres'
2022-09-07 15:44:56.642 | DEBUG | docker_gadgets.gadgets:start_service:26 - Retrieving external image for dev-jobbergate-postgres using postgres:14.1
2022-09-07 15:44:56.649 | DEBUG | docker_gadgets.helpers:get_image_external:43 - Pulling postgres:14.1 image (tag='14.1')
2022-09-07 15:45:03.190 | DEBUG | docker_gadgets.helpers:cleanup_container:13 - Checking for existing container: dev-jobbergate-postgres
2022-09-07 15:45:03.195 | DEBUG | docker_gadgets.helpers:cleanup_container:24 - No existing container found: dev-jobbergate-postgres
2022-09-07 15:45:03.196 | DEBUG | docker_gadgets.gadgets:start_service:31 - Checking if needed ports {'5432/tcp': 5432} are available
2022-09-07 15:45:03.217 | DEBUG | docker_gadgets.gadgets:start_service:34 - Starting container: dev-jobbergate-postgres
2022-09-07 15:45:03.647 | DEBUG | docker_gadgets.gadgets:start_service:48 - Started container: dev-jobbergate-postgres (<Container: e686e97595>)
```

In this example, the container name is `dev-jobbergate-postgres` and it is running in
the docker container referenced by `e686e97595` with the port 5432 mapped from
the host machine to the container.

!!!Note

This command is also very convenient for starting up a database for unit testing. To
do so, you need the `--test` flag to the command. When you run the unit tests suite,
it will use the database started by this command.


### The `start-all` subcommand

This command is just a convenient way of spinning up both a development database and a
test database in one command. It is equivalent to running the following two commands in
succession:

```shell
poetry run dev-tools db start
```


```shell
poetry run dev-tools db start --test
```


### The `login` subcommand

This command allows you to log in to the database that your Jobbergate API is configured
Expand Down Expand Up @@ -277,7 +212,8 @@ The JSON output will look something like:
## The `dev-server` subcommand

This command starts up a local development server for the Jobbergate API. It will
be created using the configuration set up in the environment settings.
be created using the configuration set up in the environment settings. This command is especially useful if
you want to run the API locally but connect to remote services such as a database and s3 hosted on AWS.

To start the server, run:

Expand Down