Skip to content

Commit 3b015c7

Browse files
authored
Adding conditional steps to release tag and master branch & adding a … (#15)
* Adding conditional steps to release tag and master branch & adding a secret config to openshift applier if pushing to quay * Updating README.md * Updating README.md * Replacing with the correct labs quay repo
1 parent 192e2d6 commit 3b015c7

File tree

4 files changed

+58
-80
lines changed

4 files changed

+58
-80
lines changed

.applier/inventory/group_vars/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ build_vars:
1010
GIT_REF: master
1111
OUTPUT_IMAGE_NAME: '{{ app_name }}'
1212
OUTPUT_IMAGE_TAG: latest
13+
PUSH_SECRET: quay-registry-secret
1314
BUILDER_IMAGE_NAME: registry.access.redhat.com/fuse7/fuse-java-openshift
1415
BUILDER_IMAGE_TAG: 1.5
1516

.applier/templates/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ objects:
2020
failedBuildsHistoryLimit: 5
2121
nodeSelector: null
2222
output:
23+
pushSecret:
24+
name: ${PUSH_SECRET}
2325
to:
2426
kind: ImageStreamTag
2527
name: "${OUTPUT_IMAGE_NAME}:${OUTPUT_IMAGE_TAG}"

Jenkinsfile

Lines changed: 44 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,13 @@ pipeline{
3535
}
3636

3737
stages{
38+
3839
stage("Prepare environment for master deploy") {
3940
agent {
4041
node {
4142
label "master"
4243
}
4344
}
44-
when {
45-
expression { GIT_BRANCH ==~ /(.*master)/ }
46-
}
4745
steps {
4846
script {
4947
// Arbitrary Groovy Script executions can do in script tags
@@ -54,33 +52,13 @@ pipeline{
5452
}
5553
}
5654
}
57-
stage("Prepare environment for develop deploy") {
58-
agent {
59-
node {
60-
label "master"
61-
}
62-
}
63-
when {
64-
expression { GIT_BRANCH ==~ /(.*develop|.*feature.*)/ }
65-
}
66-
steps {
67-
script {
68-
// Arbitrary Groovy Script executions can do in script tags
69-
env.PROJECT_NAMESPACE = "${NAMESPACE_PREFIX}-dev"
70-
env.NODE_ENV = "dev"
71-
env.QUARKUS_PROFILE = "openshift-dev"
72-
}
73-
}
74-
}
55+
7556
stage("Ansible") {
7657
agent {
7758
node {
7859
label "jenkins-slave-ansible"
7960
}
8061
}
81-
when {
82-
expression { GIT_BRANCH ==~ /(.*master|.*develop|.*feature.*)/ }
83-
}
8462
stages{
8563
stage("Ansible Galaxy") {
8664
steps {
@@ -96,6 +74,7 @@ pipeline{
9674
}
9775
}
9876
}
77+
9978
stage("Test/Build/Nexus/OpenShift Build"){
10079
agent {
10180
node {
@@ -141,8 +120,7 @@ pipeline{
141120
}
142121
steps{
143122
echo '### Running deploy ###'
144-
// sh './mvnw deploy'
145-
//
123+
// sh './mvnw deploy'
146124
}
147125
// Post can be used both on individual stages and for the entire build.
148126
post {
@@ -160,61 +138,58 @@ pipeline{
160138
}
161139
}
162140
}
163-
stage("Start Openshift Build"){
164-
when {
165-
expression { currentBuild.result != 'UNSTABLE' }
166-
}
167-
steps{
168-
echo '### Create Linux Container Image from package ###'
169-
sh '''
170-
oc project ${PIPELINES_NAMESPACE} # probs not needed
171-
oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"ImageStreamTag\\",\\"name\\":\\"${APP_NAME}:${JENKINS_TAG}\\"}}}}"
172-
oc start-build ${APP_NAME} --from-file=target/${ARTIFACTID}-${VERSION}-runner.jar --follow
173-
'''
174-
}
175-
}
141+
176142
}
177143
}
178-
stage("Openshift Deployment") {
144+
145+
146+
stage("Build a Container Image and Push it to Quay") {
179147
agent {
180148
node {
181-
label "jenkins-slave-ansible"
149+
label "master"
182150
}
183151
}
184152
when {
185-
allOf{
186-
expression { GIT_BRANCH ==~ /(.*master|.*develop|.*feature.*)/ }
187-
expression { currentBuild.result != 'UNSTABLE' }
188-
}
153+
expression { GIT_BRANCH ==~ /(.*tags\/release.*)/ }
189154
}
190155
steps {
191-
echo '### Apply Inventory using Ansible-Playbook ###'
192-
sh "ansible-galaxy install -r .applier/requirements.yml --roles-path=.applier/roles"
193-
sh "ansible-playbook .applier/apply.yml -i .applier/inventory/ -e include_tags=${NODE_ENV} -e ${NODE_ENV}_vars='{\"NAME\":\"${APP_NAME}\",\"IMAGE_NAME\":\"${APP_NAME}\",\"IMAGE_TAG\":\"${JENKINS_TAG}\"}'"
156+
157+
echo '### Create Container Image ###'
158+
sh '''
159+
oc project ${PIPELINES_NAMESPACE} # probs not needed
160+
oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"DockerImage\\",\\"name\\":\\"quay.io/rht-labs/${APP_NAME}:${JENKINS_TAG}\\"}}}}"
161+
oc start-build ${APP_NAME} --from-file=target/${ARTIFACTID}-${VERSION}-runner.jar --follow
162+
'''
163+
}
164+
post {
165+
always {
166+
archive "**"
167+
}
168+
}
169+
}
194170

195-
echo '### tag image for namespace ###'
171+
stage("Build a Container Image") {
172+
agent {
173+
node {
174+
label "master"
175+
}
176+
}
177+
when {
178+
expression { GIT_BRANCH ==~ /(.*master)/ }
179+
}
180+
steps {
181+
182+
echo '### Create Container Image ###'
196183
sh '''
197-
oc project ${PROJECT_NAMESPACE}
198-
oc tag ${PIPELINES_NAMESPACE}/${APP_NAME}:${JENKINS_TAG} ${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
184+
oc project ${PIPELINES_NAMESPACE} # probs not needed
185+
oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"ImageStreamTag\\",\\"name\\":\\"${APP_NAME}:${JENKINS_TAG}\\"}}}}"
186+
oc start-build ${APP_NAME} --from-file=target/${ARTIFACTID}-${VERSION}-runner.jar --follow
199187
'''
200-
echo '### Create a Configmap ###'
201-
sh "oc create configmap ${APP_NAME}-config --from-file=src/main/resources/application.properties --dry-run -o yaml | oc apply -f -"
202-
echo '### set env vars and image for deployment ###'
203-
sh '''
204-
oc set env dc ${APP_NAME} NODE_ENV=${NODE_ENV} QUARKUS_PROFILE=${QUARKUS_PROFILE}
205-
oc set image dc/${APP_NAME} ${APP_NAME}=docker-registry.default.svc:5000/${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
206-
oc label --overwrite dc ${APP_NAME} stage=${NODE_ENV}
207-
oc patch dc ${APP_NAME} -p "{\\"spec\\":{\\"template\\":{\\"metadata\\":{\\"labels\\":{\\"version\\":\\"${VERSION}\\",\\"release\\":\\"${RELEASE}\\",\\"stage\\":\\"${NODE_ENV}\\",\\"git-commit\\":\\"${GIT_COMMIT}\\",\\"jenkins-build\\":\\"${JENKINS_TAG}\\"}}}}}"
208-
oc rollout latest dc/${APP_NAME}
209-
'''
210-
echo '### Verify OCP Deployment ###'
211-
openshiftVerifyDeployment depCfg: env.APP_NAME,
212-
namespace: env.PROJECT_NAMESPACE,
213-
replicaCount: '1',
214-
verbose: 'false',
215-
verifyReplicaCount: 'true',
216-
waitTime: '',
217-
waitUnit: 'sec'
188+
}
189+
post {
190+
always {
191+
archive "**"
192+
}
218193
}
219194
}
220195
}

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,25 @@ mvn deploy
141141

142142
##### OpenShift Build
143143

144+
The OpenShift build is going to start after the Nexus deployment is complet and successful.
145+
146+
###### OpenShift Atomic Registry
147+
148+
If you're pushing from the master branch the build will create a container image and push it to the Openshift internal registry.
149+
144150
```
145151
oc project ${PIPELINES_NAMESPACE}
146152
oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"ImageStreamTag\\",\\"name\\":\\"${APP_NAME}:${JENKINS_TAG}\\"}}}}"
147153
oc start-build ${APP_NAME} --from-file=target/${ARTIFACTID}-${VERSION}-runner.jar --follow
148154
```
149155

150-
#### OpenShift Deployment
156+
###### Quay
151157

152-
Jenkins will spin up an Ansible agent that will run a playbook called OpenShift Applier (https://github.com/redhat-cop/openshift-applier). The `openshift-applier` is used to apply OpenShift objects to an OpenShift Cluster.
153-
154-
This agent is going to download the playbook dependencies using Ansible Galaxy and apply the playbook using **environment** as a *filter_tag*. This is going to create the necessary resources for our application deploy in an OpenShift cluster.
155-
156-
Once the resources are ready the pipeline is going to patch the DC with the new image and start a rollout deployment.
158+
If you're pushing from a release tag the build will create a container image and push it to Quay.
157159

158160
```
159-
oc set env dc ${APP_NAME} NODE_ENV=${NODE_ENV} QUARKUS_PROFILE=${QUARKUS_PROFILE}
160-
oc set image dc/${APP_NAME} ${APP_NAME}=docker-registry.default.svc:5000/${PROJECT_NAMESPACE}/${APP_NAME}:${JENKINS_TAG}
161-
oc label --overwrite dc ${APP_NAME} stage=${NODE_ENV}
162-
oc patch dc ${APP_NAME} -p "{\\"spec\\":{\\"template\\":{\\"metadata\\":{\\"labels\\":{\\"version\\":\\"${VERSION}\\",\\"release\\":\\"${RELEASE}\\",\\"stage\\":\\"${NODE_ENV}\\",\\"git-commit\\":\\"${GIT_COMMIT}\\",\\"jenkins-build\\":\\"${JENKINS_TAG}\\"}}}}}"
163-
oc rollout latest dc/${APP_NAME}
161+
oc project ${PIPELINES_NAMESPACE} # probs not needed
162+
oc patch bc ${APP_NAME} -p "{\\"spec\\":{\\"output\\":{\\"to\\":{\\"kind\\":\\"DockerImage\\",\\"name\\":\\"quay.io/rht-labs/${APP_NAME}:${JENKINS_TAG}\\"}}}}"
163+
oc start-build ${APP_NAME} --from-file=target/${ARTIFACTID}-${VERSION}-runner.jar --follow
164164
```
165165

0 commit comments

Comments
 (0)