Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #409 from kabanero-io/aadeshpa_issue_400_scan_imag…
Browse files Browse the repository at this point in the history
…e_fix

fix in scan image task
  • Loading branch information
kvijai82 authored Jun 11, 2020
2 parents fc4de68 + ff1f842 commit 3f331b3
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,34 +62,28 @@ WARNING="[WARNING]"
ERROR="[ERROR]"

if [[ ! -z "$docker_registry_url" ]]; then
docker_registry_url_trimmed_trailing_slash=${docker_registry_url%/}
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url_trimmed_trailing_slash}")
docker_registry_url=${docker_registry_url%/}
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url}")
if [[ ("$NUM_SLASHES" -ge 2 ) && ( ! -z $docker_imagename ) && ($docker_imagename != "null")]]; then
echo "$ERROR The image registry url=$docker_registry_url has imagename in it, and it is also provided as in input parameter=$docker_imagename to the pipeline as parameter, pipeline cannot take imagename twice, you can specify it from your (pipeline resourse) or through combination of (webhook setup and trigger template)."
exit 1
fi
fi

if [[ -z "$docker_registry_url" ]]; then
echo "$ERROR Please specify the image registry url in your webhook setup or event mediator or your pipeline resource and try again.
[Hint] : The image registry url can be docker.io/<docker-userid> ex: image-registry.openshift-image-registry.svc:5000/kabanero"
exit 1
else
if [[ ( -z "$docker_imagename") || ("$docker_imagename" == "null") ]]; then
#Trim the trailing forward slash('/') and then count no of forward slash.
if [[ $docker_registry_url == */ ]];then
docker_registry_url=${docker_registry_url%/}
fi
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url}")
echo "$WARNING The image registry url=$docker_registry_url has imagename in it, and it is also provided as in input parameter=$docker_imagename to the pipeline as parameter,pipeline will use the imagename from $docker_registry_url."
DOCKER_IMAGE_URL=$docker_registry_url
else
#Start of else
if [[ ( -z "$docker_imagename") || ("$docker_imagename" == "null") ]]; then
#Trim the trailing forward slash('/') and then count no of forward slash.
if [[ $docker_registry_url == */ ]];then
docker_registry_url=${docker_registry_url%/}
fi
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url}")

# This case is to handle jenkins pipeline scenario, where the user would specify the image name in the app-deploy.yaml
if [[ (-f /workspace/$gitsource/$app_deploy_filename) && ("$NUM_SLASHES" = 1) ]];then
cd /workspace/$gitsource
APPNAME=$(awk '/^ name:/ {print $2; exit}' $app_deploy_filename)
docker_imagename_lowercase=$(echo $APPNAME | tr '[:upper:]' '[:lower:]')
else
#Checking the migration case where imagename can be empty and if registry url has imagename.
#ex: image-registry.openshift-image-registry.svc:5000/kabanero/kab60-java-spring-boot2:e7a1448806240f0294035097c0203caa3f
# This case is to handle jenkins pipeline scenario, where the user would specify the image name in the app-deploy.yaml
if [[ (-f /workspace/$gitsource/$app_deploy_filename) && ("$NUM_SLASHES" = 1) ]];then
cd /workspace/$gitsource
APPNAME=$(awk '/^ name:/ {print $2; exit}' $app_deploy_filename)
docker_imagename_lowercase=$(echo $APPNAME | tr '[:upper:]' '[:lower:]')
else
#Checking the migration case where imagename can be empty and if registry url has imagename.
#ex: image-registry.openshift-image-registry.svc:5000/kabanero/kab60-java-spring-boot2:e7a1448806240f0294035097c0203caa3f
if [ "$NUM_SLASHES" = 1 ]; then
echo "$ERROR image registry url=$docker_registry_url does not have imagename and tagname values, you can specify it in your pipeline resource or through trigger template and try again."
exit 1
Expand All @@ -108,24 +102,31 @@ else
fi
docker_registry_url=$(echo $docker_registry_url | rev | cut -d"/" -f2- | rev)
fi
fi

elif [[ ! -z "$docker_imagename" ]]; then
docker_imagename_lowercase=$(echo $docker_imagename | tr '[:upper:]' '[:lower:]')
fi

#If it reaches here it means it has set the variable docker_imagename_lowercase correctly.
# If docker_registry_url value does not have trailing '/' add it before concatenating it with imagename
if [[ $docker_registry_url != */ ]];then
docker_registry_url=$docker_registry_url/
fi
elif [[ ! -z "$docker_imagename" ]]; then
docker_imagename_lowercase=$(echo $docker_imagename | tr '[:upper:]' '[:lower:]')
fi
fi


#If it reaches here it means it has set the variable docker_imagename_lowercase correctly.
# If docker_registry_url value does not have trailing '/' add it before concatenating it with imagename
if [[ $docker_registry_url != */ ]];then
docker_registry_url=$docker_registry_url/
fi

