This commit is contained in:
omallo 2017-01-04 20:36:18 +00:00 committed by GitHub
commit c3549341bf
15 changed files with 399 additions and 5 deletions

5
.gitattributes vendored Normal file
View File

@ -0,0 +1,5 @@
* text eol=lf
*.png binary
*.jpg binary
*.jpeg binary
*.jar binary

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"editor.tabSize": 2
}

6
GitVersion.yml Normal file
View File

@ -0,0 +1,6 @@
mode: ContinuousDeployment
branches:
master:
mode: ContinuousDeployment
ignore:
sha: []

View File

@ -1,5 +1,5 @@
Ruby Sample App on OpenShift
============================
Ruby Sample App on OpenShift (rubex)
====================================
This is a basic ruby application for OpenShift v3 that you can use as a starting point to develop your own application and deploy it on an [OpenShift](https://github.com/openshift/origin) cluster.

View File

@ -85,7 +85,6 @@ ul {
display: table;
/* 2 */
}
.container:after {
clear: both;
@ -226,10 +225,9 @@ pre {
<section class='container'>
<hgroup>
<h1>Welcome to your Ruby application on OpenShift</h1>
<h1>Welcome to your Ruby application on OpenShift (version {{BUILD_VERSION}})</h1>
</hgroup>
<div class="row">
<section class='col-xs-12 col-sm-6 col-md-6'>
<section>

24
deployment/config.yaml Normal file
View File

@ -0,0 +1,24 @@
prev:
deployment:
frontend:
templates:
- manifest: deployment/manifests/app.yaml
parameters:
ENV: prev
REPLICAS: 1
dev:
deployment:
frontend:
templates:
- manifest: deployment/manifests/app.yaml
parameters:
ENV: dev
REPLICAS: 1
test:
deployment:
frontend:
templates:
- manifest: deployment/manifests/app.yaml
parameters:
ENV: test
REPLICAS: 2

View File

@ -0,0 +1,45 @@
<?xml version='1.0' encoding='UTF-8'?>
<flow-definition plugin="workflow-job@2.9">
<description></description>
<keepDependencies>false</keepDependencies>
<properties>
<io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty plugin="openshift-sync@0.1.6">
<uid></uid>
<namespace></namespace>
<name></name>
<resourceVersion></resourceVersion>
</io.fabric8.jenkins.openshiftsync.BuildConfigProjectProperty>
<jenkins.model.BuildDiscarderProperty>
<strategy class="hudson.tasks.LogRotator">
<daysToKeep>-1</daysToKeep>
<numToKeep>5</numToKeep>
<artifactDaysToKeep>-1</artifactDaysToKeep>
<artifactNumToKeep>-1</artifactNumToKeep>
</strategy>
</jenkins.model.BuildDiscarderProperty>
<org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty/>
<org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
<triggers/>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
</properties>
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.23">
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.0.1">
<configVersion>2</configVersion>
<userRemoteConfigs>
<hudson.plugins.git.UserRemoteConfig>
<url>https://github.com/omallo/ruby-ex</url>
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec>
<name>*/master</name>
</hudson.plugins.git.BranchSpec>
</branches>
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
<submoduleCfg class="list"/>
<extensions/>
</scm>
<scriptPath>deployment/delivery-pipeline.groovy</scriptPath>
</definition>
<triggers/>
</flow-definition>

View File

@ -0,0 +1,45 @@
@Library('occd') _
node() {
stage("Checkout") {
deleteDir()
git(url: "https://github.com/omallo/ruby-ex.git", branch: "master", credentialsId: "github-omallo")
}
def config = occd.parseConfig(readFile("deployment/config.yaml"))
stage("Build") {
def buildVersion = occd.getDeliveryBuildVersion()
echo "buildVersion=${buildVersion}"
sh "sed -e 's/{{BUILD_VERSION}}/${buildVersion}/g' -i config.ru"
occd.build("rubex-dev", "frontend-master", "deployment/manifests/build.yaml", "master")
}
stage("Deploy to DEV") {
occd.tag("rubex-dev", "frontend", "b-master", "dev")
occd.rollout("rubex-dev", "frontend", config.dev.deployment.frontend)
}
def isPromoteToTest = false
stage("Promote to TEST?") {
isPromoteToTest = input(message: "Promotion", parameters: [booleanParam(defaultValue: false, name: "Promote to TEST?")])
}
if (isPromoteToTest) {
stage("Deploy to TEST") {
def releaseVersion = occd.getReleaseVersion()
echo "releaseVersion=${releaseVersion}"
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'github-omallo', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
sh "git tag ${releaseVersion}"
sh "git push --tags https://${GIT_USERNAME}:${GIT_PASSWORD}@github.com/omallo/ruby-ex.git"
}
occd.tag("rubex-dev", "frontend", "dev", releaseVersion)
occd.tag("rubex-dev", "frontend", releaseVersion, "test")
occd.rollout("rubex-test", "frontend", config.test.deployment.frontend)
}
}
}

View File

@ -0,0 +1,17 @@
@Library('occd') _
node() {
stage("Checkout") {
deleteDir()
git(url: "https://github.com/omallo/ruby-ex.git", branch: "${BRANCH}", credentialsId: "github-omallo")
}
stage("Build") {
def buildVersion = occd.getFeatureBuildVersion("${BRANCH}")
echo "versions: build=${buildVersion}"
sh "sed -e 's/{{BUILD_VERSION}}/${buildVersion}/g' -i config.ru"
occd.build("rubex-dev", "frontend-${BRANCH}", "deployment/manifests/build.yaml", "${BRANCH}")
}
}

View File

@ -0,0 +1,100 @@
apiVersion: v1
kind: Template
objects:
#- apiVersion: v1
# kind: PersistentVolumeClaim
# metadata:
# name: ${APP}-data
# labels:
# app: ${APP}
# spec:
# accessModes:
# - ReadWriteOnce
# resources:
# requests:
# storage: ${STORAGE_SIZE}
- apiVersion: v1
kind: DeploymentConfig
metadata:
name: ${APP}
labels:
app: ${APP}
spec:
replicas: ${REPLICAS}
selector:
app: ${APP}
deploymentconfig: ${APP}
template:
metadata:
labels:
app: ${APP}
deploymentconfig: ${APP}
spec:
containers:
- image: ${PROJECT_BASE}-${BUILD_ENV}/${APP}:${ENV}
imagePullPolicy: Always
name: ${APP}
ports:
- containerPort: 8080
protocol: TCP
triggers:
- type: ImageChange
imageChangeParams:
automatic: false
containerNames:
- ${APP}
from:
kind: ImageStreamTag
name: ${APP}:${ENV}
namespace: ${PROJECT_BASE}-${BUILD_ENV}
- apiVersion: v1
kind: Service
metadata:
name: ${APP}
labels:
app: ${APP}
spec:
ports:
- name: 8080-tcp
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: ${APP}
deploymentconfig: ${APP}
- apiVersion: v1
kind: Route
metadata:
name: ${APP}
labels:
app: ${APP}
spec:
port:
targetPort: 8080-tcp
to:
kind: Service
name: ${APP}
parameters:
- description: The project base name.
displayName: Project base name
name: PROJECT_BASE
value: rubex
- description: The application name.
displayName: Application name
name: APP
value: frontend
- description: The environment in which the image stream is built.
displayName: Build environment
name: BUILD_ENV
value: dev
- description: The environment into which the app is deployed.
displayName: Environment
name: ENV
- description: The number of replicas.
displayName: Replicas
name: REPLICAS
value: "1"
- description: The size of the storage to reclaim.
displayName: Storage size
name: STORAGE_SIZE
value: 5Gi

View File

@ -0,0 +1,38 @@
apiVersion: v1
kind: Template
objects:
- apiVersion: v1
kind: ImageStream
metadata:
name: ${APP}
labels:
app: ${APP}
- apiVersion: v1
kind: BuildConfig
metadata:
name: ${APP}-${BRANCH}
labels:
app: ${APP}
spec:
output:
to:
kind: ImageStreamTag
name: ${APP}:b-${BRANCH}
source:
type: Binary
binary: {}
strategy:
type: Source
sourceStrategy:
from:
kind: ImageStreamTag
name: ruby:2.3
namespace: openshift
parameters:
- description: The application name.
displayName: Application name
name: APP
value: frontend
- description: The branch being built.
displayName: Branch
name: BRANCH

View File

@ -0,0 +1,15 @@
@Library('occd') _
node() {
stage("Checkout") {
deleteDir()
git(url: "https://github.com/omallo/ruby-ex.git", branch: "${BRANCH}", credentialsId: "github-omallo")
}
def config = occd.parseConfig(readFile("deployment/config.yaml"))
stage("Deploy to PREV") {
occd.tag("rubex-dev", "frontend", "b-${BRANCH}", "prev")
occd.rollout("rubex-prev", "frontend", config.prev.deployment.frontend)
}
}

71
infra/setup.sh Normal file
View File

@ -0,0 +1,71 @@
#!/bin/bash
sudo htpasswd -b /etc/origin/master/htpasswd dev1 dev1
sudo htpasswd -b /etc/origin/master/htpasswd test1 test1
oc login -u system:admin
mkdir -p ~/openshift/volumes/
oc delete -f infra/volumes-local.yaml
oc apply -f infra/volumes-local.yaml
oc get pv
oc login -u system:admin
oc project openshift
oc delete is oc-jenkins
oc create is oc-jenkins
oc tag --source=docker --scheduled=true omallo/oc-jenkins:latest openshift/oc-jenkins:latest
oc login -u admin -p admin
oc new-project rubex-prev
oc policy add-role-to-user edit dev1 -n rubex-prev
oc policy add-role-to-user view test1 -n rubex-prev
oc login -u admin -p admin
oc new-project rubex-dev
oc policy add-role-to-user edit dev1 -n rubex-dev
oc policy add-role-to-user view test1 -n rubex-dev
oc login -u admin -p admin
oc new-project rubex-test
oc policy add-role-to-user edit test1 -n rubex-test
oc policy add-role-to-group system:image-puller system:serviceaccounts:rubex-prev -n rubex-dev
oc policy add-role-to-group system:image-puller system:serviceaccounts:rubex-test -n rubex-dev
oc login -u admin -p admin
oc new-project cicd
oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n rubex-prev
oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n rubex-dev
oc policy add-role-to-user edit system:serviceaccount:cicd:jenkins -n rubex-test
oc login -u admin -p admin
oc project cicd
oc process \
-f https://raw.githubusercontent.com/openshift/origin/master/examples/jenkins/jenkins-persistent-template.json \
-v JENKINS_IMAGE_STREAM_TAG=oc-jenkins:latest \
-v MEMORY_LIMIT=2Gi \
-v VOLUME_CAPACITY=5Gi \
| oc apply -f -
mkdir -p ~/openshift/volumes/disk-1/jobs/rubex-frontend-delivery
cp deployment/delivery-job-config.xml ~/openshift/volumes/disk-1/jobs/rubex-frontend-delivery/config.xml
# ---
oc login -u dev1 -p dev1
oc project rubex-dev
oc new-app --name frontend ruby:2.3~https://github.com/omallo/ruby-ex # then: configure GitHub webhook
oc expose service frontend
oc tag rubex-dev/frontend:latest rubex-dev/frontend:test
oc login -u test1 -p test1
oc project rubex-test
oc new-app rubex-dev/frontend:test
oc expose service frontend
oc login -u dev1 -p dev1
oc project rubex-dev
oc tag rubex-dev/frontend:latest rubex-dev/frontend:test

14
infra/volumes-gce.yaml Normal file
View File

@ -0,0 +1,14 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: disk-1
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
gcePersistentDisk:
pdName: disk-1
fsType: ext4

13
infra/volumes-local.yaml Normal file
View File

@ -0,0 +1,13 @@
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: disk-1
spec:
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /Users/omallo/openshift/volumes/disk-1