Skip to content

Commit

Permalink
Skip downloading when image exists hitachienergy#536
Browse files Browse the repository at this point in the history
  • Loading branch information
to-bar committed Oct 9, 2019
1 parent 1c5d055 commit fa3cc3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash -eu

ENABLED_REPOS_FILE=/var/tmp/enabled-system-repos.txt
ENABLED_REPOS_LIST_FILE=/var/tmp/enabled-system-repos.txt

if [ ! -f "$ENABLED_REPOS_FILE" ]; then
if [ ! -f "$ENABLED_REPOS_LIST_FILE" ]; then
# 'yum repoinfo' or 'yum repolist -v' not used since they may require Internet access, even with --cacheonly
yum --cacheonly repolist enabled | awk '/^$/ {next}; /repo id/ {f=1; next}; /^repolist/ {f=0}; f {sub(/\/.*/,""); print $1}' > $ENABLED_REPOS_FILE
yum --cacheonly repolist enabled | awk '/^$/ {next}; /repo id/ {f=1; next}; /^repolist/ {f=0}; f {sub(/\/.*/,""); print $1}' > $ENABLED_REPOS_LIST_FILE
fi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# VERSION 1.0.0
# VERSION 1.0.1

set -euo pipefail

Expand Down Expand Up @@ -89,11 +89,16 @@ download_image() {
local repo_basename=$(basename -- "$repository")
local dest_path="${dest_dir}/${repo_basename}-${tag}.tar"

[[ ! -f $dest_path ]] || remove_file "$dest_path"

echol "Downloading image: $image"
$SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag ||
exit_with_error "skopeo failed, command was: $SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag"
if [[ -f $dest_path ]]; then
echol "Image file: "$dest_path" already exists. Skipping..."
else
# use temporary file for downloading to be safe from sudden interruptions (network, ctrl+c)
local tmp_file_path=$(mktemp)
local skopeo_cmd="$SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag"
echol "Downloading image: $image"
{ $skopeo_cmd && mv $tmp_file_path $dest_path; } ||
exit_with_error "skopeo failed, command was: $skopeo_cmd && mv $tmp_file_path $dest_path"
fi
}

# params: <dest_dir> <package_1> ... [package_N]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# VERSION 1.0.0
# VERSION 1.0.1

set -euo pipefail

Expand Down Expand Up @@ -89,11 +89,16 @@ download_image() {
local repo_basename=$(basename -- "$repository")
local dest_path="${dest_dir}/${repo_basename}-${tag}.tar"

[[ ! -f $dest_path ]] || remove_file "$dest_path"

echol "Downloading image: $image"
$SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag ||
exit_with_error "skopeo failed, command was: $SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag"
if [[ -f $dest_path ]]; then
echol "Image file: "$dest_path" already exists. Skipping..."
else
# use temporary file for downloading to be safe from sudden interruptions (network, ctrl+c)
local tmp_file_path=$(mktemp)
local skopeo_cmd="$SKOPEO_BIN --insecure-policy copy docker://$image_name docker-archive:$dest_path:$repository:$tag"
echol "Downloading image: $image"
{ $skopeo_cmd && mv $tmp_file_path $dest_path; } ||
exit_with_error "skopeo failed, command was: $skopeo_cmd && mv $tmp_file_path $dest_path"
fi
}

# params: <dest_dir> <package_1> ... [package_N]
Expand Down

0 comments on commit fa3cc3c

Please sign in to comment.