Last active
August 29, 2015 14:25
-
-
Save aweiteka/03fc5dbb666a56d021b7 to your computer and use it in GitHub Desktop.
OpenShift v3 image CI-CD pipeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "kind": "Template", | |
| "apiVersion": "v1", | |
| "metadata": { | |
| "name": "automated-build", | |
| "creationTimestamp": null, | |
| "annotations": { | |
| "description": "An OpenShift v3 template that sets up an automated build pipeline for building docker images from Dockerfile. Assumes the base FROM image has been created as an ImageStream.", | |
| "provider": "[email protected]" | |
| } | |
| }, | |
| "objects": [ | |
| { | |
| "kind": "ImageStream", | |
| "apiVersion": "v1", | |
| "metadata": { | |
| "name": "${BUILD_IMAGE_NAME}", | |
| "creationTimestamp": null | |
| }, | |
| "spec": { | |
| "tags": [ | |
| { | |
| "name": "${BUILD_IMAGE_TAG}", | |
| "from": { | |
| "Kind": "ImageStreamTag", | |
| "Name": "${BUILD_IMAGE_TAG}" | |
| } | |
| } | |
| ] | |
| }, | |
| "status": { | |
| "dockerImageRepository": "" | |
| } | |
| }, | |
| { | |
| "kind": "BuildConfig", | |
| "apiVersion": "v1", | |
| "metadata": { | |
| "name": "${NAME}-build", | |
| "creationTimestamp": null, | |
| "labels": { | |
| "name": "${NAME}-build" | |
| } | |
| }, | |
| "spec": { | |
| "triggers": [ | |
| { | |
| "type": "github", | |
| "github": { | |
| "secret": "${GIT_SECRET}" | |
| } | |
| }, | |
| { | |
| "type": "generic", | |
| "generic": { | |
| "secret": "${GENERIC_SECRET}" | |
| } | |
| }, | |
| { | |
| "type": "imageChange", | |
| "imageChange": {} | |
| } | |
| ], | |
| "source": { | |
| "type": "Git", | |
| "git": { | |
| "uri": "${SOURCE_URI}" | |
| } | |
| }, | |
| "strategy": { | |
| "type": "Docker", | |
| "dockerStrategy": { | |
| "from": { | |
| "kind": "ImageStreamTag", | |
| "name": "${BASE_DOCKER_IMAGE}:${BASE_DOCKER_IMAGE_TAG}" | |
| } | |
| } | |
| }, | |
| "output": { | |
| "to": { | |
| "kind": "ImageStreamTag", | |
| "name": "${BUILD_IMAGE_NAME}:${BUILD_IMAGE_TAG}" | |
| } | |
| }, | |
| "resources": {} | |
| }, | |
| "status": { | |
| "lastVersion": 0 | |
| } | |
| }, | |
| { | |
| "kind": "DeploymentConfig", | |
| "apiVersion": "v1", | |
| "metadata": { | |
| "name": "${NAME}-scratch-deploy" | |
| }, | |
| "spec": { | |
| "template": { | |
| "metadata": { | |
| "labels": { | |
| "name": "${NAME}-${BUILD_IMAGE_TAG}-deploy" | |
| } | |
| }, | |
| "spec": { | |
| "containers": [ | |
| { | |
| "name": "${NAME}", | |
| "image": "${BUILD_IMAGE_NAME}", | |
| "args": ["${TEST_CMD}"] | |
| } | |
| ] | |
| } | |
| }, | |
| "replicas": 1, | |
| "selector": { | |
| "name": "${NAME}-${BUILD_IMAGE_TAG}-deploy" | |
| }, | |
| "triggers": [ | |
| { | |
| "type": "imageChange", | |
| "imageChangeParams": { | |
| "automatic": true, | |
| "from": { | |
| "kind": "ImageStreamTag", | |
| "name": "${BUILD_IMAGE_NAME}:${BUILD_IMAGE_TAG}" | |
| } | |
| } | |
| }, | |
| { | |
| "type": "generic", | |
| "generic": { | |
| "secret": "${GENERIC_SECRET}" | |
| } | |
| } | |
| ], | |
| "strategy": { | |
| "type": "Recreate", | |
| "recreateParams": { | |
| "pre": { | |
| "failurePolicy": "Abort", | |
| "execNewPod": { | |
| "command": [ | |
| "/usr/bin/curl", | |
| "-X", | |
| "GET", | |
| "http://jsonplaceholder.typicode.com/posts/1" | |
| ], | |
| "env": [ | |
| { | |
| "name": "FOO", | |
| "value": "BAR" | |
| } | |
| ], | |
| "containerName": "${NAME}" | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ], | |
| "parameters": [ | |
| { | |
| "name": "NAME", | |
| "description": "Image workflow name" | |
| }, | |
| { | |
| "name": "SOURCE_URI", | |
| "description": "Git source URI of Dockerfile repository" | |
| }, | |
| { | |
| "name": "BASE_DOCKER_IMAGE", | |
| "description": "Base docker image from the Dockerfile FROM line. This must be previously defined as an image stream." | |
| }, | |
| { | |
| "name": "BASE_DOCKER_IMAGE_TAG", | |
| "description": "Base docker image tag from the Dockerfile FROM line.", | |
| "value": "latest" | |
| }, | |
| { | |
| "name": "BUILD_IMAGE_NAME", | |
| "description": "The name of the image after it is built, not including :<tag>" | |
| }, | |
| { | |
| "name": "BUILD_IMAGE_TAG", | |
| "description": "The tag of the image after it is built", | |
| "value": "scratch" | |
| }, | |
| { | |
| "name": "TEST_CMD", | |
| "description": "Command to pass into the test container when it is run. In the form of '/usr/bin/command arg1 arg2'", | |
| "value": "" | |
| }, | |
| { | |
| "name": "GIT_SECRET", | |
| "description": "Git repo callback token", | |
| "generate": "expression", | |
| "from": "[a-zA-Z0-9]{12}" | |
| }, | |
| { | |
| "name": "GENERIC_SECRET", | |
| "description": "Generic callback token", | |
| "generate": "expression", | |
| "from": "[a-zA-Z0-9]{12}" | |
| } | |
| ], | |
| "labels": { | |
| "template": "automated-build" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # OPTIONAL: | |
| # as ose admin (root) add template for all users and projects | |
| oc create -f automated-builds.json -n openshift | |
| # create jenkins master | |
| # see https://github.com/openshift/origin/tree/master/examples/jenkins | |
| oc process -f https://raw.githubusercontent.com/openshift/origin/master/examples/jenkins/jenkins-ephemeral-template.json | oc create -f - | |
| # before we create our image build pipeline... | |
| # we need the base image image stream. Using centos here... | |
| oc create -f https://raw.githubusercontent.com/openshift/origin/master/examples/image-streams/image-streams-centos7.json | |
| # as ose user, process template, parameterize, and create | |
| # this may be done via web UI | |
| oc process -f automated-builds.json -v SOURCE_URI=https://github.com/aweiteka/test-isv-auth.git,BASE_DOCKER_IMAGE=centos,BASE_DOCKER_IMAGE_TAG=centos7,BUILD_IMAGE_NAME=acmeapp,NAME=acme,TEST_CMD='/usr/bin/sleep 10' | oc create -f - | |
| ### NOTES: | |
| # delete resources in bulk | |
| oc delete dc,builds,bc,is -l template=automated-build | |
| # remote trigger (from jenkins job, for example) | |
| # build, deploy, etc. | |
| curl -X POST <url> [--insecure] | |
| # cron cmd to update image streams from remote registries | |
| oc import-image <imagestream> | |
| # after test promote image with new tag | |
| # from jenkins? | |
| oc tag ${BUILD_IMAGE_NAME}:${BUILD_IMAGE_TAG} ${BUILD_IMAGE_NAME}:<new-tag> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment