Created
November 30, 2017 13:45
-
-
Save abn/802f09ff42f4bff373cd883911d8830b to your computer and use it in GitHub Desktop.
OpenShift Template: .NET build w/ pipeline configuration using multiple sources when using no dependency management
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
apiVersion: v1 | |
kind: Template | |
labels: | |
template: dotnet-service-multisource-template | |
metadata: | |
annotations: | |
openshift.io/display-name: .Net Multi-Source Service | |
description: .Net Multi-Source Service | |
iconClass: icon-dotnet | |
tags: dotnet | |
name: dotnet-service-multisource | |
objects: | |
- apiVersion: v1 | |
kind: BuildConfig | |
metadata: | |
labels: | |
name: ${NAME}-pipeline | |
service: ${NAME} | |
name: ${NAME}-pipeline | |
spec: | |
runPolicy: SerialLatestOnly | |
source: | |
type: None | |
sourceSecret: | |
name: ${GIT_SECRET_NAME} | |
strategy: | |
jenkinsPipelineStrategy: | |
jenkinsfile: | | |
node (''){ | |
stage('Prepare Environment') { | |
// extract SERVICE_NAME used to determine OpenShift Build Config name | |
env.SERVICE_NAME = "${env.JOB_NAME}".replaceAll(/-?${env.PROJECT_NAME}-?/,'').replaceAll(/-?pipeline-?/, '') | |
// explicitly set project name for determining credential id in later execution | |
env.PROJECT_NAME="${env.PROJECT_NAME}" | |
} | |
} | |
node ('${JENKINS_BUILD_POD_NAME}') { | |
// current stages does not require dotnet slave, however this is executed | |
// here to demonstrate capability of executing tests prior to building images | |
stage('Checkout Sources') { | |
// set the dependent source repositories | |
def sources = "${SOURCE_REPOSITORY_URLS}".split(',') | |
// list containing source directories for later use | |
def source_dirs = [] | |
// using traditional loops as a workaround for | |
// https://issues.jenkins-ci.org/browse/JENKINS-34645 | |
for (i = 0; i < sources.length; i++) { | |
def url = sources[i] | |
def dirname = url.split('/')[-1] | |
source_dirs.add(dirname) | |
dir(dirname) { | |
git ( | |
url: url, | |
credentialsId: "${env.PROJECT_NAME}-${GIT_SECRET_NAME}", | |
branch: 'master' | |
) | |
} | |
} | |
// store directory names into env for later stage | |
env.SOURCE_DIRS = source_dirs.join(' ') | |
} | |
stage('Create Source Archive') { | |
// we do this to avoid performance hits when sending many small files | |
sh "tar -czf source.tar.gz ${env.SOURCE_DIRS}" | |
} | |
stage('Build Service Image') { | |
sh "oc start-build ${env.SERVICE_NAME} --from-archive=source.tar.gz --follow" | |
} | |
} | |
type: JenkinsPipeline | |
triggers: | |
- type: Generic | |
generic: | |
allowEnv: true | |
secret: ${GIT_WEBHOOK_SECRET} | |
- type: ConfigChange | |
- apiVersion: v1 | |
kind: BuildConfig | |
metadata: | |
labels: | |
service: ${NAME} | |
name: ${NAME} | |
spec: | |
output: | |
to: | |
kind: ImageStreamTag | |
name: ${NAME}:latest | |
runPolicy: Serial | |
source: | |
type: Binary | |
strategy: | |
sourceStrategy: | |
env: | |
- name: DOTNET_STARTUP_PROJECT | |
value: ${DOTNET_STARTUP_PROJECT} | |
- name: DOTNET_FRAMEWORK | |
value: ${DOTNET_FRAMEWORK} | |
from: | |
kind: DockerImage | |
name: registry.access.redhat.com/dotnet/dotnet-20-rhel7:latest | |
type: Source | |
- apiVersion: v1 | |
kind: ImageStream | |
metadata: | |
labels: | |
service: ${NAME} | |
name: ${NAME} | |
- apiVersion: v1 | |
kind: DeploymentConfig | |
metadata: | |
labels: | |
service: ${NAME} | |
name: ${NAME} | |
spec: | |
replicas: 1 | |
selector: | |
deploymentconfig: ${NAME} | |
strategy: | |
type: Rolling | |
template: | |
metadata: | |
labels: | |
service: ${NAME} | |
deploymentconfig: ${NAME} | |
spec: | |
containers: | |
- image: sandbox/${NAME}:latest | |
imagePullPolicy: Always | |
name: ${NAME} | |
ports: | |
- containerPort: 5001 | |
protocol: TCP | |
terminationMessagePath: /dev/termination-log | |
terminationMessagePolicy: File | |
dnsPolicy: ClusterFirst | |
restartPolicy: Always | |
schedulerName: default-scheduler | |
terminationGracePeriodSeconds: 30 | |
test: false | |
triggers: | |
- type: ImageChange | |
imageChangeParams: | |
automatic: true | |
containerNames: | |
- ${NAME} | |
from: | |
kind: ImageStreamTag | |
name: ${NAME}:latest | |
- type: ConfigChange | |
- apiVersion: v1 | |
kind: Service | |
metadata: | |
labels: | |
service: ${NAME} | |
name: ${NAME} | |
spec: | |
ports: | |
- name: 5001-tcp | |
port: 5001 | |
protocol: TCP | |
targetPort: 5001 | |
selector: | |
deploymentconfig: ${NAME} | |
sessionAffinity: None | |
type: ClusterIP | |
parameters: | |
- description: The name assigned to all objects and the resulting imagestream. | |
displayName: Name | |
name: NAME | |
required: true | |
- name: SOURCE_REPOSITORY_URLS | |
displayName: Service Source Repositories | |
description: Comma separated git url(s) for service projects and dependencies. | |
required: true | |
- name: DOTNET_STARTUP_PROJECT | |
displayName: .NET Startup Project | |
description: The startup projects as required for dotnet builds. | |
required: true | |
- name: DOTNET_FRAMEWORK | |
displayName: .NET Framework | |
description: The app framework as required for dotnet builds. | |
value: netcoreapp2.0 | |
- name: GIT_SECRET_NAME | |
displayName: Git Secret Name | |
description: The OpenShift secret name containing the SSH key used for git. | |
value: deployment-key | |
- name: GIT_WEBHOOK_SECRET | |
displayName: Git Webhook Secret | |
description: A secret string used to configure the git webhook. | |
from: '[a-zA-Z0-9]{40}' | |
generate: expression | |
- name: JENKINS_BUILD_POD_NAME | |
displayName: Jenkins Build Pod Name | |
description: Jenkins build pod name to execute the build/test in. | |
value: dotnet |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment