Skip to content

Commit

Permalink
Add filter for docker prune with until-two-weeks-ago
Browse files Browse the repository at this point in the history
  • Loading branch information
stevleibelt committed Feb 14, 2025
1 parent 89f5e83 commit 1dbaf1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -952,18 +952,22 @@ function _exit_if_string_is_empty ()
#####
function _main ()
{
local PATH_TO_THIS_SCRIPT
local DATE_TWO_WEEKS_AGO

if docker info > /dev/null 2>&1;
then
DATE_TWO_WEEKS_AGO=$(date --date='-14 day' +%Y-%m-%d)
PATH_TO_THIS_SCRIPT=$(cd $(dirname "${BASH_SOURCE[0]}"); pwd)
cd "${PATH_TO_THIS_SCRIPT}" || exit 11
_echo_if_be_verbose "Pulling latest archlinux docker container"
docker pull archlinux:latest
exit_if_last_exit_code_is_not_zero ${?} "Could not execute following command: docker pull archlinux:latest"

_echo_if_be_verbose "Removing dangling containers and images"
docker container prune --filter "label=name=archlinux"
docker container prune --filter "label=name=archlinux" --filter "until=${DATE_TWO_WEEKS_AGO}"
exit_if_last_exit_code_is_not_zero ${?} "Could not execute following command: docker container prune --filter \"label=name=archlinux\""
docker image prune --filter "label=reference=archlinux"
docker image prune --filter "label=reference=archlinux" --filter "until=${DATE_TWO_WEEKS_AGO}"
exit_if_last_exit_code_is_not_zero ${?} "Could not execute following command: docker image prune --filter \"label=reference=archlinux\""

_echo_if_be_verbose "Starting build in dedicated docker container"
Expand All @@ -975,7 +979,6 @@ function _main ()
local BUILD_WAS_SUCCESSFUL
local CURRENT_WORKING_DIRECTORY
local ISO_FILE_PATH
local PATH_TO_THIS_SCRIPT
local PATH_TO_THE_DYNAMIC_DATA_DIRECTORY
local PATH_TO_THE_DISTRIBUTION_ENVIRONMENT_FILE
local PATH_TO_THE_OPTIONAL_ENVIRONMENT_FILE
Expand Down

0 comments on commit 1dbaf1a

Please sign in to comment.