commit e3b8996d076919d2d371349b5d307228dd488ee1 Author: Sander Hautvast Date: Mon Apr 26 15:55:20 2021 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ec10551 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +target/ +.idea/ +*.iml diff --git a/deployment/Jenkinsfile b/deployment/Jenkinsfile new file mode 100644 index 0000000..decf947 --- /dev/null +++ b/deployment/Jenkinsfile @@ -0,0 +1,35 @@ +pipeline{ + agent none + options { + skipDefaultCheckout() + } + + stages { + stage('Build') { + stages{ + stage('Check out') { + steps { + checkout scm + stash(name: 'hello_world', includes: '**', excludes: '**/.git/**') + } + } + stage('Maven build') { + steps { + unstash 'hello_world' + sh(script: 'mvn -B -f pom.xml clean package -Pdeploy -pl :hello-world -am') + stash(name: 'war', includes: '**') + } + } + stage('Create Build Config'){ + when { + expression { + openshift.withCluster(){ + return !openshift.selector("bc", "") + } + } + } + } + } + } + } +} \ No newline at end of file diff --git a/deployment/buildconfig.yaml b/deployment/buildconfig.yaml new file mode 100644 index 0000000..58cec5c --- /dev/null +++ b/deployment/buildconfig.yaml @@ -0,0 +1,44 @@ +apiVersion: v1 +kind: List +metadata: + name: hello-world +items: +- kind: BuildConfig + apiVersion: build.openshift.io/v1 + metadata: + name: hello-world + labels: + build: hello-world + spec: + output: + to: + kind: ImageStreamTag + name: 'hello-world:latest' + resources: + limits: + cpu: 700m + memory: 800Mi + succesfulBuildsHistoryLimit: 5 + failedBuildsHistoryLimit: 5 + strategy: + type: Source + sourceStrategy: + from: + kind: DockerImage + name: 'open-liberty:19.0.0.9-kernel-java11' + postCommit: {} + source: + type: Binary + binary: {} + triggers: + - type: GitHub + github: + secret: 6FCAFBB9756846ED + runPolicy: Serial +- kind: ImageStream + apiVersion: image.openshift.io/v1 + metadata: + labels: + build: hello-world + name: hello-world + spec: {} \ No newline at end of file diff --git a/deployment/hello-world-template.yaml b/deployment/hello-world-template.yaml new file mode 100644 index 0000000..2694b4c --- /dev/null +++ b/deployment/hello-world-template.yaml @@ -0,0 +1,110 @@ +kind: Template +metadata: + name: hello-world + annotations: + description: "Deployment Config for Hello World application" +apiVersion: v1 +objects: +- apiVersion: apps.openshift.io/v1 + kind: DeploymentConfig + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + labels: + app: hello-world + component: hello-world + name: hello-world + spec: + replicas: 1 + revisionHistoryLimit: 10 + selector: + app: hello-world + deploymentconfig: hello-world + strategy: + activeDeadlineSeconds: 21600 + resources: {} + rollingParams: + intervalSeconds: 1 + maxSurge: 25% + maxUnavailable: 25% + timeoutSeconds: 600 + updatePeriodSeconds: 1 + type: Rolling + template: + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + labels: + app: hello-world + component: hello-world + deploymentconfig: hello-world + spec: + containers: + - envFrom: + image: ' ' + imagePullPolicy: Always + name: hello-world + ports: + - containerPort: 9080 + protocol: TCP + - containerPort: 9443 + protocol: TCP + resources: {} + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + scheduler-name: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 + test: false + triggers: + - imageChangeParams: + containerNames: + - hello-world + from: + kind: ImageStreamTag + name: hello-world:latest + type: ImageChange + - type: ConfigChange +- apiVersion: route.openshift.io/v1 + kind: Route + metadata: + annotations: + openshift.io/host.generated: "true" + labels: + app: hello-world + component: hello-world + name: hello-world + spec: + port: + targetPort: 9080-tcp + to: + kind: Service + name: hello-world + weight: 100 + wildcardPolicy: None +- apiVersion: v1 + kind: Service + metadata: + annotations: + openshift.io/generated-by: OpenShiftNewApp + labels: + app: hello-world + component: hello-world + name: hello-world + spec: + ports: + - name: 9080-tcp + port: 9080 + protocol: TCP + targetPort: 9080 + - name: 9443-tcp + port: 9443 + protocol: TCP + targetPort: 9080 + selector: + app: hello-world + deploymentconfig: hello-world + sessionAffinity: None + type: ClusterIP \ No newline at end of file diff --git a/deployment/pom.xml b/deployment/pom.xml new file mode 100644 index 0000000..d40de3f --- /dev/null +++ b/deployment/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.sander + hello-world-deployment + 1.0-SNAPSHOT + + + + org.sander + hello-world + ${project.version} + war + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy + package + + copy-dependencies + + + ${basedir}/target + true + true + true + true + war + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..901383e --- /dev/null +++ b/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + org.sander + hello-world + 1.0-SNAPSHOT + war + ${project.artifactId} + Simple application to demonstrate deployment on openshift + + + 11 + 11 + + + + + javax + javaee-api + 7.0 + + + \ No newline at end of file diff --git a/src/main/java/org/sander/hello/HelloWorldController.java b/src/main/java/org/sander/hello/HelloWorldController.java new file mode 100644 index 0000000..4744a9d --- /dev/null +++ b/src/main/java/org/sander/hello/HelloWorldController.java @@ -0,0 +1,16 @@ +package org.sander.hello; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/hello") +public class HelloWorldController { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String getHello(){ + return "Hello World"; + } +}