2020-06-23 12:02:45 -04:00
|
|
|
#!/usr/bin/env bash
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
############# Deploy Container to DockerHub @admiralawkbar #####################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# NOTES: This script is used to upload a Dockerfile to DockerHub
|
2020-06-18 15:02:54 -04:00
|
|
|
# under the GitHub organization
|
2019-11-08 09:31:16 -05:00
|
|
|
# Its based on being built from a GitHub Action, but could be easily updated
|
|
|
|
# To be ran in a different medium.
|
|
|
|
#
|
2020-06-21 19:41:24 -04:00
|
|
|
# PRE-Requirements:
|
2019-11-08 09:31:16 -05:00
|
|
|
# - Dockerfile
|
|
|
|
# - System with Docker installed
|
|
|
|
# - Global variables met
|
|
|
|
|
|
|
|
###########
|
|
|
|
# Globals #
|
|
|
|
###########
|
2020-07-01 17:40:40 -04:00
|
|
|
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace
|
|
|
|
DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub
|
|
|
|
DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub
|
|
|
|
GPR_USERNAME="${GPR_USERNAME}" # Username to login to GitHub package registry
|
|
|
|
GPR_TOKEN="${GPR_TOKEN}" # Password to login to GitHub package registry
|
|
|
|
REGISTRY="${REGISTRY}" # What registry to upload | <GPR> or <Docker>
|
|
|
|
IMAGE_REPO="${IMAGE_REPO}" # Image repo to upload the image
|
|
|
|
IMAGE_VERSION="${IMAGE_VERSION}" # Version to tag the image
|
|
|
|
DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded
|
|
|
|
MAJOR_TAG='' # Major tag version if we need to update it
|
|
|
|
UPDATE_MAJOR_TAG=0 # Flag to deploy the major tag version as well
|
2019-11-08 09:31:16 -05:00
|
|
|
|
2020-08-04 17:42:39 -04:00
|
|
|
#########################
|
|
|
|
# Source Function Files #
|
|
|
|
#########################
|
|
|
|
# shellcheck source=/dev/null
|
|
|
|
source "${GITHUB_WORKSPACE}/lib/log.sh" # Source the function script(s)
|
|
|
|
|
2019-11-08 09:31:16 -05:00
|
|
|
################################################################################
|
|
|
|
############################ FUNCTIONS BELOW ###################################
|
|
|
|
################################################################################
|
|
|
|
################################################################################
|
|
|
|
#### Function Header ###########################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
Header() {
|
2020-07-30 15:15:42 -04:00
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "---- GitHub Actions Upload image to [${REGISTRY}] ----"
|
|
|
|
info "-------------------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function ValidateInput ####################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
ValidateInput() {
|
2019-11-08 09:31:16 -05:00
|
|
|
# Need to validate we have the basic variables
|
|
|
|
################
|
|
|
|
# Print header #
|
|
|
|
################
|
2020-07-30 15:15:42 -04:00
|
|
|
info "----------------------------------------------"
|
|
|
|
info "Gathering variables..."
|
|
|
|
info "----------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
|
2020-06-23 13:06:12 -04:00
|
|
|
#############################
|
2019-11-08 09:31:16 -05:00
|
|
|
# Validate GITHUB_WORKSPACE #
|
2020-06-23 13:06:12 -04:00
|
|
|
#############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${GITHUB_WORKSPACE}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [GITHUB_WORKSPACE]!"
|
|
|
|
fatal "[${GITHUB_WORKSPACE}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[GITHUB_WORKSPACE]${F[B]}, value:${F[W]}[${GITHUB_WORKSPACE}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
2020-06-23 13:06:12 -04:00
|
|
|
#####################
|
|
|
|
# Validate REGISTRY #
|
|
|
|
#####################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${REGISTRY}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [REGISTRY]!"
|
|
|
|
fatal "[${REGISTRY}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[REGISTRY]${F[B]}, value:${F[W]}[${REGISTRY}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
2020-06-23 13:06:12 -04:00
|
|
|
#####################################################
|
|
|
|
# See if we need values for GitHub package Registry #
|
|
|
|
#####################################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [[ ${REGISTRY} == "GPR" ]]; then
|
2020-06-23 13:06:12 -04:00
|
|
|
#########################
|
|
|
|
# Validate GPR_USERNAME #
|
|
|
|
#########################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${GPR_USERNAME}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [GPR_USERNAME]!"
|
|
|
|
fatal "[${GPR_USERNAME}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[GPR_USERNAME]${F[B]}, value:${F[W]}[${GPR_USERNAME}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Validate GPR_TOKEN #
|
|
|
|
######################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${GPR_TOKEN}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [GPR_TOKEN]!"
|
|
|
|
fatal "[${GPR_TOKEN}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[GPR_TOKEN]${F[B]}, value:${F[W]}[********]"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
|
|
|
########################################
|
|
|
|
# See if we need values for Ducker hub #
|
|
|
|
########################################
|
2020-07-21 13:09:07 -04:00
|
|
|
elif [[ ${REGISTRY} == "Docker" ]]; then
|
2020-06-23 13:06:12 -04:00
|
|
|
############################
|
|
|
|
# Validate DOCKER_USERNAME #
|
|
|
|
############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${DOCKER_USERNAME}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [DOCKER_USERNAME]!"
|
|
|
|
fatal "[${DOCKER_USERNAME}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[DOCKER_USERNAME]${F[B]}, value:${F[W]}[${DOCKER_USERNAME}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
############################
|
|
|
|
# Validate DOCKER_PASSWORD #
|
|
|
|
############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${DOCKER_PASSWORD}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [DOCKER_PASSWORD]!"
|
|
|
|
fatal "[${DOCKER_PASSWORD}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[DOCKER_PASSWORD]${F[B]}, value:${F[B]}[********]"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
|
|
|
###########################################
|
|
|
|
# We were not passed a registry to update #
|
|
|
|
###########################################
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to find a valid registry!"
|
2020-07-27 17:20:06 -04:00
|
|
|
fatal "Registry:[${REGISTRY}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
#######################
|
|
|
|
# Validate IMAGE_REPO #
|
|
|
|
#######################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${IMAGE_REPO}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [IMAGE_REPO]!"
|
|
|
|
fatal "[${IMAGE_REPO}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[IMAGE_REPO]${F[B]}, value:${F[W]}[${IMAGE_REPO}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
###############################################
|
|
|
|
# Need to see if GPR registry and update name #
|
|
|
|
###############################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [[ ${REGISTRY} == "GPR" ]]; then
|
|
|
|
NAME="docker.pkg.github.com/${IMAGE_REPO}/super-linter"
|
|
|
|
IMAGE_REPO="${NAME}"
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Updated [IMAGE_REPO] to:[${IMAGE_REPO}] for GPR"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
##########################
|
|
|
|
# Validate IMAGE_VERSION #
|
|
|
|
##########################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${IMAGE_VERSION}" ]; then
|
2020-07-30 15:15:42 -04:00
|
|
|
warn "Failed to get [IMAGE_VERSION]!"
|
|
|
|
info "Pulling from Branch Name..."
|
2020-01-09 14:04:41 -05:00
|
|
|
##############################
|
|
|
|
# Get the name of the branch #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
BRANCH_NAME=$(git -C "${GITHUB_WORKSPACE}" branch --contains "${GITHUB_SHA}" | awk '{print ${2}}' 2>&1)
|
2020-01-09 14:04:41 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get branch name!"
|
|
|
|
fatal "[${BRANCH_NAME}]"
|
2020-01-09 14:04:41 -05:00
|
|
|
fi
|
|
|
|
|
2020-06-20 23:56:56 -04:00
|
|
|
##################################
|
|
|
|
# Remove non alpha-numeric chars #
|
|
|
|
##################################
|
2020-07-21 13:09:07 -04:00
|
|
|
BRANCH_NAME=$(echo "${BRANCH_NAME}" | tr -cd '[:alnum:]')
|
2020-01-09 14:04:41 -05:00
|
|
|
|
|
|
|
############################################
|
|
|
|
# Set the IMAGE_VERSION to the BRANCH_NAME #
|
|
|
|
############################################
|
2020-07-21 13:09:07 -04:00
|
|
|
IMAGE_VERSION="${BRANCH_NAME}"
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Tag:[${IMAGE_VERSION}]"
|
2020-01-09 14:10:40 -05:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[IMAGE_VERSION]${F[B]}, value:${F[W]}[${IMAGE_VERSION}]"
|
2020-01-09 14:04:41 -05:00
|
|
|
fi
|
|
|
|
|
2020-06-29 13:39:10 -04:00
|
|
|
##################################
|
|
|
|
# Set regex for getting tag info #
|
|
|
|
##################################
|
|
|
|
REGEX='(v[0-9]+\.[0-9]+\.[0-9]+)' # Matches 'v1.2.3'
|
|
|
|
|
|
|
|
######################################################################
|
|
|
|
# Check if this is a latest to a versioned release at create new tag #
|
|
|
|
######################################################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [[ ${IMAGE_VERSION} =~ ${REGEX} ]]; then
|
2020-06-29 13:39:10 -04:00
|
|
|
# Need to get the major version, and set flag to update
|
|
|
|
|
|
|
|
#####################
|
|
|
|
# Set the major tag #
|
|
|
|
#####################
|
2020-07-21 13:09:07 -04:00
|
|
|
MAJOR_TAG=$(echo "${IMAGE_VERSION}" | cut -d '.' -f1)
|
2020-06-29 13:39:10 -04:00
|
|
|
|
|
|
|
###################################
|
|
|
|
# Set flag for updating major tag #
|
|
|
|
###################################
|
|
|
|
UPDATE_MAJOR_TAG=1
|
|
|
|
|
2020-07-30 15:15:42 -04:00
|
|
|
info "- Also deploying a major tag of:[${MAJOR_TAG}]"
|
2020-06-29 13:39:10 -04:00
|
|
|
fi
|
|
|
|
|
2019-11-08 09:31:16 -05:00
|
|
|
############################
|
|
|
|
# Validate DOCKERFILE_PATH #
|
|
|
|
############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ -z "${DOCKERFILE_PATH}" ]; then
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get [DOCKERFILE_PATH]!"
|
|
|
|
fatal "[${DOCKERFILE_PATH}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully found:${F[W]}[DOCKERFILE_PATH]${F[B]}, value:${F[W]}[${DOCKERFILE_PATH}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
2020-06-23 13:06:12 -04:00
|
|
|
#### Function Authenticate #####################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
Authenticate() {
|
2020-06-23 13:06:12 -04:00
|
|
|
################
|
|
|
|
# Pull in Vars #
|
|
|
|
################
|
2020-07-21 13:09:07 -04:00
|
|
|
USERNAME="${1}" # Name to auth with
|
|
|
|
PASSWORD="${2}" # Password to auth with
|
|
|
|
URL="${3}" # Url to auth towards
|
|
|
|
NAME="${4}" # name of the service
|
2020-06-23 13:06:12 -04:00
|
|
|
|
2019-11-08 09:31:16 -05:00
|
|
|
################
|
|
|
|
# Print header #
|
|
|
|
################
|
2020-07-30 15:15:42 -04:00
|
|
|
info "----------------------------------------------"
|
|
|
|
info "Login to ${NAME}..."
|
|
|
|
info "----------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
|
2020-06-23 13:06:12 -04:00
|
|
|
###################
|
|
|
|
# Auth to service #
|
|
|
|
###################
|
2020-07-21 13:09:07 -04:00
|
|
|
LOGIN_CMD=$(docker login "${URL}" --username "${USERNAME}" --password "${PASSWORD}" 2>&1)
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2019-11-08 09:31:16 -05:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to authenticate to ${NAME}!"
|
|
|
|
fatal "[${LOGIN_CMD}]"
|
2020-07-30 15:19:07 -04:00
|
|
|
else
|
2019-11-08 09:31:16 -05:00
|
|
|
# SUCCESS
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully authenticated to ${F[C]}${NAME}${F[B]}!"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function BuildImage #######################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
BuildImage() {
|
2019-11-08 09:31:16 -05:00
|
|
|
################
|
|
|
|
# Print header #
|
|
|
|
################
|
2020-07-30 15:15:42 -04:00
|
|
|
info "----------------------------------------------"
|
|
|
|
info "Building the DockerFile image..."
|
|
|
|
info "----------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
################################
|
|
|
|
# Validate the DOCKERFILE_PATH #
|
|
|
|
################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ! -f "${DOCKERFILE_PATH}" ]; then
|
2019-11-08 09:31:16 -05:00
|
|
|
# No file found
|
2020-07-27 17:35:53 -04:00
|
|
|
error "failed to find Dockerfile at:[${DOCKERFILE_PATH}]"
|
2020-07-27 17:20:06 -04:00
|
|
|
error "Please make sure you give full path!"
|
|
|
|
fatal "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
###################
|
|
|
|
# Build the image #
|
|
|
|
###################
|
2020-07-21 13:09:07 -04:00
|
|
|
docker build --no-cache -t "${IMAGE_REPO}:${IMAGE_VERSION}" -f "${DOCKERFILE_PATH}" . 2>&1
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2019-11-08 09:31:16 -05:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
fatal "failed to [build] Dockerfile!"
|
2019-11-08 10:00:07 -05:00
|
|
|
else
|
|
|
|
# SUCCESS
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully Built image!"
|
2020-06-29 13:39:10 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
########################################################
|
|
|
|
# Need to see if we need to tag a major update as well #
|
|
|
|
########################################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${UPDATE_MAJOR_TAG} -eq 1 ]; then
|
2020-06-29 13:39:10 -04:00
|
|
|
# Tag the image with the major tag as well
|
2020-07-21 13:09:07 -04:00
|
|
|
docker build -t "${IMAGE_REPO}:${MAJOR_TAG}" -f "${DOCKERFILE_PATH}" . 2>&1
|
2020-06-29 13:39:10 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2020-06-29 13:39:10 -04:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
fatal "failed to [tag] Dockerfile!"
|
2020-06-29 13:39:10 -04:00
|
|
|
else
|
|
|
|
# SUCCESS
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully tagged image!"
|
2020-06-29 13:39:10 -04:00
|
|
|
fi
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function UploadImage ######################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
UploadImage() {
|
2019-11-08 09:31:16 -05:00
|
|
|
################
|
|
|
|
# Print header #
|
|
|
|
################
|
2020-07-30 15:15:42 -04:00
|
|
|
info "----------------------------------------------"
|
|
|
|
info "Uploading the DockerFile image to ${REGISTRY}..."
|
|
|
|
info "----------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
############################################
|
|
|
|
# Upload the docker image that was created #
|
|
|
|
############################################
|
2020-07-21 13:09:07 -04:00
|
|
|
docker push "${IMAGE_REPO}:${IMAGE_VERSION}" 2>&1
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2019-11-08 09:31:16 -05:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
fatal "failed to [upload] Dockerfile!"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
|
|
|
# SUCCESS
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully Uploaded Docker image:${F[W]}[${IMAGE_VERSION}]${F[B]} to ${F[C]}${REGISTRY}${F[B]}!"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
#########################
|
|
|
|
# Get Image information #
|
|
|
|
#########################
|
2019-11-08 10:00:07 -05:00
|
|
|
IFS=$'\n' # Set the delimit to newline
|
2020-07-21 13:09:07 -04:00
|
|
|
GET_INFO_CMD=$(docker images | grep "${IMAGE_REPO}" | grep "${IMAGE_VERSION}" 2>&1)
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2019-11-08 09:31:16 -05:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Failed to get information about built Image!"
|
|
|
|
fatal "[${GET_INFO_CMD}]"
|
2019-11-08 09:31:16 -05:00
|
|
|
else
|
|
|
|
################
|
|
|
|
# Get the data #
|
|
|
|
################
|
2020-07-21 13:09:07 -04:00
|
|
|
REPO=$(echo "${GET_INFO_CMD}" | awk '{print ${1}}')
|
|
|
|
TAG=$(echo "${GET_INFO_CMD}" | awk '{print ${2}}')
|
|
|
|
IMAGE_ID=$(echo "${GET_INFO_CMD}" | awk '{print ${3}}')
|
2020-06-22 09:59:31 -04:00
|
|
|
SIZE="${GET_INFO_CMD##* }"
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
###################
|
|
|
|
# Print the goods #
|
|
|
|
###################
|
2020-07-30 15:15:42 -04:00
|
|
|
info "----------------------------------------------"
|
|
|
|
info "Docker Image Details:"
|
|
|
|
info "Repository:[${REPO}]"
|
|
|
|
info "Tag:[${TAG}]"
|
|
|
|
info "Image_ID:[${IMAGE_ID}]"
|
|
|
|
info "Size:[${SIZE}]"
|
|
|
|
info "----------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
fi
|
2020-06-29 13:39:10 -04:00
|
|
|
|
|
|
|
###############################################################
|
|
|
|
# Check if we need to upload the major tagged version as well #
|
|
|
|
###############################################################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${UPDATE_MAJOR_TAG} -eq 1 ]; then
|
2020-06-29 13:39:10 -04:00
|
|
|
############################################
|
|
|
|
# Upload the docker image that was created #
|
|
|
|
############################################
|
2020-07-21 13:09:07 -04:00
|
|
|
docker push "${IMAGE_REPO}:${MAJOR_TAG}" 2>&1
|
2020-06-29 13:39:10 -04:00
|
|
|
|
|
|
|
#######################
|
|
|
|
# Load the error code #
|
|
|
|
#######################
|
|
|
|
ERROR_CODE=$?
|
|
|
|
|
|
|
|
##############################
|
|
|
|
# Check the shell for errors #
|
|
|
|
##############################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [ ${ERROR_CODE} -ne 0 ]; then
|
2020-06-29 13:39:10 -04:00
|
|
|
# ERROR
|
2020-07-27 17:35:53 -04:00
|
|
|
fatal "failed to [upload] MAJOR_TAG:[${MAJOR_TAG}] Dockerfile!"
|
2020-06-29 13:39:10 -04:00
|
|
|
else
|
|
|
|
# SUCCESS
|
2020-07-30 15:15:42 -04:00
|
|
|
info "Successfully Uploaded TAG:${F[W]}[${MAJOR_TAG}]${F[B]} of Docker image to ${F[C]}${REGISTRY}${F[B]}!"
|
2020-06-29 13:39:10 -04:00
|
|
|
fi
|
|
|
|
fi
|
2019-11-08 09:31:16 -05:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
#### Function Footer ###########################################################
|
2020-07-01 17:40:40 -04:00
|
|
|
Footer() {
|
2020-07-30 15:15:42 -04:00
|
|
|
info "-------------------------------------------------------"
|
|
|
|
info "The step has completed"
|
|
|
|
info "-------------------------------------------------------"
|
2019-11-08 09:31:16 -05:00
|
|
|
}
|
|
|
|
################################################################################
|
|
|
|
################################## MAIN ########################################
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
##########
|
|
|
|
# Header #
|
|
|
|
##########
|
|
|
|
Header
|
|
|
|
|
|
|
|
##################
|
|
|
|
# Validate Input #
|
|
|
|
##################
|
|
|
|
ValidateInput
|
|
|
|
|
|
|
|
###################
|
|
|
|
# Build the image #
|
|
|
|
###################
|
|
|
|
BuildImage
|
|
|
|
|
|
|
|
######################
|
|
|
|
# Login to DockerHub #
|
|
|
|
######################
|
2020-07-21 13:09:07 -04:00
|
|
|
if [[ ${REGISTRY} == "Docker" ]]; then
|
2020-06-23 13:06:12 -04:00
|
|
|
# Authenticate "Username" "Password" "Url" "Name"
|
2020-07-21 13:09:07 -04:00
|
|
|
Authenticate "${DOCKER_USERNAME}" "${DOCKER_PASSWORD}" "" "Dockerhub"
|
2020-06-23 13:06:12 -04:00
|
|
|
|
|
|
|
####################################
|
|
|
|
# Login to GitHub Package Registry #
|
|
|
|
####################################
|
2020-07-21 13:09:07 -04:00
|
|
|
elif [[ ${REGISTRY} == "GPR" ]]; then
|
2020-06-23 13:06:12 -04:00
|
|
|
# Authenticate "Username" "Password" "Url" "Name"
|
2020-07-21 13:09:07 -04:00
|
|
|
Authenticate "${GPR_USERNAME}" "${GPR_TOKEN}" "https://docker.pkg.github.com" "GitHub Package Registry"
|
2020-06-23 13:06:12 -04:00
|
|
|
|
|
|
|
else
|
|
|
|
#########
|
|
|
|
# ERROR #
|
|
|
|
#########
|
2020-07-27 17:35:53 -04:00
|
|
|
error "Registry not set correctly!"
|
2020-07-27 17:20:06 -04:00
|
|
|
fatal "Registry:[${REGISTRY}]"
|
2020-06-23 13:06:12 -04:00
|
|
|
fi
|
2019-11-08 09:31:16 -05:00
|
|
|
|
|
|
|
####################
|
|
|
|
# Upload the image #
|
|
|
|
####################
|
|
|
|
UploadImage
|
|
|
|
|
|
|
|
##########
|
|
|
|
# Footer #
|
|
|
|
##########
|
|
|
|
Footer
|