diff --git a/Dockerfile b/Dockerfile index ccae302..67dedc1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,15 @@ # Build the application first using Maven -FROM maven:3.8-openjdk-11 as build -WORKDIR /app -COPY . . -RUN mvn install +#FROM maven:3.8-openjdk-11 as build +#FROM 3.9.11-sapmachine-11 as build +#WORKDIR /app +#COPY . . +#RUN mvn clean install # Inject the JAR file into a new container to keep the file small -FROM openjdk:11-jre-slim -WORKDIR /app -COPY --from=build /app/target/hello-java-spring-boot-*.jar /app/app.jar -EXPOSE 8080 -ENTRYPOINT ["sh", "-c"] -CMD ["java -jar app.jar"] +#FROM openjdk:11-jre-slim +#WORKDIR /app +#COPY --from=build /app/target/hello-java-spring-boot-*.jar /app/app.jar +#EXPOSE 8080 +#ENTRYPOINT ["sh", "-c"] +#CMD ["java -jar app.jar"] +FROM m1k3pjem/hello-java-spring-boot:latest diff --git a/Jenkinsfile b/Jenkinsfile index b9893e6..66a9a0c 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,37 +1,69 @@ // Based on: // https://raw.githubusercontent.com/redhat-cop/container-pipelines/master/basic-spring-boot/Jenkinsfile - -library identifier: "pipeline-library@v1.5", -retriever: modernSCM( - [ - $class: "GitSCMSource", - remote: "https://github.com/redhat-cop/pipeline-library.git" - ] -) - -// The name you want to give your Spring Boot application -// Each resource related to your app will be given this name -appName = "hello-java-spring-boot" - pipeline { - // Use the 'maven' Jenkins agent image which is provided with OpenShift - agent { label "maven" } + options { + // set a timeout of 60 minutes for this pipeline + timeout(time: 5, unit: 'MINUTES') + } + + environment { + DEV_PROJECT = "mavc23-dev" + APP_NAME = "hello-java-spring-boot" + APP_GIT_URL = "https://github.com/m1k3dcdc/hello-java-spring-boot.git" + } + + agent any + stages { - stage("Checkout") { - steps { - checkout scm + stage('Create Container Image') { + steps { + echo '### Create Container Image... ###' + + script { + openshift.withCluster() { + openshift.withProject("$DEV_PROJECT") { + echo "### Using project: ${openshift.project()}" + def buildConfigExists = openshift.selector("bc", "hello-java-spring-boot-bc").exists() + + echo "### BuildConfig: " + APP_NAME + " exists, start new build to update app ..." + if (!buildConfigExists) { + echo "### newBuild " + APP_NAME + " does not exist" + openshift.newBuild("--name=hello-java-spring-boot-bc", "--image=docker.io/m1k3pjem/hello-java-spring-boot", "--binary") + + if (!openshift.selector("route", APP_NAME).exists()) { + echo "### Route " + APP_NAME + " does not exist, exposing service ..." + //def service = openshift.selector("service", APP_NAME) + //service.expose() + } else { + echo "### Route " + APP_NAME + " exist" + } + } + openshift.selector("bc", "hello-java-spring-boot-bc").startBuild("--from-dir=.", "--follow") + } + } } + } } - stage("Docker Build") { - steps { - // This uploads your application's source code and performs a binary build in OpenShift - // This is a step defined in the shared library (see the top for the URL) - // (Or you could invoke this step using 'oc' commands!) - binaryBuild(buildConfigName: appName, buildFromPath: ".") + + stage('Deploy') { + steps { + echo 'Deploying....' + script { + openshift.withCluster() { + openshift.withProject("mavc23-dev") { + + def deployment = openshift.selector("dc", "hello-java-spring-boot") + + if(!deployment.exists()){ + //openshift.newApp('hello-java-spring-boot', "--as-deployment-config").narrow('svc').expose() + sh "oc apply -f . -n mavc23-dev" + } + + } + } } + } } - // You could extend the pipeline by tagging the image, - // or deploying it to a production environment, etc...... } } diff --git a/deploy.yml b/deploy.yml index 591e42d..a816e9f 100644 --- a/deploy.yml +++ b/deploy.yml @@ -1,53 +1,64 @@ apiVersion: v1 kind: List items: -- apiVersion: v1 - kind: Service - metadata: - labels: - app: hello-java-spring-boot - app.kubernetes.io/component: hello-java-spring-boot - app.kubernetes.io/instance: hello-java-spring-boot - name: hello-java-spring-boot - spec: - ports: - - name: 8080-tcp - port: 8080 - protocol: TCP - targetPort: 8080 - selector: - deployment: hello-java-spring-boot - sessionAffinity: None - type: ClusterIP -- apiVersion: apps/v1 - kind: Deployment - metadata: - labels: - app: hello-java-spring-boot - app.kubernetes.io/component: hello-java-spring-boot - app.kubernetes.io/instance: hello-java-spring-boot - name: hello-java-spring-boot - spec: - replicas: 1 - selector: - matchLabels: + - apiVersion: apps/v1 + kind: Deployment + metadata: + labels: app: hello-java-spring-boot - template: - metadata: - labels: + app.kubernetes.io/component: hello-java-spring-boot + app.kubernetes.io/instance: hello-java-spring-boot + name: hello-java-spring-boot-deploy + spec: + replicas: 1 + selector: + matchLabels: app: hello-java-spring-boot - name: hello-java-spring-boot - spec: - containers: - - image: monodot/hello-java-spring-boot:latest - imagePullPolicy: IfNotPresent + template: + metadata: + labels: + app: hello-java-spring-boot name: hello-java-spring-boot - env: - - name: FAVOURITE_CHEESE - valueFrom: - configMapKeyRef: my-configmap - key: thefavourite.cheese - ports: - - containerPort: 8080 - protocol: TCP - restartPolicy: Always + spec: + containers: + - image: docker.io/m1k3pjem/hello-java-spring-boot:latest + imagePullPolicy: IfNotPresent + name: hello-java-spring-boot + env: + - name: FAVOURITE_CHEESE + valueFrom: + configMapKeyRef: + name: hello-java-spring-boot-configmap + key: thefavourite.cheese + ports: + - containerPort: 8080 + protocol: TCP + restartPolicy: Always + - apiVersion: v1 + kind: Service + metadata: + labels: + app: hello-java-spring-boot + app.kubernetes.io/component: hello-java-spring-boot + app.kubernetes.io/instance: hello-java-spring-boot + name: hello-java-spring-boot-service + spec: + ports: + - name: 8080-tcp + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + deployment: hello-java-spring-boot + sessionAffinity: None + type: ClusterIP + - apiVersion: v1 + kind: ConfigMap + metadata: + labels: + app: hello-java-spring-boot + app.kubernetes.io/component: hello-java-spring-boot + app.kubernetes.io/instance: hello-java-spring-boot + name: hello-java-spring-boot-configmap + data: + thefavourite.cheese: GOUDA diff --git a/openshift-build.yml b/openshift-build.yml deleted file mode 100644 index afa9a53..0000000 --- a/openshift-build.yml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: v1 -kind: List -items: -- apiVersion: build.openshift.io/v1 - kind: BuildConfig - metadata: - labels: - app.kubernetes.io/name: hello-java-spring-boot - name: hello-java-spring-boot - spec: - output: - to: - kind: DockerImage - name: docker.io/monodot/hello-java-spring-boot:latest - source: - # Expect a local directory to be streamed to OpenShift as a build source - type: Binary - binary: {} - strategy: - type: Docker - dockerStrategy: - # Find the image build instructions in ./Dockerfile - dockerfilePath: Dockerfile diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 39a2b6e..0000000 --- a/renovate.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ] -}