From 8706cbf54cd6bebda9ceb4643447f3a59cf8c45c Mon Sep 17 00:00:00 2001 From: Mike Olund Date: Sun, 19 Feb 2017 17:13:22 -0800 Subject: [PATCH] Added Nginx Reverse Proxy --- openshift/templates/nginx-build-template.yaml | 90 +++++++++++++ .../templates/nginx-environment-template.yaml | 126 ++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 openshift/templates/nginx-build-template.yaml create mode 100644 openshift/templates/nginx-environment-template.yaml diff --git a/openshift/templates/nginx-build-template.yaml b/openshift/templates/nginx-build-template.yaml new file mode 100644 index 00000000..342e0f37 --- /dev/null +++ b/openshift/templates/nginx-build-template.yaml @@ -0,0 +1,90 @@ +--- +kind: Template +apiVersion: v1 +metadata: + name: nginx + creationTimestamp: +objects: +- kind: ImageStream + apiVersion: v1 + metadata: + name: "${NAME}" +- kind: BuildConfig + apiVersion: v1 + metadata: + name: "${NAME}" + creationTimestamp: + labels: + app: "${NAME}" + spec: + triggers: + - type: GitHub + github: + secret: "${GITHUB_WEBHOOK_SECRET}" + - type: Generic + generic: + secret: "${GENERIC_WEBHOOK_SECRET}" + - type: ConfigChange + - type: ImageChange + imageChange: {} + runPolicy: Serial + source: + type: Git + git: + ref: "${SOURCE_REPOSITORY_REF}" + uri: "${SOURCE_REPOSITORY_URL}" + contextDir: "${SOURCE_REPOSITORY_CONTEXT_DIR}" + strategy: + type: Source + sourceStrategy: + from: + kind: ImageStreamTag + name: "${BUILDER_IMAGESTREAM_TAG}" + env: + - name: NGINX_PROXY_URL + value: "${NGINX_PROXY_URL}" + output: + to: + kind: ImageStreamTag + name: "${NAME}:latest" + resources: {} + postCommit: {} + status: + lastVersion: 0 +parameters: +- name: NAME + displayName: Name + description: The name assigned to all of the frontend objects defined in this template. + required: true + value: nginx-proxy +- name: BUILDER_IMAGESTREAM_TAG + displayName: Builder ImageStreamTag + description: The image stream tag (e.g. rproxy:latest) of the S2I image that should be used to build the application. + value: s2i-nginx:latest +- name: SOURCE_REPOSITORY_URL + displayName: Git Repository URL + description: The URL of the repository with your nginx configuration code. + value: https://github.com/molund/eDivorce + required: true +- name: SOURCE_REPOSITORY_CONTEXT_DIR + displayName: Git sub-directory + description: The folder in the Git repo that contains the config.d directory. + value: /nginx-proxy +- name: SOURCE_REPOSITORY_REF + displayName: Git Reference + description: Set this to a branch name, tag or other ref of your repository if you are not using the default branch. +- name: GITHUB_WEBHOOK_SECRET + displayName: GitHub Webhook Secret + description: A secret string used to configure the GitHub webhook. + generate: expression + from: "[a-zA-Z0-9]{40}" +- name: GENERIC_WEBHOOK_SECRET + displayName: Generic Webhook Secret + description: A secret string used to configure the Generic webhook. + generate: expression + from: "[a-zA-Z0-9]{40}" +- name: NGINX_PROXY_URL + displayName: NGinx Proxy URL + description: The URL you want NGinx to proxy to, e.g., http://:port/ + value: http://edivorce-django:8080/ + required: true diff --git a/openshift/templates/nginx-environment-template.yaml b/openshift/templates/nginx-environment-template.yaml new file mode 100644 index 00000000..b3edf24c --- /dev/null +++ b/openshift/templates/nginx-environment-template.yaml @@ -0,0 +1,126 @@ +--- +kind: Template +apiVersion: v1 +metadata: + name: nginx +labels: + template: nginx-environment-template +objects: +- kind: DeploymentConfig + apiVersion: v1 + metadata: + name: "${NAME}" + creationTimestamp: + labels: + app: "${NAME}" + spec: + strategy: + type: Rolling + rollingParams: + updatePeriodSeconds: 1 + intervalSeconds: 1 + timeoutSeconds: 600 + maxUnavailable: 25% + maxSurge: 25% + resources: {} + triggers: + - type: ConfigChange + - type: ImageChange + imageChangeParams: + automatic: true + containerNames: + - "${NAME}" + from: + kind: ImageStreamTag + namespace: "${APP_IMAGE_NAMESPACE}" + name: "${APP_IMAGE_NAME}:deploy-to-${ENVIRONMENT_TYPE}" + replicas: 2 + test: false + selector: + app: "${NAME}" + deploymentconfig: "${NAME}" + template: + metadata: + creationTimestamp: + labels: + app: "${NAME}" + deploymentconfig: "${NAME}" + spec: + containers: + - name: "${NAME}" + image: " " + ports: + - containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: /nginx_status + port: 8080 + scheme: HTTP + initialDelaySeconds: 60 + timeoutSeconds: 30 + periodSeconds: 60 + successThreshold: 1 + failureThreshold: 5 + imagePullPolicy: Always + restartPolicy: Always + terminationGracePeriodSeconds: 30 + dnsPolicy: ClusterFirst + securityContext: {} +- kind: Service + apiVersion: v1 + metadata: + name: "${NAME}" + creationTimestamp: + labels: + app: "${NAME}" + spec: + ports: + - name: 8080-tcp + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + app: "${NAME}" + deploymentconfig: "${NAME}" + type: ClusterIP + sessionAffinity: None +- kind: Route + apiVersion: v1 + metadata: + name: "${NAME}" + creationTimestamp: + labels: + app: "${NAME}" + annotations: + openshift.io/host.generated: 'true' + spec: + host: "edivorce-${ENVIRONMENT_TYPE}.pathfinder.gov.bc.ca" + to: + kind: Service + name: "${NAME}" + weight: 100 + port: + targetPort: 8080-tcp + tls: + termination: edge + insecureEdgeTerminationPolicy: Redirect +parameters: +- name: NAME + displayName: Name + description: The name assigned to all of the frontend objects defined in this template. + required: true + value: nginx-proxy +- name: APP_IMAGE_NAME + displayName: Application image name. + description: Application image name. + value: nginx-proxy + required: true +- name: APP_IMAGE_NAMESPACE + displayName: Namespace containing application images. + description: Namespace containing application images. + value: "jag-csb-edivorce-tools" + required: true +- name: ENVIRONMENT_TYPE + displayName: Type of environnment (dev,test or prod). + required: true \ No newline at end of file