#!/usr/bin/env bash SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd) . "$SCRIPT_PATH/common.sh" cd "$(dirname "$0")"/../ || exit 1 # Check Mark if [ -f ./.mark.image ]; then log_warn "Docker images already prepared" log_warn "If you want to re-prepare the images, please remove the file $(pwd)/.mark.image" exit 1 fi log_info "Preparing image..." log_info "Checking $DOCKER - $($DOCKER --version)" # Full if [ -f ./tmp/ubuntu-full.tar.gz ]; then log_info "Importing Full Image" gzip -d -c ./tmp/ubuntu-full.tar.gz | $DOCKER load || (log_error "Import Full Image failed" && exit 1) else log_info "Pulling Full Image" if ! $DOCKER pull git.0x7f.app/woj/ubuntu-full:latest; then log_warn "Pull failed, building from scratch" log_info "Building Full Image" $DOCKER build -t git.0x7f.app/woj/ubuntu-full:latest -f scripts/ubuntu-full.Dockerfile . || (log_error "Build Full Image failed" && exit 1) fi fi # Tiny if [ -f ./tmp/ubuntu-tiny.tar.gz ]; then log_info "Importing Tiny Image" gzip -d -c ./tmp/ubuntu-tiny.tar.gz | $DOCKER load || (log_error "Import Tiny Image failed" && exit 1) else log_info "Pulling Tiny Image" if ! $DOCKER pull git.0x7f.app/woj/ubuntu-run:latest; then log_warn "Pull failed, building from scratch" log_info "Building Tiny Image" $DOCKER build -t git.0x7f.app/woj/ubuntu-run:latest -f scripts/ubuntu-run.Dockerfile . || (log_error "Build Tiny Image failed" && exit 1) fi fi # Mark if [ "$1" == "save" ]; then log_info "Saving Images" $DOCKER save git.0x7f.app/woj/ubuntu-full:latest | gzip -9 >./tmp/ubuntu-full.tar.gz $DOCKER save git.0x7f.app/woj/ubuntu-run:latest | gzip -9 >./tmp/ubuntu-tiny.tar.gz else touch ./.mark.image fi log_info "Done"