forked from hsos-ai-lab/agri-gaia-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup.sh
executable file
·35 lines (28 loc) · 1.23 KB
/
cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env bash
# SPDX-FileCopyrightText: 2024 University of Applied Sciences Osnabrück
# SPDX-FileContributor: Andreas Schliebitz
# SPDX-FileContributor: Henri Graf
# SPDX-FileContributor: Jonas Tüpker
# SPDX-FileContributor: Lukas Hesse
# SPDX-FileContributor: Maik Fruhner
# SPDX-FileContributor: Prof. Dr.-Ing. Heiko Tapken
# SPDX-FileContributor: Tobias Wamhof
#
# SPDX-License-Identifier: AGPL-3.0-or-later
docker compose down -v
compose_project_name="$(grep "^COMPOSE_PROJECT_NAME=" .env | cut -f 2 -d '=')"
containers=$(docker container ls -a --filter name="${compose_project_name}" -q)
[[ -n "${containers}" ]] && docker container rm "${containers}"
volumes=$(docker volume ls --filter name="${compose_project_name}" -q)
[[ -n "${volumes}" ]] && docker volume rm "${volumes}"
project_base_url="$(grep "^PROJECT_BASE_URL=" .env | cut -f 2 -d '=')"
if [[ -n "${project_base_url}" ]]; then
docker container ls -a --format "{{.ID}} {{.Image}}" \
| grep "registry.${project_base_url}" \
| awk '{print $1}' \
| xargs -I {} sh -c 'docker stop {} && docker rm {}'
docker image ls -a --format "{{.ID}} {{.Repository}}" \
| grep "registry.${project_base_url}" \
| awk '{print $1}' \
| xargs -I {} docker rmi -f {}
fi