#Concatenate docker_registry_url with the docker_imagename_lowercase and docker_imagetag(if exists)
if [[ (! -z "$docker_imagetag") && ("$docker_imagetag" != "null") ]]; then
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase:$docker_imagetag
#Concatenate docker_registry_url with the docker_imagename_lowercase and docker_imagetag(if exists)
if [[ (! -z "$docker_imagetag") && ("$docker_imagetag" != "null") ]]; then
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase:$docker_imagetag
else
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase
fi

#End of else
fi
else
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase
echo "$ERROR Incoming image registry url is empty , please specify the image registry url in your webhook setup or event mediator or your pipeline resource and try again.
[Hint] : The image registry url can be docker.io/<docker-userid> ex: image-registry.openshift-image-registry.svc:5000/kabanero"
exit 1
fi

echo "$DOCKER_IMAGE_URL"
8 changes: 4 additions & 4 deletions pipelines/experimental/gitops/build-push-promote-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
# Refer to https://kabanero.io/docs/ref/general/reference/semver-governance.html for policy details.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand All @@ -54,7 +54,7 @@ spec:
# This steps builds the source project using appsody build.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
imagePullPolicy: Always
command: ["/bin/bash"]
args:
Expand Down Expand Up @@ -116,7 +116,7 @@ spec:
# Refer to https://kabanero.io/docs/ref/general/reference/semver-governance.html for policy details.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand All @@ -133,7 +133,7 @@ spec:
# Push the image built in the build step to the specified image registry. Optionally sign the image.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand Down
2 changes: 1 addition & 1 deletion pipelines/experimental/gitops/deploy-gitops-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
type: git
steps:
- name: deploy
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
script: |
#!/usr/bin/env sh
Expand Down
2 changes: 1 addition & 1 deletion pipelines/experimental/gitops/deployment-condition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
description: "The Git event ref"
check:
name: deployment-condition
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/sh"]
args:
- -ce
Expand Down
2 changes: 1 addition & 1 deletion pipelines/experimental/gitops/image-scan-condition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ spec:
description: "The Git event ref"
check:
name: image-scan-condition
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/sh"]
args:
- -ce
Expand Down
101 changes: 68 additions & 33 deletions pipelines/experimental/gitops/image-scan-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
- name: mount-image
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
# Temporarily make copy of mounted image since the mounted image will be unmounted when the container for this task ends.
# TODO: Determine another way to persist the mounted container image across containers
command: ['/bin/bash']
Expand Down Expand Up @@ -103,47 +103,82 @@ spec:
# For now we needed to remove the code, because we moved out the script from utilities task to 'kabanero-utils' image
# and this image uses some other image.
########
# Tracing prefixes
INFO="[INFO]"
WARNING="[WARNING]"
ERROR="[ERROR]"
docker_registry_url=$(inputs.resources.docker-image.url)
docker_imagename=$(inputs.params.docker-imagename)
docker_imagetag=$(inputs.params.docker-imagetag)
app_deploy_filename="app-deploy.yaml"
if [[ -z "$docker_registry_url" ]]; then
echo "Error : The input parameter docker-image resource url to the script is empty, please provide it and try again(Possible value example: docker.io/<docker-userid>, image-registry.openshift-image-registry.svc:5000/kabanero)"
exit 1
else
if [[ -z "$docker_imagename" ]]; then
if [[ -f /workspace/$gitsource/$app_deploy_filename ]];then
cd /workspace/$gitsource
APPNAME=$(awk '/^ name:/ {print $2; exit}' $app_deploy_filename)
docker_imagename_lowercase=$(echo $APPNAME | tr '[:upper:]' '[:lower:]')
if [[ ! -z "$docker_registry_url" ]]; then
docker_registry_url=${docker_registry_url%/}
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url}")
if [[ ("$NUM_SLASHES" -ge 2 ) && ( ! -z $docker_imagename ) && ($docker_imagename != "null")]]; then
echo "$WARNING The image registry url=$docker_registry_url has imagename in it, and it is also provided as in input parameter=$docker_imagename to the pipeline as parameter,pipeline will use the imagename from $docker_registry_url."
DOCKER_IMAGE_URL=$docker_registry_url
else
#Start of else
if [[ ( -z "$docker_imagename") || ("$docker_imagename" == "null") ]]; then
#Trim the trailing forward slash('/') and then count no of forward slash.
if [[ $docker_registry_url == */ ]];then
docker_registry_url=${docker_registry_url%/}
fi
NUM_SLASHES=$(awk -F"/" '{print NF-1}' <<< "${docker_registry_url}")
# This case is to handle jenkins pipeline scenario, where the user would specify the image name in the app-deploy.yaml
if [[ (-f /workspace/$gitsource/$app_deploy_filename) && ("$NUM_SLASHES" = 1) ]];then
cd /workspace/$gitsource
APPNAME=$(awk '/^ name:/ {print $2; exit}' $app_deploy_filename)
docker_imagename_lowercase=$(echo $APPNAME | tr '[:upper:]' '[:lower:]')
else
#Checking the migration case where imagename can be empty and if registry url has imagename.
#ex: image-registry.openshift-image-registry.svc:5000/kabanero/kab60-java-spring-boot2:e7a1448806240f0294035097c0203caa3f
if [ "$NUM_SLASHES" = 1 ]; then
echo "$ERROR image registry url=$docker_registry_url does not have imagename and tagname values, you can specify it in your pipeline resource or through trigger template and try again."
exit 1
elif [ "$NUM_SLASHES" = 2 ]; then
url_imagename_tagname_Part=$(echo $docker_registry_url | rev | cut -d"/" -f1 | rev)
if [[ ( ! -z $url_imagename_tagname_Part ) && ( $url_imagename_tagname_Part == *":"* ) ]]; then
imagename=$(cut -d ':' -f 1 <<< "$url_imagename_tagname_Part" )
docker_imagename_lowercase=$(echo $imagename | tr '[:upper:]' '[:lower:]')
docker_imagetag=$(cut -d ':' -f 2- <<< "$url_imagename_tagname_Part" )
elif [[ (! -z $url_imagename_tagname_Part) ]]; then
imagename=$url_imagename_tagname_Part
docker_imagename_lowercase=$(echo $imagename | tr '[:upper:]' '[:lower:]')
else
echo "$ERROR docker_registry_url=$docker_registry_url does not have the imagename and the param docker_imagename is not specified. Please provide docker_registry_url with imagename or provide correct values for incoming params docker_imagename=$docker_imagename and try again. "
exit 1
fi
docker_registry_url=$(echo $docker_registry_url | rev | cut -d"/" -f2- | rev)
fi
fi
elif [[ ! -z "$docker_imagename" ]]; then
docker_imagename_lowercase=$(echo $docker_imagename | tr '[:upper:]' '[:lower:]')
fi
#If it reaches here it means it has set the variable docker_imagename_lowercase correctly.
# If docker_registry_url value does not have trailing '/' add it before concatenating it with imagename
if [[ $docker_registry_url != */ ]];then
docker_registry_url=$docker_registry_url/
fi
#Concatenate docker_registry_url with the docker_imagename_lowercase and docker_imagetag(if exists)
if [[ (! -z "$docker_imagetag") && ("$docker_imagetag" != "null") ]]; then
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase:$docker_imagetag
else
echo "Error : docker_imagename is empty and the $app_deploy_filename is not present in the github appsody project.
Either provide the value for the variable or make the $app_deploy_filename file available in the github appsody project
Case 1: If you are running a pipeline where you do not want the docker imagename to be coming from 'app-deploy.yaml' ,
you would need to provide the imagename from the Trigger file.
(Hint: Check the pipeline trigger file passing the input parameter 'docker_imagename' to the pipelines)
Case 2: If your requirement is to pull the imagename from the 'app-deploy.yaml' file variable 'name' ,
then you need to make sure that you have the file available in the appsody project in github whose url you have provided as git-source to the pipeline"
exit 1
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase
fi
else
docker_imagename_lowercase=$(echo $docker_imagename | tr '[:upper:]' '[:lower:]')
#End of else
fi
fi
#If it reaches here it means it has set the variable docker_imagename_lowercase correctly.
#Check if trailing '/' exists for docker registry url, it not add it.
if [[ $docker_registry_url != */ ]];then
docker_registry_url=$docker_registry_url/
fi
#Concatenate docker_registry_url with the docker_imagename_lowercase and docker_imagetag(if exists)
if [[ ! -z "$docker_imagetag" ]]; then
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase:$docker_imagetag
else
DOCKER_IMAGE_URL=$docker_registry_url$docker_imagename_lowercase
echo "$ERROR Incoming image registry url is empty , please specify the image registry url in your webhook setup or event mediator or your pipeline resource and try again.
[Hint] : The image registry url can be docker.io/<docker-userid> ex: image-registry.openshift-image-registry.svc:5000/kabanero"
exit 1
fi
INPUTS_RESOURCE_DOCKER_IMAGE_URL_LOWERCASE=$DOCKER_IMAGE_URL
#######
Expand Down
6 changes: 3 additions & 3 deletions pipelines/incubator/build-deploy-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
# This steps builds the source project using appsody build.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand Down Expand Up @@ -85,7 +85,7 @@ spec:
# Push the image built in the build step to the specified image registry. Optionally sign the image.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand Down Expand Up @@ -146,7 +146,7 @@ spec:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: deploy-image
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ['/bin/sh']
args:
- -c
Expand Down
4 changes: 2 additions & 2 deletions pipelines/incubator/build-push-jk-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
# This steps builds the source project using appsody build.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand Down Expand Up @@ -91,7 +91,7 @@ spec:
# Push the image built in the build step to the specified image registry. Optionally sign the image.
securityContext:
privileged: true
image: kabanero/kabanero-utils@sha256:835371285400bf247ef5ec834d22c72629d2f4b11c304db22dca8f12ecd710ce
image: kabanero/kabanero-utils@sha256:d2534cb30f618975bd5a9554920050b36d1bde5a882e8bacf100773847ec9ae8
command: ["/bin/bash"]
args:
- -c
Expand Down
Loading

0 comments on commit 3f331b3

Please sign in to comment.