Appendix C. OpenShift Template modifications

An existing OpenShift example application nodejs-ex was used for this project. It provides an OpenShift Template requiring modification to support the image promotion and deployment process. Below is an annotated list of modified sections.

ImageStream

{
  "kind": "ImageStream",
  "apiVersion": "v1",
  "metadata": {
    "name": "${NAME}",
    "annotations": {
      "description": "Keeps track of changes in the application image",
      "openshift.io/image.insecureRepository": "true"
    }
  },
  "spec": {
    "tags": [
        {
            "from": {
                "kind": "DockerImage",                                      1
                "name": "${REGISTRY}/${REGISTRY_PROJECT}/${NAME}:${TAG}"    2
            },
            "name": "${IMAGESTREAM_TAG}",                                   3
            "importPolicy": {
                "insecure": true,
                "scheduled": true                                           4
            }
        }

    ]
  }
},

1
Since an external registry is used the tags kind will be DockerImage.
2
name points to the url of the Docker image including the specific tag that will be imported.
3
This is the tag of the ImageStream within the project that will be deployed.
4
Keep the image up to do date based on any changes in the source registry.

BuildConfig

{
  "kind": "BuildConfig",
  "apiVersion": "v1",
  "metadata": {
    "name": "${NAME}",
    "annotations": {
      "description": "Defines how to build the application",
      "template.alpha.openshift.io/wait-for-ready": "true"
    }
  },
  "spec": {
    "source": {
      "type": "Git",
      "git": {
        "uri": "${SOURCE_REPOSITORY_URL}",
        "ref": "${SOURCE_REPOSITORY_REF}"
      },
      "contextDir": "${CONTEXT_DIR}"
    },
    "strategy": {
      "type": "Source",
      "sourceStrategy": {
        "from": {
          "kind": "ImageStreamTag",
          "namespace": "${NAMESPACE}",
          "name": "nodejs:6"
        },
        "env":  [
          {
            "name": "NPM_MIRROR",
            "value": "${NPM_MIRROR}"
          }
        ]
      }
    },
    "output": {
      "to": {
        "kind": "DockerImage",                                      1
        "name": "${REGISTRY}/${REGISTRY_PROJECT}/${NAME}:${TAG}"    2
      }
    },
    "triggers": [],                                                 3
    "postCommit": {
      "script": "npm test"
    }
  }
},

1
Changed from ImageStreamTag to DockerImage so an external registry can be utilized.
2
Path to the Docker Registry the image will be pushed after the build process is complete.
3
All the triggers for the BuildConfig have been removed. The initiation of the build process will be handled by Jenkins.

DeploymentConfig

{
  "kind": "DeploymentConfig",
  "apiVersion": "v1",
  "metadata": {
    "name": "${NAME}",
    "annotations": {
      "description": "Defines how to deploy the application server",
      "template.alpha.openshift.io/wait-for-ready": "true"
    }
  },
  "spec": {
    "strategy": {
      "type": "Recreate"
    },
    "triggers": [                                   1
      {
        "type": "ImageChange",
        "imageChangeParams": {
          "automatic": false,                       2
          "containerNames": [
            "nodejs-mongo-persistent"
          ],
          "from": {
            "kind": "ImageStreamTag",
            "name": "${NAME}:${IMAGESTREAM_TAG}"    3
          }
        }
      }
    ],
... [OUTPUT ABBREVIATED] ...

1
Removed ConfigChange trigger. The DeploymentConfig will be rolled out using Jenkins.
2
Changed automatic to false. Jenkins will roll out new versions through the pipelines.
3
Parameterized the IMAGESTREAM_TAG

Parameters

... [OUTPUT ABBREVIATED] ...
{
  "name": "TAG",                        1
  "displayName": "Current Docker image tag in registry",
  "description": "",
  "required": true
},
{
  "name": "IMAGESTREAM_TAG",            2
  "displayName": "Current ImageStreamTag in OpenShift",
  "description": "",
  "required": true
},
{
  "name": "REGISTRY",                   3
  "displayName": "Registry",
  "description": "The URL of the registry where the image resides",
  "required": true
},
{
  "name": "REGISTRY_PROJECT",           4
  "displayName": "The registry project where the image resides.",
  "description": "",
  "required": true
},
... [OUTPUT ABBREVIATED] ...

1
Required to control the deployment of certain tagged versions of an image
2
Required to control the deployment of certain tagged versions of an image
3
Required to use an external registry
4
Required to use an external registry