From 38e26d352e9517aed682dc49e687b2e6b671625e Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Mon, 11 Dec 2017 12:21:35 -0500 Subject: [PATCH 1/6] Use OpenShift Applier --- basic-python-flask/files/builds/dev/params | 3 + basic-python-flask/files/builds/template.yml | 99 +++++++++++++ .../files/deployments/dev/params | 4 + .../files/deployments/prod/params | 4 + .../files/deployments/stage/params | 4 + .../files/deployments/template.yml | 137 ++++++++++++++++++ .../files/projects/projects.yml | 27 ++++ .../inventory/group_vars/all.yml | 27 ++++ basic-python-flask/inventory/hosts | 2 + 9 files changed, 307 insertions(+) create mode 100644 basic-python-flask/files/builds/dev/params create mode 100644 basic-python-flask/files/builds/template.yml create mode 100644 basic-python-flask/files/deployments/dev/params create mode 100644 basic-python-flask/files/deployments/prod/params create mode 100644 basic-python-flask/files/deployments/stage/params create mode 100644 basic-python-flask/files/deployments/template.yml create mode 100644 basic-python-flask/files/projects/projects.yml create mode 100644 basic-python-flask/inventory/group_vars/all.yml create mode 100644 basic-python-flask/inventory/hosts diff --git a/basic-python-flask/files/builds/dev/params b/basic-python-flask/files/builds/dev/params new file mode 100644 index 00000000..a46407bb --- /dev/null +++ b/basic-python-flask/files/builds/dev/params @@ -0,0 +1,3 @@ +APPLICATION_NAME=flask-rest +NAMESPACE=basic-python-flask-build +SOURCE_REPOSITORY_URI=https://github.com/pabrahamsson/python-flask-rest.git diff --git a/basic-python-flask/files/builds/template.yml b/basic-python-flask/files/builds/template.yml new file mode 100644 index 00000000..516b85ca --- /dev/null +++ b/basic-python-flask/files/builds/template.yml @@ -0,0 +1,99 @@ +apiVersion: v1 +kind: Template +labels: + template: generic-python-jenkins-pipeline +metadata: + annotations: + description: Application template for Flask applications built using a Jenkins Pipeline + iconClass: icon-python + tags: flask, python, jenkins-ci + version: 1.0.0 + name: generic-python-jenkins-pipeline +objects: +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME}-pipeline + namespace: ${NAMESPACE} + spec: + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URI} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + triggers: + - type: GitHub + github: + secret: ${GITHUB_WEBHOOK_SECRET} + - type: ConfigChange + strategy: + type: JenkinsPipeline + jenkinsPipelineStrategy: + jenkinsfilePath: ${PIPELINE_SCRIPT} +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + output: + to: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + source: + binary: {} + type: Binary + strategy: + sourceStrategy: + from: + kind: ImageStreamTag + name: ${IMAGE_STREAM_TAG_NAME} + namespace: ${IMAGE_STREAM_NAMESPACE} + type: Source +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: flask-rest +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Git source URI for application + name: SOURCE_REPOSITORY_URI + required: true + value: https://github.com/redhat-cop/python-flask-rest.git +- description: Git branch/tag reference + name: SOURCE_REPOSITORY_REF + value: master +- description: Path within Git repository to build; empty for root of repository + name: CONTEXT_DIR + value: +- description: Path within Git repository pointing to the pipeline run script + name: PIPELINE_SCRIPT + value: Jenkinsfile +- description: Github trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GITHUB_WEBHOOK_SECRET + required: true +- description: Generic build trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GENERIC_WEBHOOK_SECRET + required: true +- description: Namespace in which the ImageStreams for Red Hat Middleware images are + installed. These ImageStreams are normally installed in the openshift namespace. + You should only need to modify this if you've installed the ImageStreams in a + different namespace/project. + name: IMAGE_STREAM_NAMESPACE + required: true + value: openshift +- description: Image stream tag for the image you'd like to use to build the application + name: IMAGE_STREAM_TAG_NAME + required: true + value: python:3.5 diff --git a/basic-python-flask/files/deployments/dev/params b/basic-python-flask/files/deployments/dev/params new file mode 100644 index 00000000..ae8a2f00 --- /dev/null +++ b/basic-python-flask/files/deployments/dev/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=flask-rest +NAMESPACE=basic-python-flask-dev +SA_NAMESPACE=basic-python-flask-build +READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/prod/params b/basic-python-flask/files/deployments/prod/params new file mode 100644 index 00000000..b306a524 --- /dev/null +++ b/basic-python-flask/files/deployments/prod/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=flask-rest +NAMESPACE=basic-python-flask-prod +SA_NAMESPACE=basic-python-flask-build +READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/stage/params b/basic-python-flask/files/deployments/stage/params new file mode 100644 index 00000000..52f24087 --- /dev/null +++ b/basic-python-flask/files/deployments/stage/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=flask-rest +NAMESPACE=basic-python-flask-stage +SA_NAMESPACE=basic-python-flask-build +READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/template.yml b/basic-python-flask/files/deployments/template.yml new file mode 100644 index 00000000..c276e76f --- /dev/null +++ b/basic-python-flask/files/deployments/template.yml @@ -0,0 +1,137 @@ +apiVersion: v1 +kind: Template +labels: + template: basic-python-flask +metadata: + annotations: + description: Application template for Flask applications built using a Jenkins Pipeline + iconClass: icon-python + tags: python, flask + version: 1.0.0 + name: basic-python-fask +objects: +- apiVersion: v1 + kind: Service + metadata: + annotations: + description: The web server's http port. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + ports: + - port: 8080 + targetPort: 8080 + selector: + deploymentConfig: ${APPLICATION_NAME} +- apiVersion: v1 + id: ${APPLICATION_NAME}-http + kind: Route + metadata: + annotations: + description: Route for application's http service. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + host: ${HOSTNAME_HTTP} + to: + name: ${APPLICATION_NAME} +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + replicas: 1 + selector: + deploymentConfig: ${APPLICATION_NAME} + strategy: + type: Rolling + template: + metadata: + labels: + application: ${APPLICATION_NAME} + deploymentConfig: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + spec: + containers: + - image: ${APPLICATION_NAME} + imagePullPolicy: Always + name: ${APPLICATION_NAME} + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - curl -s 'http://localhost:8080${READINESS_PATH}' + |grep -iq '${READINESS_RESPONSE}' + terminationGracePeriodSeconds: 60 + triggers: + - imageChangeParams: + automatic: true + containerNames: + - ${APPLICATION_NAME} + from: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + type: ImageChange + - type: ConfigChange +- apiVersion: v1 + groupNames: null + kind: RoleBinding + metadata: + creationTimestamp: null + labels: + template: basic-python-flask-template + name: jenkins_edit + namespace: ${NAMESPACE} + roleRef: + name: edit + subjects: + - kind: ServiceAccount + name: ${SA_NAME} + namespace: ${SA_NAMESPACE} + userNames: + - system:serviceaccount:${SA_NAMESPACE}:${SA_NAME} +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: flask-rest +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Name of a service account that can deploy to this project + name: SA_NAME + required: true + value: jenkins +- description: Namespace of service account that can deploy to this project + name: SA_NAMESPACE + required: true +- description: 'Custom hostname for http service route. Leave blank for default hostname, + e.g.: -.' + name: HOSTNAME_HTTP +- description: 'URI to check for app health' + name: READINESS_PATH + required: true + value: '/health' +- description: 'String value expected back from readiness check' + name: READINESS_RESPONSE + required: true + value: 'Hello World!' diff --git a/basic-python-flask/files/projects/projects.yml b/basic-python-flask/files/projects/projects.yml new file mode 100644 index 00000000..4c8f80b6 --- /dev/null +++ b/basic-python-flask/files/projects/projects.yml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: List +items: +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-python-flask-dev + creationTimestamp: null + displayName: Dev - Python Flask App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-python-flask-stage + creationTimestamp: null + displayName: Staging - Python Flask App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-python-flask-prod + creationTimestamp: null + displayName: Prod - Python Flask App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-python-flask-build + creationTimestam: null + displayName: Build - Jenkins is here diff --git a/basic-python-flask/inventory/group_vars/all.yml b/basic-python-flask/inventory/group_vars/all.yml new file mode 100644 index 00000000..ef45bb3c --- /dev/null +++ b/basic-python-flask/inventory/group_vars/all.yml @@ -0,0 +1,27 @@ +--- +openshift_cluster_content: +- object: projectrequest + content: + - name: basic-python-flask-spaces + file: "{{ inventory_dir }}/../files/projects/projects.yml" + file_action: create +- object: deployments + content: + - name: jenkins + namespace: basic-python-flask-build + template: openshift//jenkins-ephemeral + params: "{{ inventory_dir }}/../files/deployments/build/params" + - name: basic-python-flask-dev + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/dev/params" + - name: basic-python-flask-stage + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/stage/params" + - name: basic-python-flask-prod + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/prod/params" +- object: builds + content: + - name: jenkins + template: "{{ inventory_dir }}/../files/builds/template.yml" + params: "{{ inventory_dir }}/../files/builds/dev/params" diff --git a/basic-python-flask/inventory/hosts b/basic-python-flask/inventory/hosts new file mode 100644 index 00000000..05c07035 --- /dev/null +++ b/basic-python-flask/inventory/hosts @@ -0,0 +1,2 @@ +[seed-hosts] +localhost From a8082f0c4d7fedf18c17f974e27ecab1d4e44e0e Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Mon, 18 Dec 2017 14:09:23 -0500 Subject: [PATCH 2/6] Add python example w/ python-slave builder + coverage plugin --- basic-python-flask/files/builds/dev/params | 2 +- basic-python-flask/files/builds/template.yml | 13 +- .../files/deployments/build/params | 2 + .../files/deployments/jenkins.yml | 195 ++++++++++++++++++ .../files/imagestreams/imagestreams.yml | 42 ++++ .../inventory/group_vars/all.yml | 7 +- 6 files changed, 256 insertions(+), 5 deletions(-) create mode 100644 basic-python-flask/files/deployments/build/params create mode 100644 basic-python-flask/files/deployments/jenkins.yml create mode 100644 basic-python-flask/files/imagestreams/imagestreams.yml diff --git a/basic-python-flask/files/builds/dev/params b/basic-python-flask/files/builds/dev/params index a46407bb..20fe21fc 100644 --- a/basic-python-flask/files/builds/dev/params +++ b/basic-python-flask/files/builds/dev/params @@ -1,3 +1,3 @@ APPLICATION_NAME=flask-rest NAMESPACE=basic-python-flask-build -SOURCE_REPOSITORY_URI=https://github.com/pabrahamsson/python-flask-rest.git +SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/python-flask-rest.git diff --git a/basic-python-flask/files/builds/template.yml b/basic-python-flask/files/builds/template.yml index 516b85ca..28cad625 100644 --- a/basic-python-flask/files/builds/template.yml +++ b/basic-python-flask/files/builds/template.yml @@ -21,7 +21,7 @@ objects: source: type: Git git: - uri: ${SOURCE_REPOSITORY_URI} + uri: ${SOURCE_REPOSITORY_URL} ref: ${SOURCE_REPOSITORY_REF} contextDir: ${CONTEXT_DIR} triggers: @@ -55,6 +55,13 @@ objects: name: ${IMAGE_STREAM_TAG_NAME} namespace: ${IMAGE_STREAM_NAMESPACE} type: Source +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} parameters: - description: The name for the application. name: APPLICATION_NAME @@ -63,8 +70,8 @@ parameters: - description: The namespace to deploy into name: NAMESPACE required: true -- description: Git source URI for application - name: SOURCE_REPOSITORY_URI +- description: Git source URL for application + name: SOURCE_REPOSITORY_URL required: true value: https://github.com/redhat-cop/python-flask-rest.git - description: Git branch/tag reference diff --git a/basic-python-flask/files/deployments/build/params b/basic-python-flask/files/deployments/build/params new file mode 100644 index 00000000..3ac9f8e1 --- /dev/null +++ b/basic-python-flask/files/deployments/build/params @@ -0,0 +1,2 @@ +INSTALL_PLUGINS=cobertura:1.12 +MEMORY_LIMIT=512Mi diff --git a/basic-python-flask/files/deployments/jenkins.yml b/basic-python-flask/files/deployments/jenkins.yml new file mode 100644 index 00000000..e17caaf1 --- /dev/null +++ b/basic-python-flask/files/deployments/jenkins.yml @@ -0,0 +1,195 @@ +apiVersion: v1 +kind: Template +labels: + app: jenkins-ephemeral + template: jenkins-ephemeral-template +metadata: + annotations: + description: |- + Jenkins service, without persistent storage. + + WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing. + iconClass: icon-jenkins + openshift.io/display-name: Jenkins (Ephemeral) + openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html + openshift.io/long-description: This template deploys a Jenkins server capable + of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login. The + Jenkins configuration is stored in non-persistent storage, so this configuration + should be used for experimental purposes only. + openshift.io/provider-display-name: Red Hat, Inc. + openshift.io/support-url: https://access.redhat.com + tags: instant-app,jenkins + name: jenkins-ephemeral +objects: +- apiVersion: v1 + kind: Route + metadata: + annotations: + template.openshift.io/expose-uri: http://{.spec.host}{.spec.path} + name: ${JENKINS_SERVICE_NAME} + spec: + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + kind: DeploymentConfig + metadata: + annotations: + template.alpha.openshift.io/wait-for-ready: "true" + name: ${JENKINS_SERVICE_NAME} + spec: + replicas: 1 + selector: + name: ${JENKINS_SERVICE_NAME} + strategy: + type: Recreate + template: + metadata: + labels: + name: ${JENKINS_SERVICE_NAME} + spec: + containers: + - capabilities: {} + env: + - name: OPENSHIFT_ENABLE_OAUTH + value: ${ENABLE_OAUTH} + - name: OPENSHIFT_ENABLE_REDIRECT_PROMPT + value: "true" + - name: KUBERNETES_MASTER + value: https://kubernetes.default:443 + - name: KUBERNETES_TRUST_CERTIFICATES + value: "true" + - name: JENKINS_SERVICE_NAME + value: ${JENKINS_SERVICE_NAME} + - name: JNLP_SERVICE_NAME + value: ${JNLP_SERVICE_NAME} + - name: INSTALL_PLUGINS + value: ${INSTALL_PLUGINS} + image: ' ' + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 30 + httpGet: + path: /login + port: 8080 + initialDelaySeconds: 420 + timeoutSeconds: 3 + name: jenkins + readinessProbe: + httpGet: + path: /login + port: 8080 + initialDelaySeconds: 3 + timeoutSeconds: 3 + resources: + limits: + memory: ${MEMORY_LIMIT} + securityContext: + capabilities: {} + privileged: false + terminationMessagePath: /dev/termination-log + volumeMounts: + - mountPath: /var/lib/jenkins + name: ${JENKINS_SERVICE_NAME}-data + dnsPolicy: ClusterFirst + restartPolicy: Always + serviceAccountName: ${JENKINS_SERVICE_NAME} + volumes: + - emptyDir: + medium: "" + name: ${JENKINS_SERVICE_NAME}-data + triggers: + - imageChangeParams: + automatic: true + containerNames: + - jenkins + from: + kind: ImageStreamTag + name: ${JENKINS_IMAGE_STREAM_TAG} + namespace: ${NAMESPACE} + lastTriggeredImage: "" + type: ImageChange + - type: ConfigChange +- apiVersion: v1 + kind: ServiceAccount + metadata: + annotations: + serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}' + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + groupNames: null + kind: RoleBinding + metadata: + name: ${JENKINS_SERVICE_NAME}_edit + roleRef: + name: edit + subjects: + - kind: ServiceAccount + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + kind: Service + metadata: + name: ${JNLP_SERVICE_NAME} + spec: + ports: + - name: agent + nodePort: 0 + port: 50000 + protocol: TCP + targetPort: 50000 + selector: + name: ${JENKINS_SERVICE_NAME} + sessionAffinity: None + type: ClusterIP +- apiVersion: v1 + kind: Service + metadata: + annotations: + service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}", + "namespace": "", "kind": "Service"}]' + service.openshift.io/infrastructure: "true" + name: ${JENKINS_SERVICE_NAME} + spec: + ports: + - name: web + nodePort: 0 + port: 80 + protocol: TCP + targetPort: 8080 + selector: + name: ${JENKINS_SERVICE_NAME} + sessionAffinity: None + type: ClusterIP +parameters: +- description: The name of the OpenShift Service exposed for the Jenkins container. + displayName: Jenkins Service Name + name: JENKINS_SERVICE_NAME + value: jenkins +- description: The name of the service used for master/slave communication. + displayName: Jenkins JNLP Service Name + name: JNLP_SERVICE_NAME + value: jenkins-jnlp +- description: Whether to enable OAuth OpenShift integration. If false, the static + account 'admin' will be initialized with the password 'password'. + displayName: Enable OAuth in Jenkins + name: ENABLE_OAUTH + value: "true" +- description: Maximum amount of memory the container can use. + displayName: Memory Limit + name: MEMORY_LIMIT + value: 512Mi +- description: The OpenShift Namespace where the Jenkins ImageStream resides. + displayName: Jenkins ImageStream Namespace + name: NAMESPACE + value: openshift +- description: Name of the ImageStreamTag to be used for the Jenkins image. + displayName: Jenkins ImageStreamTag + name: JENKINS_IMAGE_STREAM_TAG + value: jenkins:latest +- description: Comma-separated list of additional plugins to install on startup. The format of each plugin spec is 'plugin-id:version' + displayName: Additional Jenkins plugins to install + name: INSTALL_PLUGINS + value: '' diff --git a/basic-python-flask/files/imagestreams/imagestreams.yml b/basic-python-flask/files/imagestreams/imagestreams.yml new file mode 100644 index 00000000..46d4a014 --- /dev/null +++ b/basic-python-flask/files/imagestreams/imagestreams.yml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: ImageStream +metadata: + annotations: + openshift.io/image.dockerRepositoryCheck: 2017-12-14T21:50:52Z + creationTimestamp: null + generation: 3 + name: jenkins-slave-python-centos7 +spec: + lookupPolicy: + local: false + tags: + - annotations: + role: jenkins-slave + slave-label: python + from: + kind: DockerImage + name: docker.io/pabrahamsson/jenkins-slave-python-centos7:latest + importPolicy: {} + name: latest + referencePolicy: + type: Source + - annotations: + role: jenkins-slave + slave-label: python + from: + kind: DockerImage + name: docker.io/pabrahamsson/jenkins-slave-python-centos7:v3.9 + importPolicy: {} + name: v3.9 + referencePolicy: + type: Source + - annotations: + role: jenkins-slave + slave-label: python + from: + kind: DockerImage + name: docker.io/pabrahamsson/jenkins-slave-python-centos7:v3.7 + importPolicy: {} + name: v3.7 + referencePolicy: + type: Source diff --git a/basic-python-flask/inventory/group_vars/all.yml b/basic-python-flask/inventory/group_vars/all.yml index ef45bb3c..fa101505 100644 --- a/basic-python-flask/inventory/group_vars/all.yml +++ b/basic-python-flask/inventory/group_vars/all.yml @@ -5,11 +5,16 @@ openshift_cluster_content: - name: basic-python-flask-spaces file: "{{ inventory_dir }}/../files/projects/projects.yml" file_action: create +- object: imagestream + content: + - name: jenkins-slave-python + file: "{{ inventory_dir }}/../files/imagestreams/imagestreams.yml" + namespace: basic-python-flask-build - object: deployments content: - name: jenkins namespace: basic-python-flask-build - template: openshift//jenkins-ephemeral + template: "{{ inventory_dir }}/../files/deployments/jenkins.yml" params: "{{ inventory_dir }}/../files/deployments/build/params" - name: basic-python-flask-dev template: "{{ inventory_dir }}/../files/deployments/template.yml" From 449d2f984a616beb312e4eba6921b53bf3d660e5 Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Fri, 29 Dec 2017 21:54:56 -0500 Subject: [PATCH 3/6] Add jenkins slave-python & sonarqube --- .../files/builds/jenkins-slave-template.yml | 67 +++++++++++++++++++ .../files/builds/jenkins-slave/params | 4 ++ basic-python-flask/files/builds/template.yml | 7 +- .../files/deployments/build/params | 2 +- .../files/deployments/postgresql/params | 4 ++ .../files/deployments/sonar/params | 9 +++ .../inventory/group_vars/all.yml | 14 +++- 7 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 basic-python-flask/files/builds/jenkins-slave-template.yml create mode 100644 basic-python-flask/files/builds/jenkins-slave/params create mode 100644 basic-python-flask/files/deployments/postgresql/params create mode 100644 basic-python-flask/files/deployments/sonar/params diff --git a/basic-python-flask/files/builds/jenkins-slave-template.yml b/basic-python-flask/files/builds/jenkins-slave-template.yml new file mode 100644 index 00000000..1d758d6c --- /dev/null +++ b/basic-python-flask/files/builds/jenkins-slave-template.yml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: Template +labels: + template: jenkins-slave +metadata: + annotations: + description: Template for Jenkins slave + iconClass: icon-jenkins + tags: instant-app,jenkins + name: jenkins-slave +objects: +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${SLAVE_NAME} + name: ${SLAVE_NAME} + namespace: ${NAMESPACE} + spec: + output: + to: + kind: ImageStreamTag + name: ${SLAVE_NAME}:latest + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + strategy: + dockerStrategy: + from: + kind: DockerImage + name: ${JENKINS_IMAGE} + triggers: + - type: ConfigChange +- apiVersion: v1 + kind: ImageStream + metadata: + annotations: + slave-label: python + labels: + application: ${SLAVE_NAME} + role: jenkins-slave + name: ${SLAVE_NAME} + namespace: ${NAMESPACE} +parameters: +- description: The name for the application. + name: SLAVE_NAME + required: true +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Git source URL for application + name: SOURCE_REPOSITORY_URL + required: true + value: https://github.com/pabrahamsson/jenkins.git +- description: Git branch/tag reference + name: SOURCE_REPOSITORY_REF + value: master +- description: Path within Git repository to build; empty for root of repository + name: CONTEXT_DIR + value: +- description: The Jenkins source image + name: JENKINS_IMAGE + required: true + value: openshift/jenkins-slave-base-centos7 diff --git a/basic-python-flask/files/builds/jenkins-slave/params b/basic-python-flask/files/builds/jenkins-slave/params new file mode 100644 index 00000000..8e54048b --- /dev/null +++ b/basic-python-flask/files/builds/jenkins-slave/params @@ -0,0 +1,4 @@ +SLAVE_NAME=slave-python +NAMESPACE=basic-python-flask-build +CONTEXT_DIR=slave-python +SOURCE_REPOSITORY_REF=slave-python diff --git a/basic-python-flask/files/builds/template.yml b/basic-python-flask/files/builds/template.yml index 28cad625..8e7e6f78 100644 --- a/basic-python-flask/files/builds/template.yml +++ b/basic-python-flask/files/builds/template.yml @@ -46,8 +46,11 @@ objects: kind: ImageStreamTag name: ${APPLICATION_NAME}:latest source: - binary: {} - type: Binary + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} strategy: sourceStrategy: from: diff --git a/basic-python-flask/files/deployments/build/params b/basic-python-flask/files/deployments/build/params index 3ac9f8e1..c226f6bb 100644 --- a/basic-python-flask/files/deployments/build/params +++ b/basic-python-flask/files/deployments/build/params @@ -1,2 +1,2 @@ -INSTALL_PLUGINS=cobertura:1.12 +INSTALL_PLUGINS=cobertura:1.12,sonar:2.6.1 MEMORY_LIMIT=512Mi diff --git a/basic-python-flask/files/deployments/postgresql/params b/basic-python-flask/files/deployments/postgresql/params new file mode 100644 index 00000000..1867b6b8 --- /dev/null +++ b/basic-python-flask/files/deployments/postgresql/params @@ -0,0 +1,4 @@ +POSTGRESQL_DATABASE=sonar +VOLUME_CAPACITY=5 +POSTGRESQL_PASSWORD=sonar +POSTGRESQL_USER=sonar diff --git a/basic-python-flask/files/deployments/sonar/params b/basic-python-flask/files/deployments/sonar/params new file mode 100644 index 00000000..909dba70 --- /dev/null +++ b/basic-python-flask/files/deployments/sonar/params @@ -0,0 +1,9 @@ +MEMORY_LIMIT=1Gi +VOLUME_CAPACITY=2Gi +MEMORY_LIMIT=2Gi +CPU_LIMIT=1 +JDBC_URL=jdbc:postgresql://postgresql:5432/sonar +JDBC_USER=sonar +JDBC_PASSWORD=sonar +SOURCE_REPOSITORY_URL=https://github.com/rht-labs/labs-ci-cd +SOURCE_REPOSITORY_CONTEXT_DIR=docker/sonarqube diff --git a/basic-python-flask/inventory/group_vars/all.yml b/basic-python-flask/inventory/group_vars/all.yml index fa101505..1cab57ca 100644 --- a/basic-python-flask/inventory/group_vars/all.yml +++ b/basic-python-flask/inventory/group_vars/all.yml @@ -5,13 +5,21 @@ openshift_cluster_content: - name: basic-python-flask-spaces file: "{{ inventory_dir }}/../files/projects/projects.yml" file_action: create -- object: imagestream +- object: builds content: - name: jenkins-slave-python - file: "{{ inventory_dir }}/../files/imagestreams/imagestreams.yml" - namespace: basic-python-flask-build + template: "{{ inventory_dir }}/../files/builds/jenkins-slave-template.yml" + params: "{{ inventory_dir }}/../files/builds/jenkins-slave/params" - object: deployments content: + - name: postgresql + namespace: basic-python-flask-build + template: openshift//postgresql-persistent + params: "{{ inventory_dir }}/../files/deployments/postgresql/params" + - name: sonarqube + namespace: basic-python-flask-build + template: https://raw.githubusercontent.com/rht-labs/labs-ci-cd/master/openshift-templates/sonarqube/template.json + params: "{{ inventory_dir }}/../files/deployments/sonar/params" - name: jenkins namespace: basic-python-flask-build template: "{{ inventory_dir }}/../files/deployments/jenkins.yml" From 24dd3fe7c54cb2a9de46edd5d196d3b3c2ab8ade Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Fri, 29 Dec 2017 23:29:30 -0500 Subject: [PATCH 4/6] Add NodeJS Express REST application pipeline --- basic-nodejs-express/files/builds/dev/params | 3 + .../files/builds/jenkins-slave-template.yml | 67 ++++++ .../files/builds/jenkins-slave/params | 4 + .../files/builds/template.yml | 109 ++++++++++ .../files/deployments/build/params | 2 + .../files/deployments/dev/params | 4 + .../files/deployments/jenkins.yml | 195 ++++++++++++++++++ .../files/deployments/postgresql/params | 4 + .../files/deployments/prod/params | 4 + .../files/deployments/sonar/params | 9 + .../files/deployments/stage/params | 4 + .../files/deployments/template.yml | 137 ++++++++++++ .../files/projects/projects.yml | 27 +++ .../inventory/group_vars/all.yml | 40 ++++ basic-nodejs-express/inventory/hosts | 2 + 15 files changed, 611 insertions(+) create mode 100644 basic-nodejs-express/files/builds/dev/params create mode 100644 basic-nodejs-express/files/builds/jenkins-slave-template.yml create mode 100644 basic-nodejs-express/files/builds/jenkins-slave/params create mode 100644 basic-nodejs-express/files/builds/template.yml create mode 100644 basic-nodejs-express/files/deployments/build/params create mode 100644 basic-nodejs-express/files/deployments/dev/params create mode 100644 basic-nodejs-express/files/deployments/jenkins.yml create mode 100644 basic-nodejs-express/files/deployments/postgresql/params create mode 100644 basic-nodejs-express/files/deployments/prod/params create mode 100644 basic-nodejs-express/files/deployments/sonar/params create mode 100644 basic-nodejs-express/files/deployments/stage/params create mode 100644 basic-nodejs-express/files/deployments/template.yml create mode 100644 basic-nodejs-express/files/projects/projects.yml create mode 100644 basic-nodejs-express/inventory/group_vars/all.yml create mode 100644 basic-nodejs-express/inventory/hosts diff --git a/basic-nodejs-express/files/builds/dev/params b/basic-nodejs-express/files/builds/dev/params new file mode 100644 index 00000000..1e31f220 --- /dev/null +++ b/basic-nodejs-express/files/builds/dev/params @@ -0,0 +1,3 @@ +APPLICATION_NAME=express-rest +NAMESPACE=basic-nodejs-express-build +SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/nodejs-express-rest.git diff --git a/basic-nodejs-express/files/builds/jenkins-slave-template.yml b/basic-nodejs-express/files/builds/jenkins-slave-template.yml new file mode 100644 index 00000000..42355da7 --- /dev/null +++ b/basic-nodejs-express/files/builds/jenkins-slave-template.yml @@ -0,0 +1,67 @@ +apiVersion: v1 +kind: Template +labels: + template: jenkins-slave +metadata: + annotations: + description: Template for Jenkins slave + iconClass: icon-jenkins + tags: instant-app,jenkins + name: jenkins-slave +objects: +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${SLAVE_NAME} + name: ${SLAVE_NAME} + namespace: ${NAMESPACE} + spec: + output: + to: + kind: ImageStreamTag + name: ${SLAVE_NAME}:latest + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + strategy: + dockerStrategy: + from: + kind: DockerImage + name: ${JENKINS_IMAGE} + triggers: + - type: ConfigChange +- apiVersion: v1 + kind: ImageStream + metadata: + annotations: + slave-label: nodejs8 + labels: + application: ${SLAVE_NAME} + role: jenkins-slave + name: ${SLAVE_NAME} + namespace: ${NAMESPACE} +parameters: +- description: The name for the application. + name: SLAVE_NAME + required: true +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Git source URL for application + name: SOURCE_REPOSITORY_URL + required: true + value: https://github.com/pabrahamsson/jenkins.git +- description: Git branch/tag reference + name: SOURCE_REPOSITORY_REF + value: master +- description: Path within Git repository to build; empty for root of repository + name: CONTEXT_DIR + value: +- description: The Jenkins source image + name: JENKINS_IMAGE + required: true + value: openshift/jenkins-slave-base-centos7 diff --git a/basic-nodejs-express/files/builds/jenkins-slave/params b/basic-nodejs-express/files/builds/jenkins-slave/params new file mode 100644 index 00000000..aebca590 --- /dev/null +++ b/basic-nodejs-express/files/builds/jenkins-slave/params @@ -0,0 +1,4 @@ +SLAVE_NAME=slave-nodejs +NAMESPACE=basic-nodejs-express-build +CONTEXT_DIR=slave-nodejs +SOURCE_REPOSITORY_REF=slave-nodejs-8 diff --git a/basic-nodejs-express/files/builds/template.yml b/basic-nodejs-express/files/builds/template.yml new file mode 100644 index 00000000..eecb762b --- /dev/null +++ b/basic-nodejs-express/files/builds/template.yml @@ -0,0 +1,109 @@ +apiVersion: v1 +kind: Template +labels: + template: generic-nodejs-jenkins-pipeline +metadata: + annotations: + description: Application template for Express applications built using a Jenkins Pipeline + iconClass: icon-nodejs + tags: flask, nodejs, jenkins-ci + version: 1.0.0 + name: generic-nodejs-jenkins-pipeline +objects: +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME}-pipeline + namespace: ${NAMESPACE} + spec: + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + triggers: + - type: GitHub + github: + secret: ${GITHUB_WEBHOOK_SECRET} + - type: ConfigChange + strategy: + type: JenkinsPipeline + jenkinsPipelineStrategy: + jenkinsfilePath: ${PIPELINE_SCRIPT} +- kind: BuildConfig + apiVersion: v1 + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + output: + to: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + source: + type: Git + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + contextDir: ${CONTEXT_DIR} + strategy: + sourceStrategy: + from: + kind: ImageStreamTag + name: ${IMAGE_STREAM_TAG_NAME} + namespace: ${IMAGE_STREAM_NAMESPACE} + type: Source +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: express-rest +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Git source URL for application + name: SOURCE_REPOSITORY_URL + required: true + value: https://github.com/redhat-cop/nodejs-express-rest.git +- description: Git branch/tag reference + name: SOURCE_REPOSITORY_REF + value: master +- description: Path within Git repository to build; empty for root of repository + name: CONTEXT_DIR + value: +- description: Path within Git repository pointing to the pipeline run script + name: PIPELINE_SCRIPT + value: Jenkinsfile +- description: Github trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GITHUB_WEBHOOK_SECRET + required: true +- description: Generic build trigger secret + from: '[a-zA-Z0-9]{8}' + generate: expression + name: GENERIC_WEBHOOK_SECRET + required: true +- description: Namespace in which the ImageStreams for Red Hat Middleware images are + installed. These ImageStreams are normally installed in the openshift namespace. + You should only need to modify this if you've installed the ImageStreams in a + different namespace/project. + name: IMAGE_STREAM_NAMESPACE + required: true + value: openshift +- description: Image stream tag for the image you'd like to use to build the application + name: IMAGE_STREAM_TAG_NAME + required: true + value: nodejs:latest diff --git a/basic-nodejs-express/files/deployments/build/params b/basic-nodejs-express/files/deployments/build/params new file mode 100644 index 00000000..c226f6bb --- /dev/null +++ b/basic-nodejs-express/files/deployments/build/params @@ -0,0 +1,2 @@ +INSTALL_PLUGINS=cobertura:1.12,sonar:2.6.1 +MEMORY_LIMIT=512Mi diff --git a/basic-nodejs-express/files/deployments/dev/params b/basic-nodejs-express/files/deployments/dev/params new file mode 100644 index 00000000..09ba735b --- /dev/null +++ b/basic-nodejs-express/files/deployments/dev/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=express-rest +NAMESPACE=basic-nodejs-express-dev +SA_NAMESPACE=basic-nodejs-express-build +READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/jenkins.yml b/basic-nodejs-express/files/deployments/jenkins.yml new file mode 100644 index 00000000..e17caaf1 --- /dev/null +++ b/basic-nodejs-express/files/deployments/jenkins.yml @@ -0,0 +1,195 @@ +apiVersion: v1 +kind: Template +labels: + app: jenkins-ephemeral + template: jenkins-ephemeral-template +metadata: + annotations: + description: |- + Jenkins service, without persistent storage. + + WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing. + iconClass: icon-jenkins + openshift.io/display-name: Jenkins (Ephemeral) + openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html + openshift.io/long-description: This template deploys a Jenkins server capable + of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login. The + Jenkins configuration is stored in non-persistent storage, so this configuration + should be used for experimental purposes only. + openshift.io/provider-display-name: Red Hat, Inc. + openshift.io/support-url: https://access.redhat.com + tags: instant-app,jenkins + name: jenkins-ephemeral +objects: +- apiVersion: v1 + kind: Route + metadata: + annotations: + template.openshift.io/expose-uri: http://{.spec.host}{.spec.path} + name: ${JENKINS_SERVICE_NAME} + spec: + tls: + insecureEdgeTerminationPolicy: Redirect + termination: edge + to: + kind: Service + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + kind: DeploymentConfig + metadata: + annotations: + template.alpha.openshift.io/wait-for-ready: "true" + name: ${JENKINS_SERVICE_NAME} + spec: + replicas: 1 + selector: + name: ${JENKINS_SERVICE_NAME} + strategy: + type: Recreate + template: + metadata: + labels: + name: ${JENKINS_SERVICE_NAME} + spec: + containers: + - capabilities: {} + env: + - name: OPENSHIFT_ENABLE_OAUTH + value: ${ENABLE_OAUTH} + - name: OPENSHIFT_ENABLE_REDIRECT_PROMPT + value: "true" + - name: KUBERNETES_MASTER + value: https://kubernetes.default:443 + - name: KUBERNETES_TRUST_CERTIFICATES + value: "true" + - name: JENKINS_SERVICE_NAME + value: ${JENKINS_SERVICE_NAME} + - name: JNLP_SERVICE_NAME + value: ${JNLP_SERVICE_NAME} + - name: INSTALL_PLUGINS + value: ${INSTALL_PLUGINS} + image: ' ' + imagePullPolicy: IfNotPresent + livenessProbe: + failureThreshold: 30 + httpGet: + path: /login + port: 8080 + initialDelaySeconds: 420 + timeoutSeconds: 3 + name: jenkins + readinessProbe: + httpGet: + path: /login + port: 8080 + initialDelaySeconds: 3 + timeoutSeconds: 3 + resources: + limits: + memory: ${MEMORY_LIMIT} + securityContext: + capabilities: {} + privileged: false + terminationMessagePath: /dev/termination-log + volumeMounts: + - mountPath: /var/lib/jenkins + name: ${JENKINS_SERVICE_NAME}-data + dnsPolicy: ClusterFirst + restartPolicy: Always + serviceAccountName: ${JENKINS_SERVICE_NAME} + volumes: + - emptyDir: + medium: "" + name: ${JENKINS_SERVICE_NAME}-data + triggers: + - imageChangeParams: + automatic: true + containerNames: + - jenkins + from: + kind: ImageStreamTag + name: ${JENKINS_IMAGE_STREAM_TAG} + namespace: ${NAMESPACE} + lastTriggeredImage: "" + type: ImageChange + - type: ConfigChange +- apiVersion: v1 + kind: ServiceAccount + metadata: + annotations: + serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}' + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + groupNames: null + kind: RoleBinding + metadata: + name: ${JENKINS_SERVICE_NAME}_edit + roleRef: + name: edit + subjects: + - kind: ServiceAccount + name: ${JENKINS_SERVICE_NAME} +- apiVersion: v1 + kind: Service + metadata: + name: ${JNLP_SERVICE_NAME} + spec: + ports: + - name: agent + nodePort: 0 + port: 50000 + protocol: TCP + targetPort: 50000 + selector: + name: ${JENKINS_SERVICE_NAME} + sessionAffinity: None + type: ClusterIP +- apiVersion: v1 + kind: Service + metadata: + annotations: + service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}", + "namespace": "", "kind": "Service"}]' + service.openshift.io/infrastructure: "true" + name: ${JENKINS_SERVICE_NAME} + spec: + ports: + - name: web + nodePort: 0 + port: 80 + protocol: TCP + targetPort: 8080 + selector: + name: ${JENKINS_SERVICE_NAME} + sessionAffinity: None + type: ClusterIP +parameters: +- description: The name of the OpenShift Service exposed for the Jenkins container. + displayName: Jenkins Service Name + name: JENKINS_SERVICE_NAME + value: jenkins +- description: The name of the service used for master/slave communication. + displayName: Jenkins JNLP Service Name + name: JNLP_SERVICE_NAME + value: jenkins-jnlp +- description: Whether to enable OAuth OpenShift integration. If false, the static + account 'admin' will be initialized with the password 'password'. + displayName: Enable OAuth in Jenkins + name: ENABLE_OAUTH + value: "true" +- description: Maximum amount of memory the container can use. + displayName: Memory Limit + name: MEMORY_LIMIT + value: 512Mi +- description: The OpenShift Namespace where the Jenkins ImageStream resides. + displayName: Jenkins ImageStream Namespace + name: NAMESPACE + value: openshift +- description: Name of the ImageStreamTag to be used for the Jenkins image. + displayName: Jenkins ImageStreamTag + name: JENKINS_IMAGE_STREAM_TAG + value: jenkins:latest +- description: Comma-separated list of additional plugins to install on startup. The format of each plugin spec is 'plugin-id:version' + displayName: Additional Jenkins plugins to install + name: INSTALL_PLUGINS + value: '' diff --git a/basic-nodejs-express/files/deployments/postgresql/params b/basic-nodejs-express/files/deployments/postgresql/params new file mode 100644 index 00000000..1867b6b8 --- /dev/null +++ b/basic-nodejs-express/files/deployments/postgresql/params @@ -0,0 +1,4 @@ +POSTGRESQL_DATABASE=sonar +VOLUME_CAPACITY=5 +POSTGRESQL_PASSWORD=sonar +POSTGRESQL_USER=sonar diff --git a/basic-nodejs-express/files/deployments/prod/params b/basic-nodejs-express/files/deployments/prod/params new file mode 100644 index 00000000..c95aaa25 --- /dev/null +++ b/basic-nodejs-express/files/deployments/prod/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=express-rest +NAMESPACE=basic-nodejs-express-prod +SA_NAMESPACE=basic-nodejs-express-build +READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/sonar/params b/basic-nodejs-express/files/deployments/sonar/params new file mode 100644 index 00000000..909dba70 --- /dev/null +++ b/basic-nodejs-express/files/deployments/sonar/params @@ -0,0 +1,9 @@ +MEMORY_LIMIT=1Gi +VOLUME_CAPACITY=2Gi +MEMORY_LIMIT=2Gi +CPU_LIMIT=1 +JDBC_URL=jdbc:postgresql://postgresql:5432/sonar +JDBC_USER=sonar +JDBC_PASSWORD=sonar +SOURCE_REPOSITORY_URL=https://github.com/rht-labs/labs-ci-cd +SOURCE_REPOSITORY_CONTEXT_DIR=docker/sonarqube diff --git a/basic-nodejs-express/files/deployments/stage/params b/basic-nodejs-express/files/deployments/stage/params new file mode 100644 index 00000000..d6f8541e --- /dev/null +++ b/basic-nodejs-express/files/deployments/stage/params @@ -0,0 +1,4 @@ +APPLICATION_NAME=express-rest +NAMESPACE=basic-nodejs-express-stage +SA_NAMESPACE=basic-nodejs-express-build +READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/template.yml b/basic-nodejs-express/files/deployments/template.yml new file mode 100644 index 00000000..d2b9bc36 --- /dev/null +++ b/basic-nodejs-express/files/deployments/template.yml @@ -0,0 +1,137 @@ +apiVersion: v1 +kind: Template +labels: + template: basic-nodejs-express +metadata: + annotations: + description: Application template for Express applications built using a Jenkins Pipeline + iconClass: icon-nodejs + tags: nodejs, express + version: 1.0.0 + name: basic-nodejs-express +objects: +- apiVersion: v1 + kind: Service + metadata: + annotations: + description: The web server's http port. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + ports: + - port: 8080 + targetPort: 8080 + selector: + deploymentConfig: ${APPLICATION_NAME} +- apiVersion: v1 + id: ${APPLICATION_NAME}-http + kind: Route + metadata: + annotations: + description: Route for application's http service. + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + host: ${HOSTNAME_HTTP} + to: + name: ${APPLICATION_NAME} +- apiVersion: v1 + kind: ImageStream + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + application: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + namespace: ${NAMESPACE} + spec: + replicas: 1 + selector: + deploymentConfig: ${APPLICATION_NAME} + strategy: + type: Rolling + template: + metadata: + labels: + application: ${APPLICATION_NAME} + deploymentConfig: ${APPLICATION_NAME} + name: ${APPLICATION_NAME} + spec: + containers: + - image: ${APPLICATION_NAME} + imagePullPolicy: Always + name: ${APPLICATION_NAME} + ports: + - containerPort: 8080 + name: http + protocol: TCP + readinessProbe: + exec: + command: + - /bin/bash + - -c + - curl -s 'http://localhost:8080${READINESS_PATH}' + |grep -iq '${READINESS_RESPONSE}' + terminationGracePeriodSeconds: 60 + triggers: + - imageChangeParams: + automatic: true + containerNames: + - ${APPLICATION_NAME} + from: + kind: ImageStreamTag + name: ${APPLICATION_NAME}:latest + type: ImageChange + - type: ConfigChange +- apiVersion: v1 + groupNames: null + kind: RoleBinding + metadata: + creationTimestamp: null + labels: + template: basic-nodejs-express-template + name: jenkins_edit + namespace: ${NAMESPACE} + roleRef: + name: edit + subjects: + - kind: ServiceAccount + name: ${SA_NAME} + namespace: ${SA_NAMESPACE} + userNames: + - system:serviceaccount:${SA_NAMESPACE}:${SA_NAME} +parameters: +- description: The name for the application. + name: APPLICATION_NAME + required: true + value: express-rest +- description: The namespace to deploy into + name: NAMESPACE + required: true +- description: Name of a service account that can deploy to this project + name: SA_NAME + required: true + value: jenkins +- description: Namespace of service account that can deploy to this project + name: SA_NAMESPACE + required: true +- description: 'Custom hostname for http service route. Leave blank for default hostname, + e.g.: -.' + name: HOSTNAME_HTTP +- description: 'URI to check for app health' + name: READINESS_PATH + required: true + value: '/health' +- description: 'String value expected back from readiness check' + name: READINESS_RESPONSE + required: true + value: 'Hello World!' diff --git a/basic-nodejs-express/files/projects/projects.yml b/basic-nodejs-express/files/projects/projects.yml new file mode 100644 index 00000000..c2ce552f --- /dev/null +++ b/basic-nodejs-express/files/projects/projects.yml @@ -0,0 +1,27 @@ +apiVersion: v1 +kind: List +items: +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-nodejs-express-dev + creationTimestamp: null + displayName: Dev - NodeJS Express App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-nodejs-express-stage + creationTimestamp: null + displayName: Staging - NodeJS Express App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-nodejs-express-prod + creationTimestamp: null + displayName: Prod - NodeJS Express App +- kind: ProjectRequest + apiVersion: v1 + metadata: + name: basic-nodejs-express-build + creationTimestam: null + displayName: Build - Jenkins is here diff --git a/basic-nodejs-express/inventory/group_vars/all.yml b/basic-nodejs-express/inventory/group_vars/all.yml new file mode 100644 index 00000000..76d2f3b0 --- /dev/null +++ b/basic-nodejs-express/inventory/group_vars/all.yml @@ -0,0 +1,40 @@ +--- +openshift_cluster_content: +- object: projectrequest + content: + - name: basic-nodejs-express-spaces + file: "{{ inventory_dir }}/../files/projects/projects.yml" + file_action: create +- object: builds + content: + - name: jenkins-slave-nodejs + template: "{{ inventory_dir }}/../files/builds/jenkins-slave-template.yml" + params: "{{ inventory_dir }}/../files/builds/jenkins-slave/params" +- object: deployments + content: + - name: postgresql + namespace: basic-nodejs-express-build + template: openshift//postgresql-persistent + params: "{{ inventory_dir }}/../files/deployments/postgresql/params" + - name: sonarqube + namespace: basic-nodejs-express-build + template: https://raw.githubusercontent.com/rht-labs/labs-ci-cd/master/openshift-templates/sonarqube/template.json + params: "{{ inventory_dir }}/../files/deployments/sonar/params" + - name: jenkins + namespace: basic-nodejs-express-build + template: "{{ inventory_dir }}/../files/deployments/jenkins.yml" + params: "{{ inventory_dir }}/../files/deployments/build/params" + - name: basic-nodejs-express-dev + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/dev/params" + - name: basic-nodejs-express-stage + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/stage/params" + - name: basic-nodejs-express-prod + template: "{{ inventory_dir }}/../files/deployments/template.yml" + params: "{{ inventory_dir }}/../files/deployments/prod/params" +- object: builds + content: + - name: jenkins + template: "{{ inventory_dir }}/../files/builds/template.yml" + params: "{{ inventory_dir }}/../files/builds/dev/params" diff --git a/basic-nodejs-express/inventory/hosts b/basic-nodejs-express/inventory/hosts new file mode 100644 index 00000000..05c07035 --- /dev/null +++ b/basic-nodejs-express/inventory/hosts @@ -0,0 +1,2 @@ +[seed-hosts] +localhost From 76bbb2b791eb273a7cb08b097e38432d6cb9953d Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Sun, 21 Oct 2018 20:23:50 -0400 Subject: [PATCH 5/6] Use pipeline-library for basic-spring-boot app, fixes #32 --- .../.applier/group_vars/seed-hosts.yml | 10 +-- basic-spring-boot/.gitignore | 1 + basic-spring-boot/.openshift/params/build-dev | 2 +- .../.openshift/params/deployment-dev | 2 +- .../.openshift/params/deployment-prod | 2 +- .../.openshift/params/deployment-stage | 2 +- basic-spring-boot/Jenkinsfile | 86 +++++-------------- basic-spring-boot/README.md | 3 +- 8 files changed, 32 insertions(+), 76 deletions(-) create mode 100644 basic-spring-boot/.gitignore diff --git a/basic-spring-boot/.applier/group_vars/seed-hosts.yml b/basic-spring-boot/.applier/group_vars/seed-hosts.yml index 87a8a3a5..5cba7710 100644 --- a/basic-spring-boot/.applier/group_vars/seed-hosts.yml +++ b/basic-spring-boot/.applier/group_vars/seed-hosts.yml @@ -4,6 +4,11 @@ openshift_cluster_content: - name: "create environments" file: "{{ inventory_dir }}/../.openshift/projects/projects.yml" action: create +- object: builds + content: + - name: "deploy build pipeline to dev" + template: "{{ inventory_dir }}/../.openshift/templates/build.yml" + params: "{{ inventory_dir }}/../.openshift/params/build-dev" - object: deployments content: - name: "deploy dev environment" @@ -15,8 +20,3 @@ openshift_cluster_content: - name: "deply prod environment" template: "{{ inventory_dir }}/../.openshift/templates/deployment.yml" params: "{{ inventory_dir }}/../.openshift/params/deployment-prod" -- object: builds - content: - - name: "deploy build pipeline to dev" - template: "{{ inventory_dir }}/../.openshift/templates/build.yml" - params: "{{ inventory_dir }}/../.openshift/params/build-dev" diff --git a/basic-spring-boot/.gitignore b/basic-spring-boot/.gitignore new file mode 100644 index 00000000..40112124 --- /dev/null +++ b/basic-spring-boot/.gitignore @@ -0,0 +1 @@ +galaxy diff --git a/basic-spring-boot/.openshift/params/build-dev b/basic-spring-boot/.openshift/params/build-dev index ba538d24..e158b26a 100644 --- a/basic-spring-boot/.openshift/params/build-dev +++ b/basic-spring-boot/.openshift/params/build-dev @@ -1,4 +1,4 @@ -APPLICATION_NAME=spring-rest +APPLICATION_NAME=basic-spring-boot NAMESPACE=basic-spring-boot-build SOURCE_REPOSITORY_URL=https://github.com/redhat-cop/container-pipelines.git SOURCE_REPOSITORY_REF=master diff --git a/basic-spring-boot/.openshift/params/deployment-dev b/basic-spring-boot/.openshift/params/deployment-dev index 441eebe9..f2480bb7 100644 --- a/basic-spring-boot/.openshift/params/deployment-dev +++ b/basic-spring-boot/.openshift/params/deployment-dev @@ -1,4 +1,4 @@ -APPLICATION_NAME=spring-rest +APPLICATION_NAME=basic-spring-boot NAMESPACE=basic-spring-boot-dev SA_NAMESPACE=basic-spring-boot-build READINESS_RESPONSE=status.:.UP diff --git a/basic-spring-boot/.openshift/params/deployment-prod b/basic-spring-boot/.openshift/params/deployment-prod index e09e4dda..982243a5 100644 --- a/basic-spring-boot/.openshift/params/deployment-prod +++ b/basic-spring-boot/.openshift/params/deployment-prod @@ -1,4 +1,4 @@ -APPLICATION_NAME=spring-rest +APPLICATION_NAME=basic-spring-boot NAMESPACE=basic-spring-boot-prod SA_NAMESPACE=basic-spring-boot-build READINESS_RESPONSE=status.:.UP diff --git a/basic-spring-boot/.openshift/params/deployment-stage b/basic-spring-boot/.openshift/params/deployment-stage index d0c280ad..74731b29 100644 --- a/basic-spring-boot/.openshift/params/deployment-stage +++ b/basic-spring-boot/.openshift/params/deployment-stage @@ -1,4 +1,4 @@ -APPLICATION_NAME=spring-rest +APPLICATION_NAME=basic-spring-boot NAMESPACE=basic-spring-boot-stage SA_NAME=jenkins SA_NAMESPACE=basic-spring-boot-build diff --git a/basic-spring-boot/Jenkinsfile b/basic-spring-boot/Jenkinsfile index 97d0ef1e..253ef808 100644 --- a/basic-spring-boot/Jenkinsfile +++ b/basic-spring-boot/Jenkinsfile @@ -1,13 +1,20 @@ +library identifier: "pipeline-library@master", +retriever: modernSCM( + [ + $class: "GitSCMSource", + remote: "https://github.com/redhat-cop/pipeline-library.git" + ] +) + openshift.withCluster() { env.NAMESPACE = openshift.project() env.POM_FILE = env.BUILD_CONTEXT_DIR ? "${env.BUILD_CONTEXT_DIR}/pom.xml" : "pom.xml" - env.APP_NAME = "${env.JOB_NAME}".replaceAll(/-?pipeline-?/, '').replaceAll(/-?${env.NAMESPACE}-?/, '').replaceAll("/", '') + env.APP_NAME = "${JOB_NAME}".replaceAll(/-build.*/, '') echo "Starting Pipeline for ${APP_NAME}..." - def projectBase = "${env.NAMESPACE}".replaceAll(/-build/, '') - env.STAGE0 = "${projectBase}-build" - env.STAGE1 = "${projectBase}-dev" - env.STAGE2 = "${projectBase}-stage" - env.STAGE3 = "${projectBase}-prod" + env.BUILD = "${env.NAMESPACE}" + env.DEV = "${APP_NAME}-dev" + env.STAGE = "${APP_NAME}-stage" + env.PROD = "${APP_NAME}-prod" } pipeline { @@ -65,95 +72,44 @@ pipeline { // Giving all the artifacts to OpenShift Binary Build // This places your artifacts into right location inside your S2I image // if the S2I image supports it. - script { - openshift.withCluster() { - openshift.withProject("${STAGE0}") { - openshift.selector("bc", "${APP_NAME}").startBuild("--from-dir=oc-build").logs("-f") - } - } - } + binaryBuild(projectName: env.BUILD, buildConfigName: env.APP_NAME, artifactsDirectoryName: "oc-build") } } stage('Promote from Build to Dev') { steps { - script { - openshift.withCluster() { - openshift.tag("${env.STAGE0}/${env.APP_NAME}:latest", "${env.STAGE1}/${env.APP_NAME}:latest") - } - } + tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.BUILD, toImagePath: env.DEV) } } stage ('Verify Deployment to Dev') { steps { - script { - openshift.withCluster() { - openshift.withProject("${STAGE1}") { - def dcObj = openshift.selector('dc', env.APP_NAME).object() - def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"]) - podSelector.untilEach { - echo "pod: ${it.name()}" - return it.object().status.containerStatuses[0].ready - } - } - } - } + verifyDeployment(projectName: env.DEV, targetApp: env.APP_NAME) } } stage('Promote from Dev to Stage') { steps { - script { - openshift.withCluster() { - openshift.tag("${env.STAGE1}/${env.APP_NAME}:latest", "${env.STAGE2}/${env.APP_NAME}:latest") - } - } + tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.DEV, toImagePath: env.STAGE) } } stage ('Verify Deployment to Stage') { steps { - script { - openshift.withCluster() { - openshift.withProject("${STAGE2}") { - def dcObj = openshift.selector('dc', env.APP_NAME).object() - def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"]) - podSelector.untilEach { - echo "pod: ${it.name()}" - return it.object().status.containerStatuses[0].ready - } - } - } - } + verifyDeployment(projectName: env.STAGE, targetApp: env.APP_NAME) } } + stage('Promote from Stage to Prod') { steps { - script { - openshift.withCluster() { - openshift.tag("${env.STAGE2}/${env.APP_NAME}:latest", "${env.STAGE3}/${env.APP_NAME}:latest") - } - } + tagImage(sourceImageName: env.APP_NAME, sourceImagePath: env.STAGE, toImagePath: env.PROD) } } stage ('Verify Deployment to Prod') { steps { - script { - openshift.withCluster() { - openshift.withProject("${STAGE3}") { - def dcObj = openshift.selector('dc', env.APP_NAME).object() - def podSelector = openshift.selector('pod', [deployment: "${APP_NAME}-${dcObj.status.latestVersion}"]) - podSelector.untilEach { - echo "pod: ${it.name()}" - return it.object().status.containerStatuses[0].ready - } - } - } - } + verifyDeployment(projectName: env.PROD, targetApp: env.APP_NAME) } } - } } diff --git a/basic-spring-boot/README.md b/basic-spring-boot/README.md index 1ecb1482..1ed259c1 100644 --- a/basic-spring-boot/README.md +++ b/basic-spring-boot/README.md @@ -5,7 +5,7 @@ This example demonstrates how to implement a full end-to-end Jenkins Pipeline fo * Deploying an integrated Jenkins server inside of OpenShift * Running both custom and oob Jenkins slaves as pods in OpenShift * "One Click" instantiation of a Jenkins Pipeline using OpenShift's Jenkins Pipeline Strategy feature -* Promotion of an application's container image within an OpenShift Cluster (using `oc tag`) +* Building a Jenkins pipeline with library functions from our [pipeline-library](https://github.com/redhat-cop/pipeline-library) * Automated rollout using the [openshift-appler](https://github.com/redhat-cop/openshift-applier) project. ## Automated Deployment @@ -17,7 +17,6 @@ This quickstart can be deployed quickly using Ansible. Here are the steps. 3. Run `ansible-galaxy install -r requirements.yml --roles-path=galaxy` 2. Log into an OpenShift cluster, then run the following command. ``` -$ oc login $ ansible-playbook -i ./.applier/ galaxy/openshift-applier/playbooks/openshift-cluster-seed.yml ``` From 981a91555888546618ae5ffd5c3c4a2232622d3c Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Sun, 21 Oct 2018 20:44:30 -0400 Subject: [PATCH 6/6] Remove WIP stuff --- basic-nodejs-express/files/builds/dev/params | 3 - .../files/builds/jenkins-slave-template.yml | 67 ------ .../files/builds/jenkins-slave/params | 4 - .../files/builds/template.yml | 109 ---------- .../files/deployments/build/params | 2 - .../files/deployments/dev/params | 4 - .../files/deployments/jenkins.yml | 195 ------------------ .../files/deployments/postgresql/params | 4 - .../files/deployments/prod/params | 4 - .../files/deployments/sonar/params | 9 - .../files/deployments/stage/params | 4 - .../files/deployments/template.yml | 137 ------------ .../files/projects/projects.yml | 27 --- .../inventory/group_vars/all.yml | 40 ---- basic-nodejs-express/inventory/hosts | 2 - basic-python-flask/files/builds/dev/params | 3 - .../files/builds/jenkins-slave-template.yml | 67 ------ .../files/builds/jenkins-slave/params | 4 - basic-python-flask/files/builds/template.yml | 109 ---------- .../files/deployments/build/params | 2 - .../files/deployments/dev/params | 4 - .../files/deployments/jenkins.yml | 195 ------------------ .../files/deployments/postgresql/params | 4 - .../files/deployments/prod/params | 4 - .../files/deployments/sonar/params | 9 - .../files/deployments/stage/params | 4 - .../files/deployments/template.yml | 137 ------------ .../files/imagestreams/imagestreams.yml | 42 ---- .../files/projects/projects.yml | 27 --- .../inventory/group_vars/all.yml | 40 ---- basic-python-flask/inventory/hosts | 2 - 31 files changed, 1264 deletions(-) delete mode 100644 basic-nodejs-express/files/builds/dev/params delete mode 100644 basic-nodejs-express/files/builds/jenkins-slave-template.yml delete mode 100644 basic-nodejs-express/files/builds/jenkins-slave/params delete mode 100644 basic-nodejs-express/files/builds/template.yml delete mode 100644 basic-nodejs-express/files/deployments/build/params delete mode 100644 basic-nodejs-express/files/deployments/dev/params delete mode 100644 basic-nodejs-express/files/deployments/jenkins.yml delete mode 100644 basic-nodejs-express/files/deployments/postgresql/params delete mode 100644 basic-nodejs-express/files/deployments/prod/params delete mode 100644 basic-nodejs-express/files/deployments/sonar/params delete mode 100644 basic-nodejs-express/files/deployments/stage/params delete mode 100644 basic-nodejs-express/files/deployments/template.yml delete mode 100644 basic-nodejs-express/files/projects/projects.yml delete mode 100644 basic-nodejs-express/inventory/group_vars/all.yml delete mode 100644 basic-nodejs-express/inventory/hosts delete mode 100644 basic-python-flask/files/builds/dev/params delete mode 100644 basic-python-flask/files/builds/jenkins-slave-template.yml delete mode 100644 basic-python-flask/files/builds/jenkins-slave/params delete mode 100644 basic-python-flask/files/builds/template.yml delete mode 100644 basic-python-flask/files/deployments/build/params delete mode 100644 basic-python-flask/files/deployments/dev/params delete mode 100644 basic-python-flask/files/deployments/jenkins.yml delete mode 100644 basic-python-flask/files/deployments/postgresql/params delete mode 100644 basic-python-flask/files/deployments/prod/params delete mode 100644 basic-python-flask/files/deployments/sonar/params delete mode 100644 basic-python-flask/files/deployments/stage/params delete mode 100644 basic-python-flask/files/deployments/template.yml delete mode 100644 basic-python-flask/files/imagestreams/imagestreams.yml delete mode 100644 basic-python-flask/files/projects/projects.yml delete mode 100644 basic-python-flask/inventory/group_vars/all.yml delete mode 100644 basic-python-flask/inventory/hosts diff --git a/basic-nodejs-express/files/builds/dev/params b/basic-nodejs-express/files/builds/dev/params deleted file mode 100644 index 1e31f220..00000000 --- a/basic-nodejs-express/files/builds/dev/params +++ /dev/null @@ -1,3 +0,0 @@ -APPLICATION_NAME=express-rest -NAMESPACE=basic-nodejs-express-build -SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/nodejs-express-rest.git diff --git a/basic-nodejs-express/files/builds/jenkins-slave-template.yml b/basic-nodejs-express/files/builds/jenkins-slave-template.yml deleted file mode 100644 index 42355da7..00000000 --- a/basic-nodejs-express/files/builds/jenkins-slave-template.yml +++ /dev/null @@ -1,67 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: jenkins-slave -metadata: - annotations: - description: Template for Jenkins slave - iconClass: icon-jenkins - tags: instant-app,jenkins - name: jenkins-slave -objects: -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${SLAVE_NAME} - name: ${SLAVE_NAME} - namespace: ${NAMESPACE} - spec: - output: - to: - kind: ImageStreamTag - name: ${SLAVE_NAME}:latest - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - strategy: - dockerStrategy: - from: - kind: DockerImage - name: ${JENKINS_IMAGE} - triggers: - - type: ConfigChange -- apiVersion: v1 - kind: ImageStream - metadata: - annotations: - slave-label: nodejs8 - labels: - application: ${SLAVE_NAME} - role: jenkins-slave - name: ${SLAVE_NAME} - namespace: ${NAMESPACE} -parameters: -- description: The name for the application. - name: SLAVE_NAME - required: true -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Git source URL for application - name: SOURCE_REPOSITORY_URL - required: true - value: https://github.com/pabrahamsson/jenkins.git -- description: Git branch/tag reference - name: SOURCE_REPOSITORY_REF - value: master -- description: Path within Git repository to build; empty for root of repository - name: CONTEXT_DIR - value: -- description: The Jenkins source image - name: JENKINS_IMAGE - required: true - value: openshift/jenkins-slave-base-centos7 diff --git a/basic-nodejs-express/files/builds/jenkins-slave/params b/basic-nodejs-express/files/builds/jenkins-slave/params deleted file mode 100644 index aebca590..00000000 --- a/basic-nodejs-express/files/builds/jenkins-slave/params +++ /dev/null @@ -1,4 +0,0 @@ -SLAVE_NAME=slave-nodejs -NAMESPACE=basic-nodejs-express-build -CONTEXT_DIR=slave-nodejs -SOURCE_REPOSITORY_REF=slave-nodejs-8 diff --git a/basic-nodejs-express/files/builds/template.yml b/basic-nodejs-express/files/builds/template.yml deleted file mode 100644 index eecb762b..00000000 --- a/basic-nodejs-express/files/builds/template.yml +++ /dev/null @@ -1,109 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: generic-nodejs-jenkins-pipeline -metadata: - annotations: - description: Application template for Express applications built using a Jenkins Pipeline - iconClass: icon-nodejs - tags: flask, nodejs, jenkins-ci - version: 1.0.0 - name: generic-nodejs-jenkins-pipeline -objects: -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME}-pipeline - namespace: ${NAMESPACE} - spec: - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - triggers: - - type: GitHub - github: - secret: ${GITHUB_WEBHOOK_SECRET} - - type: ConfigChange - strategy: - type: JenkinsPipeline - jenkinsPipelineStrategy: - jenkinsfilePath: ${PIPELINE_SCRIPT} -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - output: - to: - kind: ImageStreamTag - name: ${APPLICATION_NAME}:latest - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: ${IMAGE_STREAM_TAG_NAME} - namespace: ${IMAGE_STREAM_NAMESPACE} - type: Source -- apiVersion: v1 - kind: ImageStream - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} -parameters: -- description: The name for the application. - name: APPLICATION_NAME - required: true - value: express-rest -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Git source URL for application - name: SOURCE_REPOSITORY_URL - required: true - value: https://github.com/redhat-cop/nodejs-express-rest.git -- description: Git branch/tag reference - name: SOURCE_REPOSITORY_REF - value: master -- description: Path within Git repository to build; empty for root of repository - name: CONTEXT_DIR - value: -- description: Path within Git repository pointing to the pipeline run script - name: PIPELINE_SCRIPT - value: Jenkinsfile -- description: Github trigger secret - from: '[a-zA-Z0-9]{8}' - generate: expression - name: GITHUB_WEBHOOK_SECRET - required: true -- description: Generic build trigger secret - from: '[a-zA-Z0-9]{8}' - generate: expression - name: GENERIC_WEBHOOK_SECRET - required: true -- description: Namespace in which the ImageStreams for Red Hat Middleware images are - installed. These ImageStreams are normally installed in the openshift namespace. - You should only need to modify this if you've installed the ImageStreams in a - different namespace/project. - name: IMAGE_STREAM_NAMESPACE - required: true - value: openshift -- description: Image stream tag for the image you'd like to use to build the application - name: IMAGE_STREAM_TAG_NAME - required: true - value: nodejs:latest diff --git a/basic-nodejs-express/files/deployments/build/params b/basic-nodejs-express/files/deployments/build/params deleted file mode 100644 index c226f6bb..00000000 --- a/basic-nodejs-express/files/deployments/build/params +++ /dev/null @@ -1,2 +0,0 @@ -INSTALL_PLUGINS=cobertura:1.12,sonar:2.6.1 -MEMORY_LIMIT=512Mi diff --git a/basic-nodejs-express/files/deployments/dev/params b/basic-nodejs-express/files/deployments/dev/params deleted file mode 100644 index 09ba735b..00000000 --- a/basic-nodejs-express/files/deployments/dev/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=express-rest -NAMESPACE=basic-nodejs-express-dev -SA_NAMESPACE=basic-nodejs-express-build -READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/jenkins.yml b/basic-nodejs-express/files/deployments/jenkins.yml deleted file mode 100644 index e17caaf1..00000000 --- a/basic-nodejs-express/files/deployments/jenkins.yml +++ /dev/null @@ -1,195 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - app: jenkins-ephemeral - template: jenkins-ephemeral-template -metadata: - annotations: - description: |- - Jenkins service, without persistent storage. - - WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing. - iconClass: icon-jenkins - openshift.io/display-name: Jenkins (Ephemeral) - openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html - openshift.io/long-description: This template deploys a Jenkins server capable - of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login. The - Jenkins configuration is stored in non-persistent storage, so this configuration - should be used for experimental purposes only. - openshift.io/provider-display-name: Red Hat, Inc. - openshift.io/support-url: https://access.redhat.com - tags: instant-app,jenkins - name: jenkins-ephemeral -objects: -- apiVersion: v1 - kind: Route - metadata: - annotations: - template.openshift.io/expose-uri: http://{.spec.host}{.spec.path} - name: ${JENKINS_SERVICE_NAME} - spec: - tls: - insecureEdgeTerminationPolicy: Redirect - termination: edge - to: - kind: Service - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - kind: DeploymentConfig - metadata: - annotations: - template.alpha.openshift.io/wait-for-ready: "true" - name: ${JENKINS_SERVICE_NAME} - spec: - replicas: 1 - selector: - name: ${JENKINS_SERVICE_NAME} - strategy: - type: Recreate - template: - metadata: - labels: - name: ${JENKINS_SERVICE_NAME} - spec: - containers: - - capabilities: {} - env: - - name: OPENSHIFT_ENABLE_OAUTH - value: ${ENABLE_OAUTH} - - name: OPENSHIFT_ENABLE_REDIRECT_PROMPT - value: "true" - - name: KUBERNETES_MASTER - value: https://kubernetes.default:443 - - name: KUBERNETES_TRUST_CERTIFICATES - value: "true" - - name: JENKINS_SERVICE_NAME - value: ${JENKINS_SERVICE_NAME} - - name: JNLP_SERVICE_NAME - value: ${JNLP_SERVICE_NAME} - - name: INSTALL_PLUGINS - value: ${INSTALL_PLUGINS} - image: ' ' - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 30 - httpGet: - path: /login - port: 8080 - initialDelaySeconds: 420 - timeoutSeconds: 3 - name: jenkins - readinessProbe: - httpGet: - path: /login - port: 8080 - initialDelaySeconds: 3 - timeoutSeconds: 3 - resources: - limits: - memory: ${MEMORY_LIMIT} - securityContext: - capabilities: {} - privileged: false - terminationMessagePath: /dev/termination-log - volumeMounts: - - mountPath: /var/lib/jenkins - name: ${JENKINS_SERVICE_NAME}-data - dnsPolicy: ClusterFirst - restartPolicy: Always - serviceAccountName: ${JENKINS_SERVICE_NAME} - volumes: - - emptyDir: - medium: "" - name: ${JENKINS_SERVICE_NAME}-data - triggers: - - imageChangeParams: - automatic: true - containerNames: - - jenkins - from: - kind: ImageStreamTag - name: ${JENKINS_IMAGE_STREAM_TAG} - namespace: ${NAMESPACE} - lastTriggeredImage: "" - type: ImageChange - - type: ConfigChange -- apiVersion: v1 - kind: ServiceAccount - metadata: - annotations: - serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}' - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - groupNames: null - kind: RoleBinding - metadata: - name: ${JENKINS_SERVICE_NAME}_edit - roleRef: - name: edit - subjects: - - kind: ServiceAccount - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - kind: Service - metadata: - name: ${JNLP_SERVICE_NAME} - spec: - ports: - - name: agent - nodePort: 0 - port: 50000 - protocol: TCP - targetPort: 50000 - selector: - name: ${JENKINS_SERVICE_NAME} - sessionAffinity: None - type: ClusterIP -- apiVersion: v1 - kind: Service - metadata: - annotations: - service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}", - "namespace": "", "kind": "Service"}]' - service.openshift.io/infrastructure: "true" - name: ${JENKINS_SERVICE_NAME} - spec: - ports: - - name: web - nodePort: 0 - port: 80 - protocol: TCP - targetPort: 8080 - selector: - name: ${JENKINS_SERVICE_NAME} - sessionAffinity: None - type: ClusterIP -parameters: -- description: The name of the OpenShift Service exposed for the Jenkins container. - displayName: Jenkins Service Name - name: JENKINS_SERVICE_NAME - value: jenkins -- description: The name of the service used for master/slave communication. - displayName: Jenkins JNLP Service Name - name: JNLP_SERVICE_NAME - value: jenkins-jnlp -- description: Whether to enable OAuth OpenShift integration. If false, the static - account 'admin' will be initialized with the password 'password'. - displayName: Enable OAuth in Jenkins - name: ENABLE_OAUTH - value: "true" -- description: Maximum amount of memory the container can use. - displayName: Memory Limit - name: MEMORY_LIMIT - value: 512Mi -- description: The OpenShift Namespace where the Jenkins ImageStream resides. - displayName: Jenkins ImageStream Namespace - name: NAMESPACE - value: openshift -- description: Name of the ImageStreamTag to be used for the Jenkins image. - displayName: Jenkins ImageStreamTag - name: JENKINS_IMAGE_STREAM_TAG - value: jenkins:latest -- description: Comma-separated list of additional plugins to install on startup. The format of each plugin spec is 'plugin-id:version' - displayName: Additional Jenkins plugins to install - name: INSTALL_PLUGINS - value: '' diff --git a/basic-nodejs-express/files/deployments/postgresql/params b/basic-nodejs-express/files/deployments/postgresql/params deleted file mode 100644 index 1867b6b8..00000000 --- a/basic-nodejs-express/files/deployments/postgresql/params +++ /dev/null @@ -1,4 +0,0 @@ -POSTGRESQL_DATABASE=sonar -VOLUME_CAPACITY=5 -POSTGRESQL_PASSWORD=sonar -POSTGRESQL_USER=sonar diff --git a/basic-nodejs-express/files/deployments/prod/params b/basic-nodejs-express/files/deployments/prod/params deleted file mode 100644 index c95aaa25..00000000 --- a/basic-nodejs-express/files/deployments/prod/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=express-rest -NAMESPACE=basic-nodejs-express-prod -SA_NAMESPACE=basic-nodejs-express-build -READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/sonar/params b/basic-nodejs-express/files/deployments/sonar/params deleted file mode 100644 index 909dba70..00000000 --- a/basic-nodejs-express/files/deployments/sonar/params +++ /dev/null @@ -1,9 +0,0 @@ -MEMORY_LIMIT=1Gi -VOLUME_CAPACITY=2Gi -MEMORY_LIMIT=2Gi -CPU_LIMIT=1 -JDBC_URL=jdbc:postgresql://postgresql:5432/sonar -JDBC_USER=sonar -JDBC_PASSWORD=sonar -SOURCE_REPOSITORY_URL=https://github.com/rht-labs/labs-ci-cd -SOURCE_REPOSITORY_CONTEXT_DIR=docker/sonarqube diff --git a/basic-nodejs-express/files/deployments/stage/params b/basic-nodejs-express/files/deployments/stage/params deleted file mode 100644 index d6f8541e..00000000 --- a/basic-nodejs-express/files/deployments/stage/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=express-rest -NAMESPACE=basic-nodejs-express-stage -SA_NAMESPACE=basic-nodejs-express-build -READINESS_RESPONSE=status.:.success diff --git a/basic-nodejs-express/files/deployments/template.yml b/basic-nodejs-express/files/deployments/template.yml deleted file mode 100644 index d2b9bc36..00000000 --- a/basic-nodejs-express/files/deployments/template.yml +++ /dev/null @@ -1,137 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: basic-nodejs-express -metadata: - annotations: - description: Application template for Express applications built using a Jenkins Pipeline - iconClass: icon-nodejs - tags: nodejs, express - version: 1.0.0 - name: basic-nodejs-express -objects: -- apiVersion: v1 - kind: Service - metadata: - annotations: - description: The web server's http port. - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - ports: - - port: 8080 - targetPort: 8080 - selector: - deploymentConfig: ${APPLICATION_NAME} -- apiVersion: v1 - id: ${APPLICATION_NAME}-http - kind: Route - metadata: - annotations: - description: Route for application's http service. - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - host: ${HOSTNAME_HTTP} - to: - name: ${APPLICATION_NAME} -- apiVersion: v1 - kind: ImageStream - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} -- apiVersion: v1 - kind: DeploymentConfig - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - replicas: 1 - selector: - deploymentConfig: ${APPLICATION_NAME} - strategy: - type: Rolling - template: - metadata: - labels: - application: ${APPLICATION_NAME} - deploymentConfig: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - spec: - containers: - - image: ${APPLICATION_NAME} - imagePullPolicy: Always - name: ${APPLICATION_NAME} - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/bash - - -c - - curl -s 'http://localhost:8080${READINESS_PATH}' - |grep -iq '${READINESS_RESPONSE}' - terminationGracePeriodSeconds: 60 - triggers: - - imageChangeParams: - automatic: true - containerNames: - - ${APPLICATION_NAME} - from: - kind: ImageStreamTag - name: ${APPLICATION_NAME}:latest - type: ImageChange - - type: ConfigChange -- apiVersion: v1 - groupNames: null - kind: RoleBinding - metadata: - creationTimestamp: null - labels: - template: basic-nodejs-express-template - name: jenkins_edit - namespace: ${NAMESPACE} - roleRef: - name: edit - subjects: - - kind: ServiceAccount - name: ${SA_NAME} - namespace: ${SA_NAMESPACE} - userNames: - - system:serviceaccount:${SA_NAMESPACE}:${SA_NAME} -parameters: -- description: The name for the application. - name: APPLICATION_NAME - required: true - value: express-rest -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Name of a service account that can deploy to this project - name: SA_NAME - required: true - value: jenkins -- description: Namespace of service account that can deploy to this project - name: SA_NAMESPACE - required: true -- description: 'Custom hostname for http service route. Leave blank for default hostname, - e.g.: -.' - name: HOSTNAME_HTTP -- description: 'URI to check for app health' - name: READINESS_PATH - required: true - value: '/health' -- description: 'String value expected back from readiness check' - name: READINESS_RESPONSE - required: true - value: 'Hello World!' diff --git a/basic-nodejs-express/files/projects/projects.yml b/basic-nodejs-express/files/projects/projects.yml deleted file mode 100644 index c2ce552f..00000000 --- a/basic-nodejs-express/files/projects/projects.yml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: v1 -kind: List -items: -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-nodejs-express-dev - creationTimestamp: null - displayName: Dev - NodeJS Express App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-nodejs-express-stage - creationTimestamp: null - displayName: Staging - NodeJS Express App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-nodejs-express-prod - creationTimestamp: null - displayName: Prod - NodeJS Express App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-nodejs-express-build - creationTimestam: null - displayName: Build - Jenkins is here diff --git a/basic-nodejs-express/inventory/group_vars/all.yml b/basic-nodejs-express/inventory/group_vars/all.yml deleted file mode 100644 index 76d2f3b0..00000000 --- a/basic-nodejs-express/inventory/group_vars/all.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -openshift_cluster_content: -- object: projectrequest - content: - - name: basic-nodejs-express-spaces - file: "{{ inventory_dir }}/../files/projects/projects.yml" - file_action: create -- object: builds - content: - - name: jenkins-slave-nodejs - template: "{{ inventory_dir }}/../files/builds/jenkins-slave-template.yml" - params: "{{ inventory_dir }}/../files/builds/jenkins-slave/params" -- object: deployments - content: - - name: postgresql - namespace: basic-nodejs-express-build - template: openshift//postgresql-persistent - params: "{{ inventory_dir }}/../files/deployments/postgresql/params" - - name: sonarqube - namespace: basic-nodejs-express-build - template: https://raw.githubusercontent.com/rht-labs/labs-ci-cd/master/openshift-templates/sonarqube/template.json - params: "{{ inventory_dir }}/../files/deployments/sonar/params" - - name: jenkins - namespace: basic-nodejs-express-build - template: "{{ inventory_dir }}/../files/deployments/jenkins.yml" - params: "{{ inventory_dir }}/../files/deployments/build/params" - - name: basic-nodejs-express-dev - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/dev/params" - - name: basic-nodejs-express-stage - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/stage/params" - - name: basic-nodejs-express-prod - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/prod/params" -- object: builds - content: - - name: jenkins - template: "{{ inventory_dir }}/../files/builds/template.yml" - params: "{{ inventory_dir }}/../files/builds/dev/params" diff --git a/basic-nodejs-express/inventory/hosts b/basic-nodejs-express/inventory/hosts deleted file mode 100644 index 05c07035..00000000 --- a/basic-nodejs-express/inventory/hosts +++ /dev/null @@ -1,2 +0,0 @@ -[seed-hosts] -localhost diff --git a/basic-python-flask/files/builds/dev/params b/basic-python-flask/files/builds/dev/params deleted file mode 100644 index 20fe21fc..00000000 --- a/basic-python-flask/files/builds/dev/params +++ /dev/null @@ -1,3 +0,0 @@ -APPLICATION_NAME=flask-rest -NAMESPACE=basic-python-flask-build -SOURCE_REPOSITORY_URL=https://github.com/pabrahamsson/python-flask-rest.git diff --git a/basic-python-flask/files/builds/jenkins-slave-template.yml b/basic-python-flask/files/builds/jenkins-slave-template.yml deleted file mode 100644 index 1d758d6c..00000000 --- a/basic-python-flask/files/builds/jenkins-slave-template.yml +++ /dev/null @@ -1,67 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: jenkins-slave -metadata: - annotations: - description: Template for Jenkins slave - iconClass: icon-jenkins - tags: instant-app,jenkins - name: jenkins-slave -objects: -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${SLAVE_NAME} - name: ${SLAVE_NAME} - namespace: ${NAMESPACE} - spec: - output: - to: - kind: ImageStreamTag - name: ${SLAVE_NAME}:latest - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - strategy: - dockerStrategy: - from: - kind: DockerImage - name: ${JENKINS_IMAGE} - triggers: - - type: ConfigChange -- apiVersion: v1 - kind: ImageStream - metadata: - annotations: - slave-label: python - labels: - application: ${SLAVE_NAME} - role: jenkins-slave - name: ${SLAVE_NAME} - namespace: ${NAMESPACE} -parameters: -- description: The name for the application. - name: SLAVE_NAME - required: true -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Git source URL for application - name: SOURCE_REPOSITORY_URL - required: true - value: https://github.com/pabrahamsson/jenkins.git -- description: Git branch/tag reference - name: SOURCE_REPOSITORY_REF - value: master -- description: Path within Git repository to build; empty for root of repository - name: CONTEXT_DIR - value: -- description: The Jenkins source image - name: JENKINS_IMAGE - required: true - value: openshift/jenkins-slave-base-centos7 diff --git a/basic-python-flask/files/builds/jenkins-slave/params b/basic-python-flask/files/builds/jenkins-slave/params deleted file mode 100644 index 8e54048b..00000000 --- a/basic-python-flask/files/builds/jenkins-slave/params +++ /dev/null @@ -1,4 +0,0 @@ -SLAVE_NAME=slave-python -NAMESPACE=basic-python-flask-build -CONTEXT_DIR=slave-python -SOURCE_REPOSITORY_REF=slave-python diff --git a/basic-python-flask/files/builds/template.yml b/basic-python-flask/files/builds/template.yml deleted file mode 100644 index 8e7e6f78..00000000 --- a/basic-python-flask/files/builds/template.yml +++ /dev/null @@ -1,109 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: generic-python-jenkins-pipeline -metadata: - annotations: - description: Application template for Flask applications built using a Jenkins Pipeline - iconClass: icon-python - tags: flask, python, jenkins-ci - version: 1.0.0 - name: generic-python-jenkins-pipeline -objects: -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME}-pipeline - namespace: ${NAMESPACE} - spec: - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - triggers: - - type: GitHub - github: - secret: ${GITHUB_WEBHOOK_SECRET} - - type: ConfigChange - strategy: - type: JenkinsPipeline - jenkinsPipelineStrategy: - jenkinsfilePath: ${PIPELINE_SCRIPT} -- kind: BuildConfig - apiVersion: v1 - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - output: - to: - kind: ImageStreamTag - name: ${APPLICATION_NAME}:latest - source: - type: Git - git: - uri: ${SOURCE_REPOSITORY_URL} - ref: ${SOURCE_REPOSITORY_REF} - contextDir: ${CONTEXT_DIR} - strategy: - sourceStrategy: - from: - kind: ImageStreamTag - name: ${IMAGE_STREAM_TAG_NAME} - namespace: ${IMAGE_STREAM_NAMESPACE} - type: Source -- apiVersion: v1 - kind: ImageStream - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} -parameters: -- description: The name for the application. - name: APPLICATION_NAME - required: true - value: flask-rest -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Git source URL for application - name: SOURCE_REPOSITORY_URL - required: true - value: https://github.com/redhat-cop/python-flask-rest.git -- description: Git branch/tag reference - name: SOURCE_REPOSITORY_REF - value: master -- description: Path within Git repository to build; empty for root of repository - name: CONTEXT_DIR - value: -- description: Path within Git repository pointing to the pipeline run script - name: PIPELINE_SCRIPT - value: Jenkinsfile -- description: Github trigger secret - from: '[a-zA-Z0-9]{8}' - generate: expression - name: GITHUB_WEBHOOK_SECRET - required: true -- description: Generic build trigger secret - from: '[a-zA-Z0-9]{8}' - generate: expression - name: GENERIC_WEBHOOK_SECRET - required: true -- description: Namespace in which the ImageStreams for Red Hat Middleware images are - installed. These ImageStreams are normally installed in the openshift namespace. - You should only need to modify this if you've installed the ImageStreams in a - different namespace/project. - name: IMAGE_STREAM_NAMESPACE - required: true - value: openshift -- description: Image stream tag for the image you'd like to use to build the application - name: IMAGE_STREAM_TAG_NAME - required: true - value: python:3.5 diff --git a/basic-python-flask/files/deployments/build/params b/basic-python-flask/files/deployments/build/params deleted file mode 100644 index c226f6bb..00000000 --- a/basic-python-flask/files/deployments/build/params +++ /dev/null @@ -1,2 +0,0 @@ -INSTALL_PLUGINS=cobertura:1.12,sonar:2.6.1 -MEMORY_LIMIT=512Mi diff --git a/basic-python-flask/files/deployments/dev/params b/basic-python-flask/files/deployments/dev/params deleted file mode 100644 index ae8a2f00..00000000 --- a/basic-python-flask/files/deployments/dev/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=flask-rest -NAMESPACE=basic-python-flask-dev -SA_NAMESPACE=basic-python-flask-build -READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/jenkins.yml b/basic-python-flask/files/deployments/jenkins.yml deleted file mode 100644 index e17caaf1..00000000 --- a/basic-python-flask/files/deployments/jenkins.yml +++ /dev/null @@ -1,195 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - app: jenkins-ephemeral - template: jenkins-ephemeral-template -metadata: - annotations: - description: |- - Jenkins service, without persistent storage. - - WARNING: Any data stored will be lost upon pod destruction. Only use this template for testing. - iconClass: icon-jenkins - openshift.io/display-name: Jenkins (Ephemeral) - openshift.io/documentation-url: https://docs.openshift.org/latest/using_images/other_images/jenkins.html - openshift.io/long-description: This template deploys a Jenkins server capable - of managing OpenShift Pipeline builds and supporting OpenShift-based oauth login. The - Jenkins configuration is stored in non-persistent storage, so this configuration - should be used for experimental purposes only. - openshift.io/provider-display-name: Red Hat, Inc. - openshift.io/support-url: https://access.redhat.com - tags: instant-app,jenkins - name: jenkins-ephemeral -objects: -- apiVersion: v1 - kind: Route - metadata: - annotations: - template.openshift.io/expose-uri: http://{.spec.host}{.spec.path} - name: ${JENKINS_SERVICE_NAME} - spec: - tls: - insecureEdgeTerminationPolicy: Redirect - termination: edge - to: - kind: Service - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - kind: DeploymentConfig - metadata: - annotations: - template.alpha.openshift.io/wait-for-ready: "true" - name: ${JENKINS_SERVICE_NAME} - spec: - replicas: 1 - selector: - name: ${JENKINS_SERVICE_NAME} - strategy: - type: Recreate - template: - metadata: - labels: - name: ${JENKINS_SERVICE_NAME} - spec: - containers: - - capabilities: {} - env: - - name: OPENSHIFT_ENABLE_OAUTH - value: ${ENABLE_OAUTH} - - name: OPENSHIFT_ENABLE_REDIRECT_PROMPT - value: "true" - - name: KUBERNETES_MASTER - value: https://kubernetes.default:443 - - name: KUBERNETES_TRUST_CERTIFICATES - value: "true" - - name: JENKINS_SERVICE_NAME - value: ${JENKINS_SERVICE_NAME} - - name: JNLP_SERVICE_NAME - value: ${JNLP_SERVICE_NAME} - - name: INSTALL_PLUGINS - value: ${INSTALL_PLUGINS} - image: ' ' - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 30 - httpGet: - path: /login - port: 8080 - initialDelaySeconds: 420 - timeoutSeconds: 3 - name: jenkins - readinessProbe: - httpGet: - path: /login - port: 8080 - initialDelaySeconds: 3 - timeoutSeconds: 3 - resources: - limits: - memory: ${MEMORY_LIMIT} - securityContext: - capabilities: {} - privileged: false - terminationMessagePath: /dev/termination-log - volumeMounts: - - mountPath: /var/lib/jenkins - name: ${JENKINS_SERVICE_NAME}-data - dnsPolicy: ClusterFirst - restartPolicy: Always - serviceAccountName: ${JENKINS_SERVICE_NAME} - volumes: - - emptyDir: - medium: "" - name: ${JENKINS_SERVICE_NAME}-data - triggers: - - imageChangeParams: - automatic: true - containerNames: - - jenkins - from: - kind: ImageStreamTag - name: ${JENKINS_IMAGE_STREAM_TAG} - namespace: ${NAMESPACE} - lastTriggeredImage: "" - type: ImageChange - - type: ConfigChange -- apiVersion: v1 - kind: ServiceAccount - metadata: - annotations: - serviceaccounts.openshift.io/oauth-redirectreference.jenkins: '{"kind":"OAuthRedirectReference","apiVersion":"v1","reference":{"kind":"Route","name":"${JENKINS_SERVICE_NAME}"}}' - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - groupNames: null - kind: RoleBinding - metadata: - name: ${JENKINS_SERVICE_NAME}_edit - roleRef: - name: edit - subjects: - - kind: ServiceAccount - name: ${JENKINS_SERVICE_NAME} -- apiVersion: v1 - kind: Service - metadata: - name: ${JNLP_SERVICE_NAME} - spec: - ports: - - name: agent - nodePort: 0 - port: 50000 - protocol: TCP - targetPort: 50000 - selector: - name: ${JENKINS_SERVICE_NAME} - sessionAffinity: None - type: ClusterIP -- apiVersion: v1 - kind: Service - metadata: - annotations: - service.alpha.openshift.io/dependencies: '[{"name": "${JNLP_SERVICE_NAME}", - "namespace": "", "kind": "Service"}]' - service.openshift.io/infrastructure: "true" - name: ${JENKINS_SERVICE_NAME} - spec: - ports: - - name: web - nodePort: 0 - port: 80 - protocol: TCP - targetPort: 8080 - selector: - name: ${JENKINS_SERVICE_NAME} - sessionAffinity: None - type: ClusterIP -parameters: -- description: The name of the OpenShift Service exposed for the Jenkins container. - displayName: Jenkins Service Name - name: JENKINS_SERVICE_NAME - value: jenkins -- description: The name of the service used for master/slave communication. - displayName: Jenkins JNLP Service Name - name: JNLP_SERVICE_NAME - value: jenkins-jnlp -- description: Whether to enable OAuth OpenShift integration. If false, the static - account 'admin' will be initialized with the password 'password'. - displayName: Enable OAuth in Jenkins - name: ENABLE_OAUTH - value: "true" -- description: Maximum amount of memory the container can use. - displayName: Memory Limit - name: MEMORY_LIMIT - value: 512Mi -- description: The OpenShift Namespace where the Jenkins ImageStream resides. - displayName: Jenkins ImageStream Namespace - name: NAMESPACE - value: openshift -- description: Name of the ImageStreamTag to be used for the Jenkins image. - displayName: Jenkins ImageStreamTag - name: JENKINS_IMAGE_STREAM_TAG - value: jenkins:latest -- description: Comma-separated list of additional plugins to install on startup. The format of each plugin spec is 'plugin-id:version' - displayName: Additional Jenkins plugins to install - name: INSTALL_PLUGINS - value: '' diff --git a/basic-python-flask/files/deployments/postgresql/params b/basic-python-flask/files/deployments/postgresql/params deleted file mode 100644 index 1867b6b8..00000000 --- a/basic-python-flask/files/deployments/postgresql/params +++ /dev/null @@ -1,4 +0,0 @@ -POSTGRESQL_DATABASE=sonar -VOLUME_CAPACITY=5 -POSTGRESQL_PASSWORD=sonar -POSTGRESQL_USER=sonar diff --git a/basic-python-flask/files/deployments/prod/params b/basic-python-flask/files/deployments/prod/params deleted file mode 100644 index b306a524..00000000 --- a/basic-python-flask/files/deployments/prod/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=flask-rest -NAMESPACE=basic-python-flask-prod -SA_NAMESPACE=basic-python-flask-build -READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/sonar/params b/basic-python-flask/files/deployments/sonar/params deleted file mode 100644 index 909dba70..00000000 --- a/basic-python-flask/files/deployments/sonar/params +++ /dev/null @@ -1,9 +0,0 @@ -MEMORY_LIMIT=1Gi -VOLUME_CAPACITY=2Gi -MEMORY_LIMIT=2Gi -CPU_LIMIT=1 -JDBC_URL=jdbc:postgresql://postgresql:5432/sonar -JDBC_USER=sonar -JDBC_PASSWORD=sonar -SOURCE_REPOSITORY_URL=https://github.com/rht-labs/labs-ci-cd -SOURCE_REPOSITORY_CONTEXT_DIR=docker/sonarqube diff --git a/basic-python-flask/files/deployments/stage/params b/basic-python-flask/files/deployments/stage/params deleted file mode 100644 index 52f24087..00000000 --- a/basic-python-flask/files/deployments/stage/params +++ /dev/null @@ -1,4 +0,0 @@ -APPLICATION_NAME=flask-rest -NAMESPACE=basic-python-flask-stage -SA_NAMESPACE=basic-python-flask-build -READINESS_RESPONSE=status.:..success diff --git a/basic-python-flask/files/deployments/template.yml b/basic-python-flask/files/deployments/template.yml deleted file mode 100644 index c276e76f..00000000 --- a/basic-python-flask/files/deployments/template.yml +++ /dev/null @@ -1,137 +0,0 @@ -apiVersion: v1 -kind: Template -labels: - template: basic-python-flask -metadata: - annotations: - description: Application template for Flask applications built using a Jenkins Pipeline - iconClass: icon-python - tags: python, flask - version: 1.0.0 - name: basic-python-fask -objects: -- apiVersion: v1 - kind: Service - metadata: - annotations: - description: The web server's http port. - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - ports: - - port: 8080 - targetPort: 8080 - selector: - deploymentConfig: ${APPLICATION_NAME} -- apiVersion: v1 - id: ${APPLICATION_NAME}-http - kind: Route - metadata: - annotations: - description: Route for application's http service. - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - host: ${HOSTNAME_HTTP} - to: - name: ${APPLICATION_NAME} -- apiVersion: v1 - kind: ImageStream - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} -- apiVersion: v1 - kind: DeploymentConfig - metadata: - labels: - application: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - namespace: ${NAMESPACE} - spec: - replicas: 1 - selector: - deploymentConfig: ${APPLICATION_NAME} - strategy: - type: Rolling - template: - metadata: - labels: - application: ${APPLICATION_NAME} - deploymentConfig: ${APPLICATION_NAME} - name: ${APPLICATION_NAME} - spec: - containers: - - image: ${APPLICATION_NAME} - imagePullPolicy: Always - name: ${APPLICATION_NAME} - ports: - - containerPort: 8080 - name: http - protocol: TCP - readinessProbe: - exec: - command: - - /bin/bash - - -c - - curl -s 'http://localhost:8080${READINESS_PATH}' - |grep -iq '${READINESS_RESPONSE}' - terminationGracePeriodSeconds: 60 - triggers: - - imageChangeParams: - automatic: true - containerNames: - - ${APPLICATION_NAME} - from: - kind: ImageStreamTag - name: ${APPLICATION_NAME}:latest - type: ImageChange - - type: ConfigChange -- apiVersion: v1 - groupNames: null - kind: RoleBinding - metadata: - creationTimestamp: null - labels: - template: basic-python-flask-template - name: jenkins_edit - namespace: ${NAMESPACE} - roleRef: - name: edit - subjects: - - kind: ServiceAccount - name: ${SA_NAME} - namespace: ${SA_NAMESPACE} - userNames: - - system:serviceaccount:${SA_NAMESPACE}:${SA_NAME} -parameters: -- description: The name for the application. - name: APPLICATION_NAME - required: true - value: flask-rest -- description: The namespace to deploy into - name: NAMESPACE - required: true -- description: Name of a service account that can deploy to this project - name: SA_NAME - required: true - value: jenkins -- description: Namespace of service account that can deploy to this project - name: SA_NAMESPACE - required: true -- description: 'Custom hostname for http service route. Leave blank for default hostname, - e.g.: -.' - name: HOSTNAME_HTTP -- description: 'URI to check for app health' - name: READINESS_PATH - required: true - value: '/health' -- description: 'String value expected back from readiness check' - name: READINESS_RESPONSE - required: true - value: 'Hello World!' diff --git a/basic-python-flask/files/imagestreams/imagestreams.yml b/basic-python-flask/files/imagestreams/imagestreams.yml deleted file mode 100644 index 46d4a014..00000000 --- a/basic-python-flask/files/imagestreams/imagestreams.yml +++ /dev/null @@ -1,42 +0,0 @@ -apiVersion: v1 -kind: ImageStream -metadata: - annotations: - openshift.io/image.dockerRepositoryCheck: 2017-12-14T21:50:52Z - creationTimestamp: null - generation: 3 - name: jenkins-slave-python-centos7 -spec: - lookupPolicy: - local: false - tags: - - annotations: - role: jenkins-slave - slave-label: python - from: - kind: DockerImage - name: docker.io/pabrahamsson/jenkins-slave-python-centos7:latest - importPolicy: {} - name: latest - referencePolicy: - type: Source - - annotations: - role: jenkins-slave - slave-label: python - from: - kind: DockerImage - name: docker.io/pabrahamsson/jenkins-slave-python-centos7:v3.9 - importPolicy: {} - name: v3.9 - referencePolicy: - type: Source - - annotations: - role: jenkins-slave - slave-label: python - from: - kind: DockerImage - name: docker.io/pabrahamsson/jenkins-slave-python-centos7:v3.7 - importPolicy: {} - name: v3.7 - referencePolicy: - type: Source diff --git a/basic-python-flask/files/projects/projects.yml b/basic-python-flask/files/projects/projects.yml deleted file mode 100644 index 4c8f80b6..00000000 --- a/basic-python-flask/files/projects/projects.yml +++ /dev/null @@ -1,27 +0,0 @@ -apiVersion: v1 -kind: List -items: -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-python-flask-dev - creationTimestamp: null - displayName: Dev - Python Flask App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-python-flask-stage - creationTimestamp: null - displayName: Staging - Python Flask App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-python-flask-prod - creationTimestamp: null - displayName: Prod - Python Flask App -- kind: ProjectRequest - apiVersion: v1 - metadata: - name: basic-python-flask-build - creationTimestam: null - displayName: Build - Jenkins is here diff --git a/basic-python-flask/inventory/group_vars/all.yml b/basic-python-flask/inventory/group_vars/all.yml deleted file mode 100644 index 1cab57ca..00000000 --- a/basic-python-flask/inventory/group_vars/all.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -openshift_cluster_content: -- object: projectrequest - content: - - name: basic-python-flask-spaces - file: "{{ inventory_dir }}/../files/projects/projects.yml" - file_action: create -- object: builds - content: - - name: jenkins-slave-python - template: "{{ inventory_dir }}/../files/builds/jenkins-slave-template.yml" - params: "{{ inventory_dir }}/../files/builds/jenkins-slave/params" -- object: deployments - content: - - name: postgresql - namespace: basic-python-flask-build - template: openshift//postgresql-persistent - params: "{{ inventory_dir }}/../files/deployments/postgresql/params" - - name: sonarqube - namespace: basic-python-flask-build - template: https://raw.githubusercontent.com/rht-labs/labs-ci-cd/master/openshift-templates/sonarqube/template.json - params: "{{ inventory_dir }}/../files/deployments/sonar/params" - - name: jenkins - namespace: basic-python-flask-build - template: "{{ inventory_dir }}/../files/deployments/jenkins.yml" - params: "{{ inventory_dir }}/../files/deployments/build/params" - - name: basic-python-flask-dev - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/dev/params" - - name: basic-python-flask-stage - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/stage/params" - - name: basic-python-flask-prod - template: "{{ inventory_dir }}/../files/deployments/template.yml" - params: "{{ inventory_dir }}/../files/deployments/prod/params" -- object: builds - content: - - name: jenkins - template: "{{ inventory_dir }}/../files/builds/template.yml" - params: "{{ inventory_dir }}/../files/builds/dev/params" diff --git a/basic-python-flask/inventory/hosts b/basic-python-flask/inventory/hosts deleted file mode 100644 index 05c07035..00000000 --- a/basic-python-flask/inventory/hosts +++ /dev/null @@ -1,2 +0,0 @@ -[seed-hosts] -localhost