Skip to content

Commit

Permalink
fix: clean up old images when running admyral up
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgrittner committed Sep 27, 2024
1 parent 503daea commit 9b58452
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions admyral/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
is_docker_running,
get_docker_compose_cmd,
list_running_docker_containers,
clean_up_old_images,
)
from admyral.config.config import get_local_postgres_volume
from admyral import __version__
Expand Down Expand Up @@ -78,6 +79,14 @@ def up() -> None:
# figure out the path of the docker-compose directory
docker_compose_dir_path = _get_docker_compose_dir_path()

# clean up old images
click.echo("\nCleaning up old images...")
for repository_name in ["admyralai/web", "admyralai/api", "admyralai/worker"]:
clean_up_old_images(
repository_name=repository_name, current_version=__version__
)
click.echo("Done.")

command = get_docker_compose_cmd()
command.append("up")
command.append("-d")
Expand Down
11 changes: 11 additions & 0 deletions admyral/utils/docker_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,14 @@ def list_running_docker_containers() -> list[str]:
docker_client = DockerClient.from_env()
containers = docker_client.containers.list()
return [container.name for container in containers]


def clean_up_old_images(
repository_name: str, current_version: str | None = None
) -> None:
docker_client = DockerClient.from_env()
images = docker_client.images.list(name=repository_name)
for image in images:
if current_version and current_version in image.tags:
continue
image.remove()
6 changes: 3 additions & 3 deletions deploy/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ services:
volumes:
- ${POSTGRES_VOLUME_PATH}:/var/lib/postgresql/data

admyral-api:
api:
container_name: admyral-api
# build:
# context: ../..
Expand Down Expand Up @@ -63,14 +63,14 @@ services:
# dockerfile: ../docker/Dockerfile.web
image: admyralai/web:${ADMYRAL_VERSION}
depends_on:
admyral-api:
api:
condition: service_healthy
networks:
- admyral-network
ports:
- 3000:3000
environment:
- ADMYRAL_API_BASE_URL=http://admyral-api:8000
- ADMYRAL_API_BASE_URL=http://api:8000

worker:
container_name: admyral-worker
Expand Down

0 comments on commit 9b58452

Please sign in to comment.