{"id":24849347,"url":"https://github.com/bugbiteme/hello-spring","last_synced_at":"2025-10-14T20:30:57.007Z","repository":{"id":43601936,"uuid":"137964074","full_name":"bugbiteme/hello-spring","owner":"bugbiteme","description":"Spring Boot \"Hello World\" with JUnit test intended for OpenShift and stand alone deployment demo","archived":false,"fork":false,"pushed_at":"2024-07-25T16:40:32.000Z","size":101,"stargazers_count":1,"open_issues_count":2,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-07T12:49:26.493Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bugbiteme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-20T01:26:22.000Z","updated_at":"2023-08-30T11:38:36.000Z","dependencies_parsed_at":"2025-01-31T12:43:08.529Z","dependency_job_id":null,"html_url":"https://github.com/bugbiteme/hello-spring","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/bugbiteme/hello-spring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugbiteme%2Fhello-spring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugbiteme%2Fhello-spring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugbiteme%2Fhello-spring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugbiteme%2Fhello-spring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bugbiteme","download_url":"https://codeload.github.com/bugbiteme/hello-spring/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bugbiteme%2Fhello-spring/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279020905,"owners_count":26086948,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-31T12:30:55.478Z","updated_at":"2025-10-14T20:30:57.001Z","avatar_url":"https://github.com/bugbiteme.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# hello-spring\n\nThis is a simple \"Hello World!\" web app using the Spring Boot java framework:\n[http://spring.io](http://spring.io).\n\nI intended **hello-spring** to be used with OpenShift workshops, but this can be used however you want. \n\nThis project also demonstrates JUnit testing. \n\nThis README file will provide instructions for building and running the service locally, as well as instructions for deploying to OpenShift using S2I (source to image) and setting up a build pipeline. \n\n*On a side note, you can easily spin up a Spring Boot project yourself from scratch by using the [\"SPRING INITIALIZR\"](http://start.spring.io). This will generate the maven pom.xml file and initial project directory structure that can compile and run right away, including setup for JUnit testing, which is demonstrated here in `hello-spring`.*\n\nThis project is set up to use maven to build the jar executable, so ensure that it is installed on your build system ([maven](https://maven.apache.org/install.html)). \n\n**Note**:  `yum`, `apt-get`, `brew install`, \n`chocolatey`, etc.. can all be used to install maven.\n\n## Building and running locally\nOnce you clone the project to your local system, you can build and test locally by running:\n\n`mvn clean test` - for unit testing\n\n`mvn clean package` - to compile a *jar executable \nwhich you can run locally\n\n`mvn spring-boot:run` - to build and run your code in one step.\n\nAfter successful compilation, you will find the executable jar in the `target/` directory.\n\nYou can also run the `hello` service with the following command from the project root directory:\n\n`java -jar target/*.jar`\n\nOnce the service is running, point your web browser to `localhost:8080` or run the command:\n\n`curl localhost:8080` \n\non the command line to see the welcome message.\n\nNote: Try `localhost:8080/api` as well!\n\n## Unit testing\nThe test class `HelloControllerTest` contains a unit test to ensure the application returns the string \"Hello World!\"\n\n~~~\n@Test\n    public void getHello() throws Exception {\n        mvc.perform(MockMvcRequestBuilders.get(\"/\").accept(MediaType.APPLICATION_JSON))\n                .andExpect(status().isOk())\n                .andExpect(content().string(equalTo(\"Hello World!\")));\n    }\n~~~\n\nWhen you use maven to package or test, you can see if the test passes or fails (passes by defualt).\n\n`mvn test`\n\n~~~\n[INFO] Results:\n[INFO] \n[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 8.661 s\n[INFO] Finished at: 2018-06-20T07:49:20-07:00\n[INFO] ------------------------------------------------------------------------\n\n~~~\n\n\nTo see the unit test fail, edit `String greeting`string in the `HelloController` class.\n\nExample:\n\n~~~\n@RestController\npublic class HelloController {\n\n\tString greeting = \"Hello Foo!\";\n\n    @RequestMapping(\"/\")\n    public String index() { return greeting; }\n    ...\n\n}\n~~~\n\nIf you run your test again with maven, you will get an error:\n\n`mvn test`\n\n~~~\n[ERROR] Failures: \n[ERROR]   HelloControllerTest.getHello:29 Response content\nExpected: \"Hello World!\"\n     but: was \"Hello Foo!\"\n[INFO] \n[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD FAILURE\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 6.799 s\n[INFO] Finished at: 2018-06-20T08:03:55-07:00\n[INFO] ------------------------------------------------------------------------\n[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.21.0:test (default-test) on project hello: There are test failures.\n~~~\n\nFix your code and verify it will pass testing once again.\n\n## Deploy code to OpenShift using S2I\n\ncreate a new OpenShift project to run your hello-spring application/service\n\n`oc new-project hello-spring`\n\nThe Java S2I image enables developers to automatically build, deploy and run java applications on demand, in OpenShift Container Platform, by simply specifying the location of their application source code or compiled java binaries. In many cases, these java applications are bootable “fat jars” that include an embedded version of an application server and other frameworks (spring-boot in this instance).\n\n### Getting the image stream \n\nIf your OpenShift environment doesn't already have a java image present in its catalog (as in some versions of minishift, for some reason) you can create one in the OpenShift project by importing an image stream. \n\n### Getting the image stream from an official source\n\nGo to [https://access.redhat.com/containers](https://access.redhat.com/containers)\n\n*Builder Image -\u003e Java Application -\u003e Get Latest Image -\u003e Choose your platform: Red Hat OpenShift*\n\nFrom here you can copy and paste the import command provided:\n\nexample `oc import-image my-redhat-openjdk-18/openjdk18-openshift --from=registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift —-confirm`\n\nThis will tell OpenShift how to find the Java S2I image. \n\nvalidate the name of the image stream:\n\n`oc get is`\n\n~~~\nNAME                  DOCKER REPO                                       TAGS      UPDATED\nopenjdk18-openshift   172.30.1.1:5000/hello-maven/openjdk18-openshift   latest    20 minutes ago\n~~~\n\nNow you can deploy the service from github\n\n`oc new-app https://github.com/bugbiteme/hello-spring.git --name hello --image-stream=openjdk18-openshift`\n\nA build gets created and starts compiling and creating the java container from the image. You can follow the build logs using OpenShift Web Console or OpenShift CLI command:\n\n`oc logs -f bc/hello`\n\nSome of this should look similar from when you built the application locally, including unit test status!\n\nOnce the container image has been built, it can be deployed, scaled and added to your CI/CD pipeline.\n\nIn order to access the `hello` app (e.g. from a browser), it needs to be exposed and added to the load balancer. Run the following command to add the Web UI service to the built-in HAProxy load balancer in OpenShift.\n\n~~~\noc expose svc/hello\noc get route hello\n~~~\n \nOutput:\n \n~~~\nroute \"hello\" exposed\nNAME      HOST/PORT                                  PATH      SERVICES   PORT       TERMINATION   WILDCARD\nhello     hello-hello-spring.192.168.99.100.nip.io             hello      8080-tcp                 None\n~~~\n\n### Validate \nvalidate it is running using curl (or a web browser)\n\n`curl hello-hello-spring.\u003cIP ADDRESS\u003e`\n \n Output:\n \n `Hello World!`\n \n\nTry the rest API:\n\n`curl hello-hello-spring.\u003cIP ADDRESS\u003e/api`\n \n Output:\n \n `{\"greeting\":\"Hello World!\"}`\n\n## Deploying prebuilt jar from local build\n\nIn some scenarios, you may want to compile and test the code locally and deploy the localy built jar/war, in this case, from a new OpenShift project with no application deployed, use the maven fabric8 plugin to build and deploy your application/service:\n\n`mvn fabric8:deploy`\n\nThere are directives in `pom.xml` which will tell allow for the fabric8 plugin to be used:\n\n~~~\n   \u003cproperties\u003e\n\t\t...\n\t\t\u003c!--fabric8 info--\u003e\n\t\t\u003cfabric8.version\u003e2.3.4\u003c/fabric8.version\u003e\n\t\t\u003cspring.k8s.bom.version\u003e0.2.0.RELEASE\u003c/spring.k8s.bom.version\u003e\n\t\t\u003ck8s.client.version\u003e2.4.1\u003c/k8s.client.version\u003e\n\t\t\u003cfabric8.maven.plugin.version\u003e3.5.32\u003c/fabric8.maven.plugin.version\u003e\n\t\t...\n\t\u003c/properties\u003e\n~~~\n\nand\n\n~~~\n           \u003c!--fabric8 info--\u003e\n\t\t\t\u003cplugin\u003e\n\t\t\t\t\u003cgroupId\u003eio.fabric8\u003c/groupId\u003e\n\t\t\t\t\u003cartifactId\u003efabric8-maven-plugin\u003c/artifactId\u003e\n\t\t\t\t\u003cversion\u003e${fabric8.maven.plugin.version}\u003c/version\u003e\n\t\t\t\t\u003cexecutions\u003e\n\t\t\t\t\t\u003cexecution\u003e\n\t\t\t\t\t\t\u003cgoals\u003e\n\t\t\t\t\t\t\t\u003cgoal\u003eresource\u003c/goal\u003e\n\t\t\t\t\t\t\t\u003cgoal\u003ebuild\u003c/goal\u003e\n\t\t\t\t\t\t\u003c/goals\u003e\n\t\t\t\t\t\u003c/execution\u003e\n\t\t\t\t\u003c/exec\u003e\n\t\t\t\t...\n\t\t\t\u003c/plugin\u003e\n~~~\n\n## Setting up a Jenkins pipeline (WORK IN PROGRESS)\n\nThis will work in minishift 3.3 . 3.4 won't work out of the box due to a lack of a different jenkins container image template beeing needed. For this section, if you are using 3.4, there is one additional step listed later on, if you run into issues while using 3.4.\n\nminishift 3.3 is included in Red Hat Developer Suite 2.2.0\n\nSince minishift is in a sandbox environment, it cannot be access from external sources (such as public github). The fisrt thing we need to do is set up a local git repository using [Gogs](https://gogs.io). Gogs is an open source/free version of Github that we will be deploying in an openshift project of it's own:\n\n`oc new-project gogs`\n\n~~~\noc new-app -f http://bit.ly/openshift-gogs-persistent-template \\\n    --param=HOSTNAME=gogs-gogs.$(minishift ip).nip.io \\\n    --param=GOGS_VERSION=0.9.113 \\\n    --param=SKIP_TLS_VERIFY=true \n~~~\n\n`oc get route gogs`\n\nOnce deployed:\n\n- Navigate to the gogs url (from get route)\n\n- Register a new account\n\n- From the **+** in the upper right corner, select \"New Migration\"\n\n- Clone this repo (\"Clone Address\"): \n\n  - `https://github.com/bugbiteme/hello-spring.git`\n\n- Repository Name: \"hello-spring\"\n\nNow create a new subdirectory for your new repo\n\n~~~\nmkdir gogs\ncd gogs\ngit clone http://gogs-gogs.\u003cIP-ADDRESS\u003e.nip.io/\u003cPROFILE\u003e/hello-spring.git \ncd hello-spring\n~~~\n\nBuild and run code locally to validate (requires maven to build)\n\n~~~\nmvn spring-boot:run \ncurl localhost:8080/api\n{\"greeting\":\"Hello World!\"}\n~~~\n\nctrl-c to kill app\n\nAny changes you commit will go to your own repo on gogs\n\nCreate a new version of hello-spring project\n\n`oc new-project hello-spring-pipeline`\n\nDeploy the app from the gogs repo:\n\n~~~\noc new-app http://gogs-gogs.\u003cIP-ADDRESS\u003e.nip.io/\u003cPROFILE\u003e/hello-spring.git --name hello --image-stream=redhat-openjdk18-openshift:1.2\n~~~\n\n`oc expose svc/hello`\n\n`oc get route hello`\n\n~~~\nNAME      HOST/PORT                                    PATH      SERVICES   PORT       TERMINATION   WILDCARD\nhello     hello-hello-pipeline.192.168.99.100.nip.io             hello      8080-tcp                 None\n~~~\n\nVerify the application is running correctly and that the route is accessible:\n\nex. `curl hello-hello-spring-pipeline.192.168.99.100.nip.io/api`\n\n`{\"greeting\":\"Hello World!\"}`\n\n### Here is where we actually create an OpenShift pipeline\n\nOpenShift Pipelines enable creating deployment pipelines using the Jenkinsfile format.\n\nOpenShift automates deployments using deployment triggers that react to changes to the container image or configuration. Since you want to control the deployments just from the pipeline (and not configuration changes), remove the \"hello\" application deploy triggers so that building a new \"hello\" container image won’t automatically result in a new deployment. This will allow the pipeline to decide when a deployment should occur.\n\nRemove the hello deployment triggers:\n\n\n~~~\noc  set triggers dc/hello --manual\n\ndeploymentconfig \"hello\" updated\n~~~\n\nDeploy a Jenkins server using the provided template and container image that comes out-of-the-box with OpenShift:\n\n~~~\noc new-app jenkins-ephemeral\noc logs -f dc/jenkins\n\n--\u003e Scaling jenkins-2-centos7-1 to 1\n--\u003e Success\n~~~\n\n*Note: it may take a few minutes before the Jenkens server is accessible.*\n\n*Note: If this doesn't work, you may be on minishift 3.4... I have a workaround for this!*\n\n*Note: If you get the following error message*\n\n~~~\nerror: Errors occurred while determining argument types:\n\njenkins-ephemeral as a local directory pointing to a Git repository:  stat jenkins-ephemeral: no such file or directory\n\nErrors occurred during resource creation:\nerror: no match for \"jenkins-ephemeral\"\n...\n~~~\n\n*Run the following from the hello-spring project directory*\n\n~~~\noc create -f images-templates/jenkins-ephemeral-template.json\n\ntemplate \"jenkins-ephemeral\" created\n\noc new-app jenkins-ephemeral\n~~~\n\nThis imports the correct image template of Jenkens needed for this tutorial.\n\nEnsure the Jenkens container/server is up and running before you proceed by logging into it.\n\nTake a look at the Jenkinsfile included with this cloned project\n\n`cat pipeline/Jenkinsfile`\n\n~~~\npipeline {\n  agent {\n      label 'maven'\n  }\n  stages {\n    stage('Build JAR') {\n      steps {\n        sh \"mvn -B -DskipTests clean package\"\n        stash name:\"jar\", includes:\"target/hello-0.0.1-SNAPSHOT.jar\"\n      }\n    }\n    stage('Test') {\n      steps {\n        sh 'mvn test'\n      }\n      post {\n        always {\n          junit 'target/surefire-reports/*.xml'\n        }\n      }\n    }\n    stage('Build Image') {\n      steps {\n        unstash name:\"jar\"\n        script {\n          openshift.withCluster() {\n            openshift.startBuild(\"hello\", \"--from-file=target/hello-0.0.1-SNAPSHOT.jar\", \"--wait\")\n          }\n        }\n      }\n    }\n    stage('Deploy') {\n      steps {\n        script {\n          openshift.withCluster() {\n\t\t\tdef dc = openshift.selector(\"dc\", \"hello\")\n\t\t\tdc.rollout().latest()\n            dc.rollout().status()\n          }\n        }\n      }\n    }\n  }\n}\n~~~\n\nThis pipeline has three stages:\n\n- Build JAR: to build jar file using Maven\n- Test: Run junit testing on build\n- Build Image: to build a container image (\"hello\") from the JAR archive using OpenShift S2I\n- Deploy: to deploy the \"hello\" container image in the current project\n\nThe next steps will deploy the Jenkinsfile to the build and deploy pipeline configuration for this project:\n\nAfter Jenkins is deployed and is running (verify in web console), create a deployment pipeline by running the following command within the hello-pipeline folder:\n\noc new-app . --name=hello-pipeline --strategy=pipeline\n\n~~~\n    * A pipeline build using source code from http://gogs-gogs.192.168.99.100.nip.io/leon/hello-spring.git#master will be created\n      * Use 'start-build' to trigger a new build\n\n--\u003e Creating resources ...\n    buildconfig \"hello-pipeline\" created\n--\u003e Success\n    Build scheduled, use 'oc logs -f bc/hello-pipeline' to track its progress.\n    Run 'oc status' to view your app.\n~~~\n\nOnce complete, the pipeline for the hello app has been configured to build and deploy code from the gogs/git repository\n\nYou can view and manaually run the pipeline from the hello-spring project:\n\nBuilds -\u003e Pipelines\n\nNote: If you want to make addtions/edits to the pipeline, simply edit *Jenkinsfile* contained in this project and push it to the gogs repo.\n\n### Automatically Run the Pipeline on Every Code Change/Commit/Push\n\nConfigure the pipeline you just created to run every time you commit/push a code change the git repo.\n\nManually triggering the deployment pipeline to run is useful but the real goal is to be able to build and deploy every change in code or configuration at least to lower environments (e.g. dev and test) and ideally all the way to production with some manual approvals in-place.\n\nIn order to automate triggering the pipeline, you can define a webhook on your Git repository to notify OpenShift on every commit that is made to the Git repository and trigger a pipeline execution.\n\nYou can get see the webhook links for your hello-pipeline using the describe command.\n\n~~~\noc describe bc hello-pipeline\n\n\nName:\t\thello-pipeline\nNamespace:\thello-spring\nCreated:\t22 minutes ago\nLabels:\t\tapp=hello-pipeline\nAnnotations:\topenshift.io/generated-by=OpenShiftNewApp\nLatest Version:\t2\n\nStrategy:\t\tJenkinsPipeline\nURL:\t\t\thttp://gogs-gogs.192.168.99.100.nip.io/leon/hello-spring.git\nRef:\t\t\tmaster\nJenkinsfile path:\tpipeline/Jenkinsfile\n\nBuild Run Policy:\tSerial\nTriggered by:\t\tConfig\nWebhook GitHub:\n\tURL:\thttps://192.168.99.100:8443/apis/build.openshift.io/v1/namespaces/hello-spring/buildconfigs/hello-pipeline/webhooks/Gwl9kmgTzyw1LC1pnQME/github\nWebhook Generic:\n\tURL:\t\thttps://192.168.99.100:8443/apis/build.openshift.io/v1/namespaces/hello-spring/buildconfigs/hello-pipeline/webhooks/nzz7rtxyANqUv2ekIgzo/generic\n\tAllowEnv:\tfalse\n\n~~~\n\nYou can also see the webhooks in the OpenShift Web Console by going to Build » Pipelines, click on the pipeline and go to the Configurations tab.\n\nCopy the “Generic” web hook and go into the Gogs *hello-spring* project and click *settings*\n\n\nOn the left menu, click *Webhooks* and then the *Add Webhook* button and then select *Gogs*.\n\nCreate a webhook with the following details:\n\n* Payload URL: paste the \"Generic\" webhook url you copied from the hello-pipeline project\n* Content type: application/json\n\n\nClick on *Add Webhook*.\n\nOnce the webook has been added, the pipeline will run each time you push code to the git repo!\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugbiteme%2Fhello-spring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbugbiteme%2Fhello-spring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbugbiteme%2Fhello-spring/lists"}