From db4662123ef0e24f13b190bf2d9f0563889f2e29 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 09:56:16 -0500 Subject: [PATCH 1/7] Adding deploy --- .github/workflows/deploy-RELEASE.yml | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/deploy-RELEASE.yml diff --git a/.github/workflows/deploy-RELEASE.yml b/.github/workflows/deploy-RELEASE.yml new file mode 100644 index 00000000..263dbe26 --- /dev/null +++ b/.github/workflows/deploy-RELEASE.yml @@ -0,0 +1,66 @@ +--- +######################### +######################### +## 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 + 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 + shell: bash + run: .automation/upload-docker.sh From 62ac7b3f0097659e22ee1d074021edeb1ddd3cf0 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:06:12 -0500 Subject: [PATCH 2/7] Updating code to allow for both registry --- .automation/upload-docker.sh | 147 +++++++++++++++++++++++++++-------- 1 file changed, 116 insertions(+), 31 deletions(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index c41adb33..500e9535 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -20,6 +20,9 @@ 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 | or 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 @@ -33,7 +36,7 @@ Header() { echo "" echo "-------------------------------------------------------" - echo "------ GitHub Actions Upload image to DockerHub -------" + echo "---- GitHub Actions Upload image to [$REGISTRY] ----" echo "-------------------------------------------------------" echo "" } @@ -51,9 +54,9 @@ ValidateInput() echo "----------------------------------------------" echo "" - ############################ + ############################# # Validate GITHUB_WORKSPACE # - ############################ + ############################# if [ -z "$GITHUB_WORKSPACE" ]; then echo "ERROR! Failed to get [GITHUB_WORKSPACE]!" echo "ERROR:[$GITHUB_WORKSPACE]" @@ -62,28 +65,77 @@ ValidateInput() 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]" + ##################### + # Validate REGISTRY # + ##################### + if [ -z "$REGISTRY" ]; then + echo "ERROR! Failed to get [REGISTRY]!" + echo "ERROR:[$REGISTRY]" exit 1 else - echo "Successfully found:[DOCKER_USERNAME], value:[$DOCKER_USERNAME]" + echo "Successfully found:[REGISTRY], value:[$REGISTRY]" fi - ############################ - # Validate DOCKER_PASSWORD # - ############################ - if [ -z "$DOCKER_PASSWORD" ]; then - echo "ERROR! Failed to get [DOCKER_PASSWORD]!" - echo "ERROR:[$DOCKER_PASSWORD]" - exit 1 + ##################################################### + # 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 # + ############################ + 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 + ########################################### + # We were not passed a registry to update # + ########################################### else - echo "Successfully found:[DOCKER_PASSWORD], value:[********]" + echo "ERROR! Failed to find a valid registry!" + echo "Registry:[$REGISTRY]" + exit 1 fi + ####################### # Validate IMAGE_REPO # ####################### @@ -93,6 +145,14 @@ ValidateInput() exit 1 else 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 ########################## @@ -146,22 +206,30 @@ ValidateInput() fi } ################################################################################ -#### Function LoginToDocker #################################################### -LoginToDocker() +#### Function Authenticate ##################################################### +Authenticate() { + ################ + # Pull in Vars # + ################ + USERNAME="$1" # Name to auth with + PASSWD="$2" # Password to auth with + URL="$3" # Url to auth towards + NAME="$4" # name of the service + ################ # Print header # ################ echo "" echo "----------------------------------------------" - echo "Login to DockerHub..." + echo "Login to $NAME..." echo "----------------------------------------------" echo "" - ###################### - # Login to DockerHub # - ###################### - LOGIN_CMD=$(docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD" 2>&1) + ################### + # Auth to service # + ################### + LOGIN_CMD=$(docker login "$URL" --username "$USERNAME" --password "$PASSWORD" 2>&1) ####################### # Load the error code # @@ -173,12 +241,12 @@ LoginToDocker() ############################## if [ $ERROR_CODE -ne 0 ]; then # ERROR - echo "ERROR! Failed to authenticate to DockerHub!" + echo "ERROR! Failed to authenticate to $NAME!" echo "ERROR:[$LOGIN_CMD]" exit 1 else # SUCCESS - echo "Successfully authenticated to DockerHub!" + echo "Successfully authenticated to $NAME!" fi } ################################################################################ @@ -194,7 +262,6 @@ BuildImage() echo "----------------------------------------------" echo "" - ################################ # Validate the DOCKERFILE_PATH # ################################ @@ -238,7 +305,7 @@ UploadImage() ################ echo "" echo "----------------------------------------------" - echo "Uploading the DockerFile image..." + echo "Uploading the DockerFile image to $REGISTRY..." echo "----------------------------------------------" echo "" @@ -261,7 +328,7 @@ UploadImage() exit 1 else # SUCCESS - echo "Successfully Uploaded Docker image to DockerHub!" + echo "Successfully Uploaded Docker image to $REGISTRY!" fi ######################### @@ -332,7 +399,25 @@ ValidateInput ###################### # Login to DockerHub # ###################### -LoginToDocker +if [[ "$REGISTRY" == "Docker" ]]; then + # Authenticate "Username" "Password" "Url" "Name" + Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "https://docker.com" "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 ################### # Build the image # From 509fc7c7bbbe336fdcecb90358886883ef3b57ab Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:08:33 -0500 Subject: [PATCH 3/7] Updating workflows --- .github/workflows/deploy-DEV.yml | 3 ++- .github/workflows/deploy-PROD.yml | 3 ++- .github/workflows/deploy-RELEASE.yml | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-DEV.yml b/.github/workflows/deploy-DEV.yml index 4b6975d7..d9af1b44 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -43,13 +43,14 @@ jobs: ##################### # Run Deploy script # ##################### - - name: Deploy image to DockerHub + - name: Deploy DEV image to DockerHub env: # Set the Env Vars DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} IMAGE_REPO: github/super-linter DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker shell: bash run: .automation/upload-docker.sh diff --git a/.github/workflows/deploy-PROD.yml b/.github/workflows/deploy-PROD.yml index fd39563b..b2306c80 100644 --- a/.github/workflows/deploy-PROD.yml +++ b/.github/workflows/deploy-PROD.yml @@ -40,7 +40,7 @@ jobs: ##################### # Run Deploy script # ##################### - - name: Deploy image to DockerHub + - name: Deploy latest image to DockerHub env: # Set the Env Vars DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} @@ -48,5 +48,6 @@ jobs: IMAGE_REPO: github/super-linter IMAGE_VERSION: latest DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker shell: bash run: .automation/upload-docker.sh diff --git a/.github/workflows/deploy-RELEASE.yml b/.github/workflows/deploy-RELEASE.yml index 263dbe26..27a3a4a4 100644 --- a/.github/workflows/deploy-RELEASE.yml +++ b/.github/workflows/deploy-RELEASE.yml @@ -48,6 +48,7 @@ jobs: IMAGE_REPO: github/super-linter IMAGE_VERSION: ${{ github.ref }} DOCKERFILE_PATH: Dockerfile + REGISTRY: Docker shell: bash run: .automation/upload-docker.sh @@ -62,5 +63,6 @@ jobs: IMAGE_REPO: github/super-linter IMAGE_VERSION: ${{ github.ref }} DOCKERFILE_PATH: Dockerfile + REGISTRY: GPR shell: bash run: .automation/upload-docker.sh From f3fbf867fcc3055434f11aa9070cd8cbb0380889 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:10:36 -0500 Subject: [PATCH 4/7] fix var name --- .automation/upload-docker.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 500e9535..74e3f0aa 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -212,10 +212,10 @@ Authenticate() ################ # Pull in Vars # ################ - USERNAME="$1" # Name to auth with - PASSWD="$2" # Password to auth with - URL="$3" # Url to auth towards - NAME="$4" # name of the service + 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 # From 57cd6822980f8b6e63a8f0dbeed703ad9a795711 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:19:37 -0500 Subject: [PATCH 5/7] Change of order --- .automation/upload-docker.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 74e3f0aa..8564ef28 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -396,6 +396,11 @@ Header ################## ValidateInput +################### +# Build the image # +################### +BuildImage + ###################### # Login to DockerHub # ###################### @@ -419,11 +424,6 @@ else exit 1 fi -################### -# Build the image # -################### -BuildImage - #################### # Upload the image # #################### From 1084ce762c80b991e08c5f74ae43e15a9e0e52ad Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:26:28 -0500 Subject: [PATCH 6/7] less verbose --- .automation/upload-docker.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 8564ef28..b814de01 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -406,7 +406,7 @@ BuildImage ###################### if [[ "$REGISTRY" == "Docker" ]]; then # Authenticate "Username" "Password" "Url" "Name" - Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "https://docker.com" "Dockerhub" + Authenticate "$DOCKER_USERNAME" "$DOCKER_PASSWORD" "" "Dockerhub" #################################### # Login to GitHub Package Registry # From 1f27f86381c55a79a4e6b339615c6a7972443160 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 23 Jun 2020 12:39:07 -0500 Subject: [PATCH 7/7] updated doc --- .github/CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e2302dd8..253b1933 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -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: 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 -3. Publish the docker image to GitHub package registry -4. Publish the docker image to Docker Hub +3. A GitHub Action will Publish the Docker image to GitHub Package Registry once a Release is created +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) ## Resources