mirror of
https://github.com/super-linter/super-linter.git
synced 2024-12-22 20:52:12 -05:00
adding the files
This commit is contained in:
parent
d5a9e48631
commit
3d09c1b736
2 changed files with 362 additions and 0 deletions
318
.automation/upload-docker.sh
Normal file
318
.automation/upload-docker.sh
Normal file
|
@ -0,0 +1,318 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
############# Deploy Container to DockerHub @admiralawkbar #####################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
# NOTES: This script is used to upload a Dockerfile to DockerHub
|
||||||
|
# Its based on being built from a GitHub Action, but could be easily updated
|
||||||
|
# To be ran in a different medium.
|
||||||
|
#
|
||||||
|
# PRE-Reqs:
|
||||||
|
# - Dockerfile
|
||||||
|
# - System with Docker installed
|
||||||
|
# - Global variables met
|
||||||
|
|
||||||
|
###########
|
||||||
|
# Globals #
|
||||||
|
###########
|
||||||
|
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # Github Workspace
|
||||||
|
DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub
|
||||||
|
DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password to login to DockerHub
|
||||||
|
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
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
############################ FUNCTIONS BELOW ###################################
|
||||||
|
################################################################################
|
||||||
|
################################################################################
|
||||||
|
#### Function Header ###########################################################
|
||||||
|
Header()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "-------------------------------------------------------"
|
||||||
|
echo "------ Github Actions Upload image to DockerHub -------"
|
||||||
|
echo "-------------------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
#### Function ValidateInput ####################################################
|
||||||
|
ValidateInput()
|
||||||
|
{
|
||||||
|
# Need to validate we have the basic variables
|
||||||
|
################
|
||||||
|
# Print header #
|
||||||
|
################
|
||||||
|
echo ""
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo "Gathering variables..."
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
############################
|
||||||
|
# Validate GITHUB_WORKSPACE #
|
||||||
|
############################
|
||||||
|
if [ -z "$GITHUB_WORKSPACE" ]; then
|
||||||
|
echo "ERROR! Failed to get [GITHUB_WORKSPACE]!"
|
||||||
|
echo "ERROR:[$GITHUB_WORKSPACE]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
############################
|
||||||
|
# Validate DOCKER_USERNAME #
|
||||||
|
############################
|
||||||
|
if [ -z "$DOCKER_USERNAME" ]; then
|
||||||
|
echo "ERROR! Failed to get [DOCKER_USERNAME]!"
|
||||||
|
echo "ERROR:[$DOCKER_USERNAME]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
############################
|
||||||
|
# Validate DOCKER_PASSWORD #
|
||||||
|
############################
|
||||||
|
if [ -z "$DOCKER_PASSWORD" ]; then
|
||||||
|
echo "ERROR! Failed to get [DOCKER_PASSWORD]!"
|
||||||
|
echo "ERROR:[$DOCKER_PASSWORD]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[DOCKER_PASSWORD], value:[********]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Validate IMAGE_REPO #
|
||||||
|
#######################
|
||||||
|
if [ -z "$IMAGE_REPO" ]; then
|
||||||
|
echo "ERROR! Failed to get [IMAGE_REPO]!"
|
||||||
|
echo "ERROR:[$IMAGE_REPO]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# Validate IMAGE_VERSION #
|
||||||
|
##########################
|
||||||
|
if [ -z "$IMAGE_VERSION" ]; then
|
||||||
|
echo "ERROR! Failed to get [IMAGE_VERSION]!"
|
||||||
|
echo "ERROR:[$IMAGE_VERSION]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[IMAGE_VERSION], value:[$IMAGE_VERSION]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
############################
|
||||||
|
# Validate DOCKERFILE_PATH #
|
||||||
|
############################
|
||||||
|
if [ -z "$DOCKERFILE_PATH" ]; then
|
||||||
|
echo "ERROR! Failed to get [DOCKERFILE_PATH]!"
|
||||||
|
echo "ERROR:[$DOCKERFILE_PATH]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
echo "Successfully found:[DOCKERFILE_PATH], value:[$DOCKERFILE_PATH]"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
#### Function LoginToDocker ####################################################
|
||||||
|
LoginToDocker()
|
||||||
|
{
|
||||||
|
################
|
||||||
|
# Print header #
|
||||||
|
################
|
||||||
|
echo ""
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo "Login to DockerHub..."
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
######################
|
||||||
|
# Login to DockerHub #
|
||||||
|
######################
|
||||||
|
LOGIN_CMD=$(docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" 2>&1)
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Load the error code #
|
||||||
|
#######################
|
||||||
|
ERROR_CODE=$?
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ $ERROR_CODE -ne 0 ]; then
|
||||||
|
# ERROR
|
||||||
|
echo "ERROR! Failed to authenticate to DockerHub!"
|
||||||
|
echo "ERROR:[$LOGIN_CMD]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
# SUCCESS
|
||||||
|
echo "Successfully authenticaterd to DockerHub!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
#### Function BuildImage #######################################################
|
||||||
|
BuildImage()
|
||||||
|
{
|
||||||
|
################
|
||||||
|
# Print header #
|
||||||
|
################
|
||||||
|
echo ""
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo "Building the DockerFile image..."
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
################################
|
||||||
|
# Validate the DOCKERFILE_PATH #
|
||||||
|
################################
|
||||||
|
if [ ! -f "$DOCKERFILE_PATH" ]; then
|
||||||
|
# No file found
|
||||||
|
echo "ERROR! failed to find Dockerfile at:[$DOCKERFILE_PATH]"
|
||||||
|
echo "Please make sure you give full path!"
|
||||||
|
echo "Example:[/configs/Dockerfile] or [Dockerfile] if at root directory"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Build the image #
|
||||||
|
###################
|
||||||
|
BUILD_CMD=$(docker build --no-cache -t "$IMAGE_REPO:$IMAGE_VERSION" "$DOCKERFILE_PATH" 2>&1)
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Load the error code #
|
||||||
|
#######################
|
||||||
|
ERROR_CODE=$?
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ $ERROR_CODE -ne 0 ]; then
|
||||||
|
# ERROR
|
||||||
|
echo "ERROR! failed to [build] Dockerfile!"
|
||||||
|
echo "ERROR:[$BUILD_CMD]"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
#### Function UploadImage ######################################################
|
||||||
|
UploadImage()
|
||||||
|
{
|
||||||
|
################
|
||||||
|
# Print header #
|
||||||
|
################
|
||||||
|
echo ""
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo "Uploading the DockerFile image..."
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
|
||||||
|
############################################
|
||||||
|
# Upload the docker image that was created #
|
||||||
|
############################################
|
||||||
|
UPLOAD_CMD=$(docker push "$IMAGE_REPO:$IMAGE_VERSION" 2>&1)
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Load the error code #
|
||||||
|
#######################
|
||||||
|
ERROR_CODE=$?
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ $ERROR_CODE -ne 0 ]; then
|
||||||
|
# ERROR
|
||||||
|
echo "ERROR! failed to [build] Dockerfile!"
|
||||||
|
echo "ERROR:[$UPLOAD_CMD]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
# SUCCESS
|
||||||
|
echo "Successfully Uploaded Docker image to DockerHub!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
#########################
|
||||||
|
# Get Image information #
|
||||||
|
#########################
|
||||||
|
GET_INFO_CMD=$(docker images | grep "$IMAGE_REPO" | grep "$IMAGE_VERSION" 2>&1)
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# Load the error code #
|
||||||
|
#######################
|
||||||
|
ERROR_CODE=$?
|
||||||
|
|
||||||
|
##############################
|
||||||
|
# Check the shell for errors #
|
||||||
|
##############################
|
||||||
|
if [ $ERROR_CODE -ne 0 ]; then
|
||||||
|
# ERROR
|
||||||
|
echo "ERROR! Failed to get information about built Image!"
|
||||||
|
echo "ERROR:[$GET_INFO_CMD]"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
################
|
||||||
|
# Get the data #
|
||||||
|
################
|
||||||
|
REPO=$(echo "$GET_INFO_CMD" | cut -f1 -d' ')
|
||||||
|
TAG=$(echo "$GET_INFO_CMD" | cut -f2 -d' ')
|
||||||
|
IMAGE_ID=$(echo "$GET_INFO_CMD" | cut -f3 -d' ')
|
||||||
|
SIZE=$(echo "${GET_INFO_CMD##* }")
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Print the goods #
|
||||||
|
###################
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
echo "Docker Image Details:"
|
||||||
|
echo "Repository:[$REPO]"
|
||||||
|
echo "Tag:[$TAG]"
|
||||||
|
echo "Image_ID:[$IMAGE_ID]"
|
||||||
|
echo "Size:[$SIZE]"
|
||||||
|
echo "----------------------------------------------"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
#### Function Footer ###########################################################
|
||||||
|
Footer()
|
||||||
|
{
|
||||||
|
echo ""
|
||||||
|
echo "-------------------------------------------------------"
|
||||||
|
echo "The step has completed"
|
||||||
|
echo "-------------------------------------------------------"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
################################################################################
|
||||||
|
################################## MAIN ########################################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Header #
|
||||||
|
##########
|
||||||
|
Header
|
||||||
|
|
||||||
|
##################
|
||||||
|
# Validate Input #
|
||||||
|
##################
|
||||||
|
ValidateInput
|
||||||
|
|
||||||
|
######################
|
||||||
|
# Login to DockerHub #
|
||||||
|
######################
|
||||||
|
LoginToDocker
|
||||||
|
|
||||||
|
###################
|
||||||
|
# Build the image #
|
||||||
|
###################
|
||||||
|
BuildImage
|
||||||
|
|
||||||
|
####################
|
||||||
|
# Upload the image #
|
||||||
|
####################
|
||||||
|
UploadImage
|
||||||
|
|
||||||
|
##########
|
||||||
|
# Footer #
|
||||||
|
##########
|
||||||
|
Footer
|
44
.github/workflows/deploy.yml
vendored
Normal file
44
.github/workflows/deploy.yml
vendored
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
---
|
||||||
|
#########################
|
||||||
|
#########################
|
||||||
|
## Deploy Docker Image ##
|
||||||
|
#########################
|
||||||
|
#########################
|
||||||
|
|
||||||
|
#
|
||||||
|
# Documentation:
|
||||||
|
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
|
||||||
|
#
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Start the job on all push to master #
|
||||||
|
#######################################
|
||||||
|
on: ["push"]
|
||||||
|
# Only run when the push is on master
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
###############
|
||||||
|
# Set the Job #
|
||||||
|
###############
|
||||||
|
jobs:
|
||||||
|
env:
|
||||||
|
# Set the Env Vars
|
||||||
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
IMAGE_REPO: admiralawkbar/super-linter
|
||||||
|
IMAGE_VERSION: latest
|
||||||
|
DOCKERFILE_PATH: Dockerfile
|
||||||
|
build:
|
||||||
|
# Name the Job
|
||||||
|
name: Deploy Docker Image
|
||||||
|
# Set the agent to run on
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
##################
|
||||||
|
# Load all steps #
|
||||||
|
##################
|
||||||
|
steps:
|
||||||
|
# Run Deploy script
|
||||||
|
- name: Deploy image to DockerHub
|
||||||
|
shell: bash
|
||||||
|
run: .automation/upload-docker.sh
|
Loading…
Reference in a new issue