Browse Source

Added Jenkins pipelines

pull/160/head
Mike Olund 8 years ago
parent
commit
c8c6109262
10 changed files with 135 additions and 112 deletions
  1. +0
    -19
      openshift/create-env.sh
  2. +0
    -28
      openshift/destroy-env.sh
  3. +3
    -9
      openshift/jenkins/build-and-deploy-to-dev
  4. +8
    -0
      openshift/jenkins/deploy-to-prod
  5. +9
    -0
      openshift/jenkins/deploy-to-test
  6. +114
    -0
      openshift/jenkins/pipeline.yaml
  7. +0
    -0
      openshift/nginx-proxy/conf.d/server.conf
  8. +0
    -14
      openshift/project_label.sh
  9. +0
    -41
      openshift/scripts/run-in-container.sh
  10. +1
    -1
      openshift/templates/nginx-build-template.yaml

+ 0
- 19
openshift/create-env.sh View File

@ -1,19 +0,0 @@
#!/usr/bin/env bash
echo -n "Enter the name of the environment (default=dev): "
read ENVIRONMENT
ENVIRONMENT=${ENVIRONMENT:-dev}
OS_PROJECT_NAME=jag-csb-edivorce-$ENVIRONMENT
echo "Changing project to $OS_PROJECT_NAME..."
oc project $OS_PROJECT_NAME
echo -n "Enter the path to the environment creation template (default=templates/edivorce-environment-template.yaml): "
read CREATE_SCRIPT
CREATE_SCRIPT=${CREATE_SCRIPT:-templates/edivorce-environment-template.yaml}
oc create -f $CREATE_SCRIPT
/bin/bash project_label.sh $OS_PROJECT_NAME team=jag product=edivorce environment=$ENVIRONMENT

+ 0
- 28
openshift/destroy-env.sh View File

@ -1,28 +0,0 @@
#!/usr/bin/env bash
# this is hard-coded to only destroy the dev environment
# you can chage it to 'test' or 'prod' if you are sure you want to destroy EVERYTHING, include the database
oc project jag-csb-edivorce-dev
# delete all imagestreams
oc delete is --all
# delete services by name (we don't want to accidentally delete the gluster service!)
oc delete svc weasyprint
oc delete svc postgresql
oc delete svc edivorce-django
# delete routes
oc delete route --all
# delete persistent volume claims
oc delete pvc --all
# delete replication controllers
oc delete rc --all
# delete deployment configurations
oc delete dc --all
# delete pods
oc delete po --all

jenkins-pipeline/jenkinsfile → openshift/jenkins/build-and-deploy-to-dev View File

@ -1,18 +1,12 @@
node('master') { node('master') {
stage 'buildInDevelopment'
stage 'buildInTools'
openshiftBuild(namespace: 'jag-csb-edivorce-tools', buildConfig: 'edivorce-django', showBuildLogs: 'true') openshiftBuild(namespace: 'jag-csb-edivorce-tools', buildConfig: 'edivorce-django', showBuildLogs: 'true')
stage 'deployInDevelopment'
stage 'deployInDev'
openshiftTag(namespace: 'jag-csb-edivorce-tools', sourceStream: 'edivorce-django', sourceTag: 'latest', destinationNamespace: 'jag-csb-edivorce-tools', destinationStream: 'edivorce-django', destinationTag: 'deploy-to-dev')
openshiftDeploy(namespace: 'jag-csb-edivorce-dev', deploymentConfig: 'edivorce-django') openshiftDeploy(namespace: 'jag-csb-edivorce-dev', deploymentConfig: 'edivorce-django')
openshiftScale(namespace: 'jag-csb-edivorce-dev', deploymentConfig: 'edivorce-django',replicaCount: '1') openshiftScale(namespace: 'jag-csb-edivorce-dev', deploymentConfig: 'edivorce-django',replicaCount: '1')
stage 'test'
sh 'curl -s https://justice.gov.bc.ca/divorce-dev'
stage 'deployInTesting'
openshiftTag(namespace: 'jag-csb-edivorce-tools', sourceStream: 'edivorce-django', sourceTag: 'latest', destinationNamespace: 'jag-csb-edivorce-tools', destinationStream: 'edivorce-django', destinationTag: 'deploy-to-test')
openshiftDeploy(namespace: 'jag-csb-edivorce-test', deploymentConfig: 'edivorce-django')
openshiftScale(namespace: 'jag-csb-edivorce-test', deploymentConfig: 'edivorce-django',replicaCount: '1')
} }

