Merge pull request #254 from github/AddReleaseDeploy

Adding deploy For releases
This commit is contained in:
Lukas Gravley 2020-06-23 14:09:28 -05:00 committed by GitHub
commit 06d5f71037
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 194 additions and 39 deletions

View file

@ -20,6 +20,9 @@
GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace
DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub DOCKER_USERNAME="${DOCKER_USERNAME}" # Username to login to DockerHub
DOCKER_PASSWORD="${DOCKER_PASSWORD}" # Password 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_REPO="${IMAGE_REPO}" # Image repo to upload the image
IMAGE_VERSION="${IMAGE_VERSION}" # Version to tag the image IMAGE_VERSION="${IMAGE_VERSION}" # Version to tag the image
DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded DOCKERFILE_PATH="${DOCKERFILE_PATH}" # Path to the Dockerfile to be uploaded
@ -33,7 +36,7 @@ Header()
{ {
echo "" echo ""
echo "-------------------------------------------------------" echo "-------------------------------------------------------"
echo "------ GitHub Actions Upload image to DockerHub -------" echo "---- GitHub Actions Upload image to [$REGISTRY] ----"
echo "-------------------------------------------------------" echo "-------------------------------------------------------"
echo "" echo ""
} }
@ -51,9 +54,9 @@ ValidateInput()
echo "----------------------------------------------" echo "----------------------------------------------"
echo "" echo ""
############################ #############################
# Validate GITHUB_WORKSPACE # # Validate GITHUB_WORKSPACE #
############################ #############################
if [ -z "$GITHUB_WORKSPACE" ]; then if [ -z "$GITHUB_WORKSPACE" ]; then
echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" echo "ERROR! Failed to get [GITHUB_WORKSPACE]!"
echo "ERROR:[$GITHUB_WORKSPACE]" echo "ERROR:[$GITHUB_WORKSPACE]"
@ -62,6 +65,46 @@ ValidateInput()
echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]" echo "Successfully found:[GITHUB_WORKSPACE], value:[$GITHUB_WORKSPACE]"
fi fi
#####################
# Validate REGISTRY #
#####################
if [ -z "$REGISTRY" ]; then
echo "ERROR! Failed to get [REGISTRY]!"
echo "ERROR:[$REGISTRY]"
exit 1
else
echo "Successfully found:[REGISTRY], value:[$REGISTRY]"
fi
#####################################################
# See if we need values for GitHub package Registry #
#####################################################
if [[ "$REGISTRY" == "GPR" ]]; then
#########################
# Validate GPR_USERNAME #
#########################
if [ -z "$GPR_USERNAME" ]; then
echo "ERROR! Failed to get [GPR_USERNAME]!"
echo "ERROR:[$GPR_USERNAME]"
exit 1
else
echo "Successfully found:[GPR_USERNAME], value:[$GPR_USERNAME]"
fi
######################
# Validate GPR_TOKEN #
######################
if [ -z "$GPR_TOKEN" ]; then
echo "ERROR! Failed to get [GPR_TOKEN]!"
echo "ERROR:[$GPR_TOKEN]"
exit 1
else
echo "Successfully found:[GPR_TOKEN], value:[********]"
fi
########################################
# See if we need values for Ducker hub #
########################################
elif [[ "$REGISTRY" == "Docker" ]]; then
############################ ############################
# Validate DOCKER_USERNAME # # Validate DOCKER_USERNAME #
############################ ############################
@ -83,6 +126,15 @@ ValidateInput()
else else
echo "Successfully found:[DOCKER_PASSWORD], value:[********]" echo "Successfully found:[DOCKER_PASSWORD], value:[********]"
fi fi
###########################################
# We were not passed a registry to update #
###########################################
else
echo "ERROR! Failed to find a valid registry!"
echo "Registry:[$REGISTRY]"
exit 1
fi
####################### #######################
# Validate IMAGE_REPO # # Validate IMAGE_REPO #
@ -93,6 +145,14 @@ ValidateInput()
exit 1 exit 1
else else
echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]" echo "Successfully found:[IMAGE_REPO], value:[$IMAGE_REPO]"
###############################################
# Need to see if GPR registry and update name #
###############################################
if [[ "$REGISTRY" == "GPR" ]]; then
NAME="docker.pkg.github/$IMAGE_REPO"
IMAGE_REPO="$NAME"
echo "Updated [IMAGE_REPO] to:[$IMAGE_REPO] for GPR"
fi
fi fi
########################## ##########################
@ -146,22 +206,30 @@ ValidateInput()
fi fi
} }
################################################################################ ################################################################################
#### Function LoginToDocker #################################################### #### Function Authenticate #####################################################
LoginToDocker() Authenticate()
{ {
################
# Pull in Vars #
################
USERNAME="$1" # Name to auth with
PASSWORD="$2" # Password to auth with
URL="$3" # Url to auth towards
NAME="$4" # name of the service
################ ################
# Print header # # Print header #
################ ################
echo "" echo ""
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Login to DockerHub..." echo "Login to $NAME..."
echo "----------------------------------------------" echo "----------------------------------------------"
echo "" echo ""
###################### ###################
# Login to DockerHub # # Auth to service #
###################### ###################
LOGIN_CMD=$(docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" 2>&1) LOGIN_CMD=$(docker login "$URL" --username "$USERNAME" --password "$PASSWORD" 2>&1)
####################### #######################
# Load the error code # # Load the error code #
@ -173,12 +241,12 @@ LoginToDocker()
############################## ##############################
if [ $ERROR_CODE -ne 0 ]; then if [ $ERROR_CODE -ne 0 ]; then
# ERROR # ERROR
echo "ERROR! Failed to authenticate to DockerHub!" echo "ERROR! Failed to authenticate to $NAME!"
echo "ERROR:[$LOGIN_CMD]" echo "ERROR:[$LOGIN_CMD]"
exit 1 exit 1
else else
# SUCCESS # SUCCESS
echo "Successfully authenticated to DockerHub!" echo "Successfully authenticated to $NAME!"
fi fi
} }
################################################################################ ################################################################################
@ -194,7 +262,6 @@ BuildImage()
echo "----------------------------------------------" echo "----------------------------------------------"
echo "" echo ""
################################ ################################
# Validate the DOCKERFILE_PATH # # Validate the DOCKERFILE_PATH #
################################ ################################
@ -238,7 +305,7 @@ UploadImage()
################ ################
echo "" echo ""
echo "----------------------------------------------" echo "----------------------------------------------"
echo "Uploading the DockerFile image..." echo "Uploading the DockerFile image to $REGISTRY..."
echo "----------------------------------------------" echo "----------------------------------------------"
echo "" echo ""
@ -261,7 +328,7 @@ UploadImage()
exit 1 exit 1
else else
# SUCCESS # SUCCESS
echo "Successfully Uploaded Docker image to DockerHub!" echo "Successfully Uploaded Docker image to $REGISTRY!"
fi fi
######################### #########################
@ -329,16 +396,34 @@ Header
################## ##################
ValidateInput ValidateInput
######################
# Login to DockerHub #
######################
LoginToDocker
################### ###################
# Build the image # # Build the image #
################### ###################
BuildImage BuildImage
######################
# Login to DockerHub #
######################
if [[ "$REGISTRY" == "Docker" ]]; then
# Authenticate "Username" "Password" "Url" "Name"
Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "" "Dockerhub"
####################################
# Login to GitHub Package Registry #
####################################
elif [[ "$REGISTRY" == "GPR" ]]; then
# Authenticate "Username" "Password" "Url" "Name"
Authenticate "$GPR_USERNAME" "$GPR_TOKEN" "https://docker.pkg.github.com" "GitHub Package Registry"
else
#########
# ERROR #
#########
echo "ERROR! Registry not set correctly!"
echo "Registry:[$REGISTRY]"
exit 1
fi
#################### ####################
# Upload the image # # Upload the image #
#################### ####################

View file

@ -33,8 +33,8 @@ Draft pull requests are also welcome to get feedback early on, or if there is so
If you are the current maintainer of this action: If you are the current maintainer of this action:
1. Update `README.md` and the wiki to reflect new version number in the example workflow file sections 1. Update `README.md` and the wiki to reflect new version number in the example workflow file sections
2. Draft [Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) with a summarized changelog 2. Draft [Release](https://help.github.com/en/github/administering-a-repository/managing-releases-in-a-repository) with a summarized changelog
3. Publish the docker image to GitHub package registry 3. A GitHub Action will Publish the Docker image to GitHub Package Registry once a Release is created
4. Publish the docker image to Docker Hub 4. A GitHub Action will Publish the Docker image to Docker Hub once a Release is created
5. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners) 5. Look for approval from [CODEOWNERS](https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners)
## Resources ## Resources

View file

@ -43,13 +43,14 @@ jobs:
##################### #####################
# Run Deploy script # # Run Deploy script #
##################### #####################
- name: Deploy image to DockerHub - name: Deploy DEV image to DockerHub
env: env:
# Set the Env Vars # Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_REPO: github/super-linter IMAGE_REPO: github/super-linter
DOCKERFILE_PATH: Dockerfile DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash shell: bash
run: .automation/upload-docker.sh run: .automation/upload-docker.sh

View file

@ -40,7 +40,7 @@ jobs:
##################### #####################
# Run Deploy script # # Run Deploy script #
##################### #####################
- name: Deploy image to DockerHub - name: Deploy latest image to DockerHub
env: env:
# Set the Env Vars # Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
@ -48,5 +48,6 @@ jobs:
IMAGE_REPO: github/super-linter IMAGE_REPO: github/super-linter
IMAGE_VERSION: latest IMAGE_VERSION: latest
DOCKERFILE_PATH: Dockerfile DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash shell: bash
run: .automation/upload-docker.sh run: .automation/upload-docker.sh

68
.github/workflows/deploy-RELEASE.yml vendored Normal file
View file

@ -0,0 +1,68 @@
---
#########################
#########################
## Deploy Docker Image ##
#########################
#########################
#
# Documentation:
# https://help.github.com/en/articles/workflow-syntax-for-github-actions
#
#######################################
# Start the job on all push to master #
#######################################
on:
release:
# Want to run the automation when a release is created
types: ['created']
###############
# Set the Job #
###############
jobs:
build:
# Name the Job
name: Deploy Docker Image - Release
# Set the agent to run on
runs-on: ubuntu-latest
##################
# Load all steps #
##################
steps:
##########################
# Checkout the code base #
##########################
- name: Checkout Code
uses: actions/checkout@v2
###################################
# Run Deploy script for Dockerhub #
###################################
- name: Deploy Release image to Dockerhub
env:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
IMAGE_REPO: github/super-linter
IMAGE_VERSION: ${{ github.ref }}
DOCKERFILE_PATH: Dockerfile
REGISTRY: Docker
shell: bash
run: .automation/upload-docker.sh
#############################
# Run Deploy script for GPR #
#############################
- name: Deploy Release image to GitHub Package Registry
env:
# Set the Env Vars
DOCKER_USERNAME: ${{ secrets.GPR_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.GPR_PASSWORD }}
IMAGE_REPO: github/super-linter
IMAGE_VERSION: ${{ github.ref }}
DOCKERFILE_PATH: Dockerfile
REGISTRY: GPR
shell: bash
run: .automation/upload-docker.sh