From a8082f0c4d7fedf18c17f974e27ecab1d4e44e0e Mon Sep 17 00:00:00 2001 From: Petter Abrahamsson Date: Mon, 18 Dec 2017 14:09:23 -0500 Subject: [PATCH] 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"