diff options
author | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-01-03 17:59:31 +0000 |
---|---|---|
committer | Maxim Kuvyrkov <maxim.kuvyrkov@linaro.org> | 2021-01-03 17:59:31 +0000 |
commit | 7654f42e2d36c49b388abc653c5017170eea3ce1 (patch) | |
tree | bfd4ae634249d9730432670c25df7a0bf7aa4eed | |
parent | 50781c0bdac875936dab082d1043f7f4a3317546 (diff) |
Docker image pull/use: Fix and improve
Change-Id: Ieb39c841151533d7553786f78f80fbb7a62857e2
-rwxr-xr-x | start-container-docker.sh | 10 | ||||
-rwxr-xr-x | tcwg-cleanup-stale-containers.sh | 6 | ||||
-rwxr-xr-x | tcwg-start-container.sh | 12 |
3 files changed, 20 insertions, 8 deletions
diff --git a/start-container-docker.sh b/start-container-docker.sh index bc3f6145..f306c34e 100755 --- a/start-container-docker.sh +++ b/start-container-docker.sh @@ -217,8 +217,8 @@ image=linaro/ci-${container_arch}-tcwg-build-ubuntu:${distro} stamp_dir=/home/shared/docker if ! [ -d "$stamp_dir" ]; then - sudo mkdir -p "$stamp_dir" - sudo chmod 0777 "$stamp_dir" + sudo mkdir -p "$stamp_dir" || mkdir -p "$stamp_dir" + sudo chmod 0777 "$stamp_dir" || chmod 0777 "$stamp_dir" fi # We use two stamp files per image: @@ -237,8 +237,8 @@ pull_image=false # that any change to master docker images will be deployed within a day. pull_if_older_than=$(($(date +%s) - 1*24*60*60)) # Use negative comparison to handle non-existent stamp files. -if ! [ "$(stat -c %Z "$image_stamp.pull" 2>/dev/null)" \ - -gt $pull_if_older_than ]; then +if ! [ "$(stat -c %Z "$image_stamp.pull")" \ + -gt $pull_if_older_than ] 2>/dev/null; then pull_image=true fi @@ -403,7 +403,7 @@ if $ssh_info; then fi # Update the time of image use, so that we don't remove the image in -# tcwg-cleanup-stale-containers . +# tcwg-cleanup-stale-containers. rm -f "$image_stamp.use" touch "$image_stamp.use" diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index fe626621..cc89a01e 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -184,10 +184,10 @@ if $cleanup_images; then image_stamp="$stamp_dir/$(echo "$image" | tr "/:" "_")" remove_if_not_used_since=$(($(date +%s) - 3*24*60*60)) # Use negative comparison to handle non-existent stamp files. - if ! [ "$(stat -c %Z "$image_stamp.use" 2>/dev/null)" \ - -gt $remove_if_not_used_since ]; then + if ! [ "$(stat -c %Z "$image_stamp.use")" \ + -gt $remove_if_not_used_since ] 2>/dev/null; then # Untag the image. - docker rmi "$image" + docker rmi -f "$image" fi done # Prune untagged images. diff --git a/tcwg-start-container.sh b/tcwg-start-container.sh index 5c227871..2c0efb2c 100755 --- a/tcwg-start-container.sh +++ b/tcwg-start-container.sh @@ -53,6 +53,18 @@ docker run --rm $image start.sh > "$start_sh" bash "$start_sh" "$@" rm "$start_sh" +# See start-container-docker.sh for background on image stamp files. +# Note that there is no need to track pull requests, since these happen +# once a day anyway. +stamp_dir=/home/shared/docker +if ! [ -d "$stamp_dir" ]; then + sudo mkdir -p "$stamp_dir" || mkdir -p "$stamp_dir" + sudo chmod 0777 "$stamp_dir" || chmod 0777 "$stamp_dir" +fi +image_stamp="$stamp_dir/$(echo "$image" | tr "/:" "_")" +rm -f "$image_stamp.use" +touch "$image_stamp.use" + if [ x"$rm_cnt" != x"" ]; then # With the new container started delete the old one. # Note that if both old and new containers need an exclusive resource |