+ 8
- 0
openshift/jenkins/deploy-to-prod View File

@ -0,0 +1,8 @@
node('master') {
stage 'deployInProd'
openshiftTag(namespace: 'jag-csb-edivorce-tools', sourceStream: 'edivorce-django', sourceTag: 'deploy-to-test', destinationNamespace: 'jag-csb-edivorce-tools', destinationStream: 'edivorce-django', destinationTag: 'deploy-to-prod')
openshiftDeploy(namespace: 'jag-csb-edivorce-prod', deploymentConfig: 'edivorce-django')
openshiftScale(namespace: 'jag-csb-edivorce-prod', deploymentConfig: 'edivorce-django',replicaCount: '1')
}

+ 9
- 0
openshift/jenkins/deploy-to-test View File

@ -0,0 +1,9 @@
node('master') {
stage 'deployInTest'
openshiftTag(namespace: 'jag-csb-edivorce-tools', sourceStream: 'edivorce-django', sourceTag: 'deploy-to-dev', destinationNamespace: 'jag-csb-edivorce-tools', destinationStream: 'edivorce-django', destinationTag: 'deploy-to-test')
openshiftDeploy(namespace: 'jag-csb-edivorce-test', deploymentConfig: 'edivorce-django')
openshiftScale(namespace: 'jag-csb-edivorce-test', deploymentConfig: 'edivorce-django',replicaCount: '1')
}

+ 114
- 0
openshift/jenkins/pipeline.yaml View File

@ -0,0 +1,114 @@
---
kind: Template
apiVersion: v1
metadata:
name: edivorce-build-pipeline
labels:
template: edivorce-build-pipeline
objects:
- kind: BuildConfig
apiVersion: v1
metadata:
name: build-and-deploy-to-dev
namespace:
labels:
name: build-and-deploy-to-dev
annotations:
pipeline.alpha.openshift.io/uses: '[{"name": "", "namespace": "", "kind": "DeploymentConfig"}]'
spec:
triggers:
-
type: GitHub
github:
secret: ${GITHUB_WEBHOOK_SECRET}
-
type: Generic
generic:
secret: ${GITHUB_WEBHOOK_SECRET}
runPolicy: Serial
source:
type: Git
git:
uri: 'https://github.com/bcgov/eDivorce'
ref: master
contextDir: openshift/jenkins
strategy:
type: JenkinsPipeline
jenkinsPipelineStrategy:
jenkinsfilePath: build-and-deploy-to-dev
output:
resources:
postCommit:
- kind: BuildConfig
apiVersion: v1
metadata:
name: deploy-to-prod
namespace:
labels:
name: deploy-to-prod
annotations:
pipeline.alpha.openshift.io/uses: '[{"name": "", "namespace": "", "kind": "DeploymentConfig"}]'
spec:
triggers:
-
type: GitHub
github:
secret: ${GITHUB_WEBHOOK_SECRET}
-
type: Generic
generic:
secret: ${GITHUB_WEBHOOK_SECRET}
runPolicy: Serial
source:
type: Git
git:
uri: 'https://github.com/bcgov/eDivorce'
ref: master
contextDir: openshift/jenkins
strategy:
type: JenkinsPipeline
jenkinsPipelineStrategy:
jenkinsfilePath: deploy-to-prod
output:
resources:
postCommit:
- kind: BuildConfig
apiVersion: v1
metadata:
name: deploy-to-test
namespace:
labels:
name: deploy-to-test
annotations:
pipeline.alpha.openshift.io/uses: '[{"name": "", "namespace": "", "kind": "DeploymentConfig"}]'
spec:
triggers:
-
type: GitHub
github:
secret: ${GITHUB_WEBHOOK_SECRET}
-
type: Generic
generic:
secret: ${GITHUB_WEBHOOK_SECRET}
runPolicy: Serial
source:
type: Git
git:
uri: 'https://github.com/bcgov/eDivorce'
ref: master
contextDir: openshift/jenkins
strategy:
type: JenkinsPipeline
jenkinsPipelineStrategy:
jenkinsfilePath: deploy-to-test
output:
resources:
postCommit:
parameters:
- 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}"

