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

add sidecar_container() #67

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft

Conversation

NiklasRosenstein
Copy link
Contributor

@NiklasRosenstein NiklasRosenstein commented Jul 3, 2023

Sidecar containers are containers that are run alongside other tasks, and can stay active in the background the entire
time. The development workflow or integration tests of your project may require that certain Docker containers run in
the background, such as a database or a web server. Kraken provides a way to run these containers alongside your tasks
using the {@PyLink kraken.std.docker.sidecar_container} function.

from kraken.std.docker import sidecar_container
from kraken.std.python import pytest

sidecar_container(
    name="postgres",
    image="postgres:latest",
    ports=["5432:5432"],
    env={"POSTGRES_PASSWORD": "postgres"},
)

pytest(tests_dir="src").depends_on("postgres.start")

This example will start a Postgres container before running the tests. The depends_on argument ensures that the
Postgres container is started before the tests are run. The start suffix is added to the task name. The function
will also generate a postgres.stop task that you can run to stop the container via the CLI.

$ kraken run :postgres.start

Start build

> :postgres.start PENDING
1d3e0c9d2ccf5f60f82f179e1340fbfaaeda398c0ee0167b34cd8b9ee6ba51ac
> :postgres.start SUCCEEDED (Container kraken.sidecar-container.postgres started)

Build summary

  :postgres.start SUCCEEDED (Container kraken.sidecar-container.postgres started) [0.866s]

$ docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS          PORTS                    NAMES
e40cc9fc9ff3   postgres:latest   "docker-entrypoint.s…"   14 seconds ago   Up 13 seconds   0.0.0.0:5432->5432/tcp   kraken.sidecar-container.postgres

$ kraken run :postgres.stop

Start build

> :postgres.stop PENDING
kraken.sidecar-container.postgres
> :postgres.stop SUCCEEDED (Container kraken.sidecar-container.postgres stopped)

Build summary

  :postgres.stop SUCCEEDED (Container kraken.sidecar-container.postgres stopped) [0.493s]

Todo

  • Fix warning when running postgres.start

    [07/03/23 18:02:43] WARNING  BackgroundTask.teardown() did not get called on task ":postgres.start". This may cause some issues, such as an error during serialization or task.py:601
                                zombie processes.                                                                                                                                       
    

NiklasRosenstein and others added 5 commits July 3, 2023 17:56
…n()` is not called when the task has not returned `TaskStatusType.STARTED`. This was expected when the task returned a different task status, but the logged warning did not delinate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add feature to declare sidecar containers for tests and development
1 participant