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 #149 from kabanero-io/aadeshpa-issue-132-merge-two…
Browse files Browse the repository at this point in the history
…-tasks

aadeshpa issue 132 merged build and deploy task
  • Loading branch information
kvijai82 authored Dec 5, 2019
2 parents 1c71bd5 + 082d0fd commit 2365738
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 165 deletions.
5 changes: 5 additions & 0 deletions pipelines/incubator/build-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ spec:
resources:
- name: git-source
type: git
- name: docker-image
type: image
tasks:
- name: build-task
taskRef:
Expand All @@ -15,3 +17,6 @@ spec:
inputs:
- name: git-source
resource: git-source
outputs:
- name: docker-image
resource: docker-image
18 changes: 4 additions & 14 deletions pipelines/incubator/build-push-deploy-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ spec:
- name: docker-image
type: image
tasks:
- name: build-push-task
- name: build-push-deploy-task
taskRef:
name: CollectionId-build-push-task
name: CollectionId-build-push-deploy-task
resources:
inputs:
- name: git-source
Expand All @@ -27,20 +27,10 @@ spec:
- name: image-scan-task
taskRef:
name: CollectionId-image-scan-task
runAfter: [build-push-task]
runAfter: [build-push-deploy-task]
resources:
inputs:
- name: git-source
resource: git-source
- name: docker-image
resource: docker-image
- name: deploy-task
taskRef:
name: CollectionId-deploy-task
runAfter: [build-push-task]
resources:
inputs:
- name: git-source
resource: git-source
- name: docker-image
resource: docker-image
resource: docker-image
156 changes: 156 additions & 0 deletions pipelines/incubator/build-push-deploy-task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#Kabanero! on activate substitute CollectionId for text 'CollectionId'
apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
name: CollectionId-build-push-deploy-task
spec:
inputs:
resources:
- name: git-source
type: git
params:
- name: pathToDockerFile
default: /workspace/extracted/Dockerfile
- name: pathToContext
default: /workspace/extracted
- name: appsody-yaml-file-path
default: $HOME/.appsody/.appsody.yaml
- name: repository-name
default: CollectionId
- name: app-deploy-file-name
default: app-deploy.yaml
outputs:
resources:
- name: docker-image
type: image
steps:
- name: extract
securityContext:
privileged: true
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ["/bin/bash"]
args:
- -c
- |
echo "running appsody extract"
appsody extract --buildah --target-dir /workspace/$gitsource -v
echo "extract completed"
ls -la /workspace/$gitsource
cat /workspace/git-source/$(inputs.params.app-deploy-file-name)
env:
- name: gitsource
value: git-source
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: validate-collection-is-active
securityContext:
privileged: true
image: kabanero/validate-collection:0.1
command: ["/bin/bash"]
args:
- -c
- "/validate.sh"
env:
- name: gitsource
value: git-source
- name: build
securityContext:
privileged: true
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ["/bin/bash"]
args:
- -c
- |
echo "Checking for configmap value....DEFAULT_COLLECTION_IMAGE_REGISTRY_URL=$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL"
echo "appsody-yaml-file-path=$(inputs.params.appsody-yaml-file-path)"
if [ -z "$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL" ]
then
echo "DEFAULT_COLLECTION_IMAGE_REGISTRY_URL=$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL given as input by user is empty, so using the registry for collection image download from $(inputs.params.appsody-yaml-file-path)"
else
if [ -f "$(inputs.params.appsody-yaml-file-path)" ]
then
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) exists."
else
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) does not exists, we are creating it by running appsody list command."
appsody version
fi
#Replacing the container registry from index.docker.io to DEFAULT_COLLECTION_IMAGE_REGISTRY_URL for collection image download in the file inputs.params.appsody-yaml-file-path
sed -i -e 's#images: .*$#images: $(DEFAULT_COLLECTION_IMAGE_REGISTRY_URL)#g' $(inputs.params.appsody-yaml-file-path)
echo "sed command completed successfully"
#Creating a cert for authentication of buildah login of the DEFAULT_COLLECTION_IMAGE_REGISTRY_URL registry url
echo "HOST=$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL" > cert-creation.sh
echo "sudo mkdir -p /etc/docker/certs.d/\${HOST}" >> cert-creation.sh
echo "openssl s_client -connect \${HOST} -servername \${HOST} 2>/dev/null </dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/docker/certs.d/\${HOST}/ca.crt" >> cert-creation.sh
if [[ ( -z "$DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_USERNAME" ) || ( -z "$DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_PASSWORD" ) ]]
then
echo "DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_USERNAME or DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_PASSWORD is empty ,Assumption is $DEFAULT_COLLECTION_IMAGE_REGISTRY_URL is internal registry, skipping the login to the registry"
else
echo "Both DEFAULT_COLLECTION_IMAGE_REGISTRY_URL and Secrets are provided"
echo "Adding buildah login command to cert-creation.sh script"
echo "buildah login -u $DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_USERNAME -p $DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_PASSWORD \${HOST}" >> cert-creation.sh
fi
chmod 755 cert-creation.sh
./cert-creation.sh
fi
cd /workspace/$gitsource
appsody build -t $(outputs.resources.docker-image.url) --buildah --buildah-options "--format=docker"
env:
- name: gitsource
value: git-source
- name: DEFAULT_COLLECTION_IMAGE_REGISTRY_URL
valueFrom:
configMapKeyRef:
name: collection-image-registry-map
key: default-collection-image-registry-url
optional: true
- name: DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_USERNAME
valueFrom:
secretKeyRef:
name: default-collection-image-registry-secret
key: username
optional: true
- name: DEFAULT_COLLECTION_IMAGE_REGISTRY_SECRET_PASSWORD
valueFrom:
secretKeyRef:
name: default-collection-image-registry-secret
key: password
optional: true
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: config-volume
mountPath: /config
- name: secret-volume
mountPath: /etc/secret-volume
- name: push
securityContext:
privileged: true
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ['buildah', 'push', '--tls-verify=false', '$(outputs.resources.docker-image.url)', 'docker://$(outputs.resources.docker-image.url)']
env:
- name: gitsource
value: git-source
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: deploy-image
image: kabanero/kabanero-utils:0.3.0
command: ['/bin/sh']
args: ['-c', 'find /workspace/git-source -name ${YAMLFILE} -type f|xargs kubectl apply -f']
env:
- name: YAMLFILE
value: $(inputs.params.app-deploy-file-name)
volumes:
- name: varlibcontainers
emptyDir: {}
- name: config-volume
configMap:
name: collection-image-registry-map
optional: true
- name: secret-volume
secret:
secretName: default-collection-image-registry-secret
optional: true
2 changes: 1 addition & 1 deletion pipelines/incubator/build-push-pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ spec:
- name: git-source
resource: git-source
- name: docker-image
resource: docker-image
resource: docker-image
77 changes: 44 additions & 33 deletions pipelines/incubator/build-push-task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,64 @@ spec:
default: /workspace/extracted
- name: appsody-yaml-file-path
default: $HOME/.appsody/.appsody.yaml
- name: app-deploy-file-name
default: app-deploy.yaml
outputs:
resources:
- name: docker-image
type: image
steps:
- name: assemble-extract
- name: extract
securityContext:
privileged: true
image: appsody/appsody-buildah:0.2.1
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ["/bin/bash"]
args:
- -c
- |
echo "running appsody extract"
appsody extract --buildah --target-dir /workspace/$gitsource -v
echo "extract completed"
ls -la /workspace/$gitsource
cat /workspace/git-source/$(inputs.params.app-deploy-file-name)
env:
- name: gitsource
value: git-source
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: validate-collection-is-active
securityContext:
privileged: true
image: kabanero/validate-collection:0.1
command: ["/bin/bash"]
args:
- -c
- "/validate.sh"
env:
- name: gitsource
value: git-source
- name: build
securityContext:
privileged: true
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ["/bin/bash"]
args:
- -c
- |
echo "Checking for configmap value....DEFAULT_COLLECTION_IMAGE_REGISTRY_URL=$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL"
echo "appsody-yaml-file-path=$(inputs.params.appsody-yaml-file-path)"
if [ -f "$(inputs.params.appsody-yaml-file-path)" ]
then
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) exists."
else
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) does not exists, we are creating it by running appsody list command."
appsody version
fi
if [ -z "$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL" ]
then
echo "DEFAULT_COLLECTION_IMAGE_REGISTRY_URL=$DEFAULT_COLLECTION_IMAGE_REGISTRY_URL given as input by user is empty, so using the registry for collection image download from $(inputs.params.appsody-yaml-file-path)"
else
if [ -f "$(inputs.params.appsody-yaml-file-path)" ]
then
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) exists."
else
echo "Appsody yaml file $(inputs.params.appsody-yaml-file-path) does not exists, we are creating it by running appsody list command."
appsody version
fi
#Replacing the container registry from index.docker.io to DEFAULT_COLLECTION_IMAGE_REGISTRY_URL for collection image download in the file inputs.params.appsody-yaml-file-path
sed -i -e 's#images: .*$#images: $(DEFAULT_COLLECTION_IMAGE_REGISTRY_URL)#g' $(inputs.params.appsody-yaml-file-path)
echo "sed command completed successfully"
Expand All @@ -61,7 +93,8 @@ spec:
chmod 755 cert-creation.sh
./cert-creation.sh
fi
/extract.sh
cd /workspace/$gitsource
appsody build -t $(outputs.resources.docker-image.url) --buildah --buildah-options "--format=docker"
env:
- name: gitsource
value: git-source
Expand Down Expand Up @@ -90,32 +123,10 @@ spec:
mountPath: /config
- name: secret-volume
mountPath: /etc/secret-volume
- name: validate-collection-is-active
securityContext:
privileged: true
image: kabanero/validate-collection:0.1
command: ["/bin/bash"]
args:
- -c
- "/validate.sh"
env:
- name: gitsource
value: git-source
- name: build
securityContext:
privileged: true
image: appsody/appsody-buildah:0.2.1
command: ['buildah', 'bud', '--tls-verify=false', '--format=docker', '-f', '$(inputs.params.pathToDockerFile)', '-t', '$(outputs.resources.docker-image.url)', '$(inputs.params.pathToContext)']
env:
- name: gitsource
value: git-source
volumeMounts:
- mountPath: /var/lib/containers
name: varlibcontainers
- name: push
securityContext:
privileged: true
image: appsody/appsody-buildah:0.2.1
image: appsody/appsody-buildah:0.5.0-buildah1.9.0
command: ['buildah', 'push', '--tls-verify=false', '$(outputs.resources.docker-image.url)', 'docker://$(outputs.resources.docker-image.url)']
env:
- name: gitsource
Expand Down
Loading

0 comments on commit 2365738

Please sign in to comment.