Commit 7bbff06b authored by Adrian DC's avatar Adrian DC
Browse files

ci(gitlab-ci): preserve only existing Docker images after 'images'

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parent 540ed6f6
Loading
Loading
Loading
Loading
+27 −0
Changes for .gitlab-ci.yml: 27 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -130,6 +130,14 @@ images:
        rename=$(echo "${base_rename}" | cut -d'|' -f2 | tr -d ' ')
        image="${REGISTRY_HOST}/${REGISTRY_NAMESPACE}/${REGISTRY_PROJECT}/${rename:-${base}}"
        if [ -z "${IMAGE}" ] || echo "${image}" | grep -q "${IMAGE}"; then
          base_local='false'
          image_local='false'
          if docker images -q "${base}" 2>/dev/null | grep -q '.'; then
            base_local='true'
          fi
          if docker images -q "${image}" 2>/dev/null | grep -q '.'; then
            image_local='true'
          fi
          echo ' '
          echo " [INFO] Pull: ${base}"
          echo ' '
@@ -139,8 +147,13 @@ images:
          echo " [INFO] Push: ${image}"
          echo ' '
          docker push "${image}" || true
          if [ ! -z "${CI_LOCAL:-}" ] && [ "${base_local}" = 'false' ]; then
            docker rmi "${base}" >/dev/null || true
          fi
          if [ ! -z "${CI_LOCAL:-}" ] && [ "${image_local}" = 'false' ]; then
            docker rmi "${image}" >/dev/null || true
          fi
        fi
      done
    # Prepare project images
    - |
@@ -164,6 +177,14 @@ images:
        base="${REGISTRY_HOST}/${REGISTRY_NAMESPACE}/${REGISTRY_PROJECT}/${base}"
        image="${REGISTRY_HOST}/${REGISTRY_NAMESPACE}/${REGISTRY_PROJECT}/${REGISTRY_PROJECT}:${name}"
        if [ -z "${IMAGE}" ] || echo "${image}" | grep -q "${IMAGE}"; then
          base_local='false'
          image_local='false'
          if docker images -q "${base}" 2>/dev/null | grep -q '.'; then
            base_local='true'
          fi
          if docker images -q "${image}" 2>/dev/null | grep -q '.'; then
            image_local='true'
          fi
          echo ' '
          echo " [INFO] Pull: ${image}"
          echo ' '
@@ -180,6 +201,12 @@ images:
          echo " [INFO] Push: ${image}"
          echo ' '
          docker push "${image}" || true
          if [ ! -z "${CI_LOCAL:-}" ] && [ "${base_local}" = 'false' ]; then
            docker rmi "${base}" >/dev/null || true
          fi
          if [ ! -z "${CI_LOCAL:-}" ] && [ "${image_local}" = 'false' ]; then
            docker rmi "${image}" >/dev/null || true
          fi
        fi
      done
  rules: