From cd74d80762f86e01b8a90391756c243182a9ae3b Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Fri, 4 Sep 2020 09:52:04 -0500 Subject: [PATCH] adding some cleanup --- .automation/upload-docker.sh | 10 ++++---- .automation/validate-docker-labels.sh | 33 ++++++++++++++++++++------- .github/workflows/deploy-DEV.yml | 14 ++++++------ 3 files changed, 37 insertions(+), 20 deletions(-) diff --git a/.automation/upload-docker.sh b/.automation/upload-docker.sh index 1234f0b9..e1836836 100755 --- a/.automation/upload-docker.sh +++ b/.automation/upload-docker.sh @@ -38,9 +38,9 @@ CONTAINER_URL='' # Final URL to upload ########################################################### # Dynamic build variables to pass to container when built # ########################################################### -BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') # Current build date EX> "2017-08-28T09:24:41Z" -BUILD_REVISION=$(git rev-parse --short HEAD)# Current git commit EX> "e89faa7" -BUILD_VERSION='' # Current version of the container being built +BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') # Current build date EX> "2017-08-28T09:24:41Z" +BUILD_REVISION=$(git rev-parse --short HEAD) # Current git commit EX> "e89faa7" +BUILD_VERSION='' # Current version of the container being built ######################### # Source Function Files # @@ -363,7 +363,7 @@ BuildImage() { ################### # Build the image # ################### - docker build --build-arg "BUILD_DATE=${BUILD_DATE}" --build-arg "BUILD_VERSION=${BUILD_VERSION}" -t "${ADDITONAL_URL}:${IMAGE_VERSION}" -f "${DOCKERFILE_PATH}" . 2>&1 + docker build --build-arg "BUILD_DATE=${BUILD_DATE}" --build-arg "BUILD_REVISION=${BUILD_REVISION}" --build-arg "BUILD_VERSION=${BUILD_VERSION}" -t "${ADDITONAL_URL}:${IMAGE_VERSION}" -f "${DOCKERFILE_PATH}" . 2>&1 ####################### # Load the error code # @@ -388,7 +388,7 @@ BuildImage() { ################### # Build the image # ################### - docker build --build-arg "BUILD_DATE=${BUILD_DATE}" --build-arg "BUILD_VERSION=${MAJOR_TAG}" -t "${ADDITONAL_URL}:${MAJOR_TAG}" -f "${DOCKERFILE_PATH}" . 2>&1 + docker build --build-arg "BUILD_DATE=${BUILD_DATE}" --build-arg "BUILD_REVISION=${BUILD_REVISION}" --build-arg "BUILD_VERSION=${MAJOR_TAG}" -t "${ADDITONAL_URL}:${MAJOR_TAG}" -f "${DOCKERFILE_PATH}" . 2>&1 ####################### # Load the error code # diff --git a/.automation/validate-docker-labels.sh b/.automation/validate-docker-labels.sh index 92b48c35..cee8d4bd 100755 --- a/.automation/validate-docker-labels.sh +++ b/.automation/validate-docker-labels.sh @@ -9,10 +9,11 @@ ########### GITHUB_WORKSPACE="${GITHUB_WORKSPACE}" # GitHub Workspace GITHUB_SHA="${GITHUB_SHA}" # Sha used to create this branch -BUILD_DATE="${BUILD_DATE}" -BUILD_REVISION="${GITHUB_SHA}" -BUILD_VERSION="${GITHUB_SHA}" -ERROR=0 +BUILD_DATE="${BUILD_DATE}" # Date the container was built +BUILD_REVISION="${GITHUB_SHA}" # GitHub Sha +BUILD_VERSION="${GITHUB_SHA}" # Version of the container +ORG_REPO="github/super-linter" # Org/repo +ERROR=0 # Error count ######################### # Source Function Files # @@ -33,17 +34,33 @@ Header() { ################################################################################ #### Function ValidateLabel #################################################### ValidateLabel() { - LABEL=$(docker inspect --format "{{ index .Config.Labels \"$1\" }}" github/super-linter:"${GITHUB_SHA}") - if [[ ${LABEL} != "$2" ]]; then - error "Assert failed [$1 - '${LABEL}' != '$2']" + ############## + # Grab input # + ############## + CONTAINER_KEY="$1" # Example: org.opencontainers.image.created + CONTAINER_VALUE="$2" # Example: 1985-04-12T23:20:50.52Z + + ######################## + # Get the docker label # + ######################## + LABEL=$(docker inspect --format "{{ index .Config.Labels \"${CONTAINER_KEY}\" }}" "${ORG_REPO}:${GITHUB_SHA}") + + ################### + # Check the value # + ################### + if [[ ${LABEL} != "${CONTAINER_VALUE}" ]]; then + error "Assert failed [${CONTAINER_KEY} - '${LABEL}' != '${CONTAINER_VALUE}']" ERROR=1 else - info "Assert passed [$1]" + info "Assert passed [${CONTAINER_KEY}]" fi } ################################################################################ #### Function Footer ########################################################### Footer() { + ##################################### + # Check if any errors were reported # + ##################################### if [[ ${ERROR} -gt 0 ]]; then fatal "There were some failed assertions. See above" else diff --git a/.github/workflows/deploy-DEV.yml b/.github/workflows/deploy-DEV.yml index 32bd6607..5e6e0de2 100644 --- a/.github/workflows/deploy-DEV.yml +++ b/.github/workflows/deploy-DEV.yml @@ -56,6 +56,13 @@ jobs: shell: bash run: docker build --build-arg "BUILD_DATE=${BUILD_DATE}" --build-arg "BUILD_REVISION=${GITHUB_SHA}" --build-arg "BUILD_VERSION=${GITHUB_SHA}" --no-cache -t github/super-linter:${GITHUB_SHA} . + ######################################## + # Validates the metadata docker labels # + ######################################## + - name: Run Docker label test cases + shell: bash + run: .automation/validate-docker-labels.sh + ##################################### # Run Linter against Test code base # ##################################### @@ -76,10 +83,3 @@ jobs: - name: Run against all code base shell: bash run: docker run -e RUN_LOCAL=true -e OUTPUT_DETAILS=detailed -v ${GITHUB_WORKSPACE}:/tmp/lint github/super-linter:${GITHUB_SHA} - - ######################################## - # Validates the metadata docker labels # - ######################################## - - name: Run Docker label test cases - shell: bash - run: .automation/validate-docker-labels.sh