Skip to content

Commit

Permalink
wip: Allow to import an image from an archive #80
Browse files Browse the repository at this point in the history
  • Loading branch information
Christophe Nouguier committed Sep 25, 2019
1 parent 4c56181 commit fa16a3f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions kargo
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ kargo_build()
popd > /dev/null
}

kargo_import()
kargo_load()
{
kargo_read_configuration
# check whether an agument is provided
Expand All @@ -183,13 +183,24 @@ kargo_import()
rclone copyto $ARCHIVE /tmp/$LOCAL_ARCHIVE
ARCHIVE=/tmp/$LOCAL_ARCHIVE
fi
# import the archive
# load the archive
echo loading $ARCHIVE
local ARCHIVE_IMAGE_TAG=`docker load < $ARCHIVE`
# retrieve the source image and the source tag
local REGEXP="Loaded image: (.*):(.*)"
[[ "$ARCHIVE_IMAGE_TAG" =~ $REGEXP ]]
local ARCHIVE_IMAGE="${BASH_REMATCH[1]}"
local ARCHIVE_TAG="${BASH_REMATCH[2]}"
if [ "$ARCHIVE_IMAGE" == "" ] || [ "$ARCHIVE_TAG" == "" ]; then
echo error: an error has occured while loading archive \"$ARCHIVE\"
exit 1
fi
# tag and push the loaded image
local IMAGE_VAR=${1^^}_IMAGE
local IMAGE=${!IMAGE_VAR}
local TAG_VAR=${1^^}_TAG
local TAG=${!TAG_VAR}
echo importing $ARCHIVE
docker import $ARCHIVE $IMAGE:$TAG
docker tag $ARCHIVE_IMAGE:$ARCHIVE_TAG $IMAGE:$TAG
docker push $IMAGE:$TAG
}

Expand Down Expand Up @@ -218,7 +229,7 @@ kargo_deploy()
local SERVICE_ARCHIVE_NAME=${SERVICE_NAME}_ARCHIVE
local SERVICE_ARCHIVE=${!SERVICE_ARCHIVE_NAME}
if [ "$SERVICE_ARCHIVE" != "" ]; then
kargo_import $SERVICE
kargo_load $SERVICE
fi
local SERVICE_EXTENSION_NAME=${SERVICE_NAME}_EXTENSION
local SERVICE_EXTENSION=${!SERVICE_EXTENSION_NAME}
Expand Down Expand Up @@ -281,7 +292,7 @@ case $1 in
configure) kargo_configure;;
info) kargo_info;;
build) kargo_build "$2";;
import) kargo_import "$2";;
load) kargo_load "$2";;
deploy) kargo_deploy "$2";;
update) kargo_update "$2" "$3";;
remove) kargo_remove "$2";;
Expand Down

0 comments on commit fa16a3f

Please sign in to comment.