nginx-proxy/conf.d/server.conf → openshift/nginx-proxy/conf.d/server.conf View File


+ 0
- 14
openshift/project_label.sh View File

@ -1,14 +0,0 @@
#!/usr/bin/env bash
# todo: this is an example from https://github.com/bcgov/esm-server/tree/develop/openshift
# todo: it needs to be completely reconfigured for eDivorce!!!!
#project_label.sh $OS_PROJECT_NAME category=$CATEGORY team=$TEAM product=$PRODUCT environment=$ENVIRONMENT
PROJECT_NAME=$1
echo "Project name is $1"
for i in "${@:2}"; do
oc label --overwrite namespace/$PROJECT_NAME $i
done

+ 0
- 41
openshift/scripts/run-in-container.sh View File

@ -1,41 +0,0 @@
#!/bin/bash
# Use this script to run one-off commands inside a container of a pod where your
# Python application code lives in.
# You can accomplish the same results by using regular commands from OpenShift.
# This script is just wrapping calls to `oc` to make it a little more
# convenient to use. In the future, the `oc` cli tool might incorporate changes
# that make this script obsolete.
# Related GitHub issues:
# - https://github.com/GoogleCloudPlatform/kubernetes/issues/8876
# - https://github.com/openshift/origin/issues/2001
# Usage examples:
#
# ./run-in-container.sh ./manage.py migrate
# ./run-in-container.sh ./manage.py createsuperuser
# ./run-in-container.sh ./manage.py shell
#
# If your Python pods are labeled with a name other than "django", you can use:
#
# POD_NAME=name ./run-in-container.sh ./manage.py check
#
# If there is more than one replica, you can also specify a POD by index:
#
# POD_INDEX=1 ./run-in-container.sh ./manage.py shell
#
# Or both together:
#
# POD_NAME=frontend POD_INDEX=2 ./run-in-container.sh ./manage.py shell
# Get name of a currently deployed pod by label and index
POD_INSTANCE_NAME=`oc get pods \
-l "name=${POD_NAME:-django-frontend}" \
-t "{{ with index .items ${POD_INDEX:-0} }}{{ .metadata.name }}{{ end }}"`
# Run command in a container of the specified pod:
oc exec -p "$POD_INSTANCE_NAME" -it -- bash -c "${@:-echo}"

+ 1
- 1
openshift/templates/nginx-build-template.yaml View File

@ -69,7 +69,7 @@ parameters:
- name: SOURCE_REPOSITORY_CONTEXT_DIR - name: SOURCE_REPOSITORY_CONTEXT_DIR
displayName: Git sub-directory displayName: Git sub-directory
description: The folder in the Git repo that contains the config.d directory. description: The folder in the Git repo that contains the config.d directory.
value: /nginx-proxy
value: /openshift/nginx-proxy
- name: SOURCE_REPOSITORY_REF - name: SOURCE_REPOSITORY_REF
displayName: Git Reference 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. description: Set this to a branch name, tag or other ref of your repository if you are not using the default branch.


Loading…
Cancel
Save