Deploy Spring Boot Application with Ease Using Railway.app

Deploy Spring Boot Application with Ease Using Railway.app

Deploying Your Spring Boot Application with Ease Using Railway.app: A Step-by-Step Guide.

With the recent demise of Heroku.com Free tier, as a Spring Boot application developer finding a similar platform has been daunting task. But railway.app has made life much easier for early-stage development or side hustle projects.

In this article, we explore a new Platform named railway.app which helps with the deployment of code to cloud infrastructure without the need to worry about the underlying infrastructure. We as a developer need to take our code, and railway.app would do all the dirty work for us. Right from start via their in-built templates, launch, scale to security all is taken care of. In this blog post, we will how quickly we can bootstrap Spring Boot application into a development(PROD) environment for a side hustle or LIVE project.

Pre-requisite

  • A railway.app account.

  • GitHub Account

  • Java Spring Boot Apps (We will bootstrap one quickly here.)

Bootstrap Spring Boot Web Application

Visit https://start.spring.io/ Just change the Build tool to Maven and add Spring Web dependency.

Rest keep as default and generate the artifact. We are going with JDK17 and Spring Boot v3, won't matter in terms of how this article pans out. Just adding a basic web controller, to download Spring Boot Project to hit the HTTP endpoint once deployed on railway.app

We will test locally once, to see if we get an HTTP response on the exposed Controller.

The next step involves pushing our locally written code to Github. We are pushing to this repository on GitHub. Post push it's time to deploy our code to railway.app

Deploying Spring Boot to railway.app

  1. Login to railway.app account, the best is to do it via github.com

  2. By default, it will allocate you to a Starter plan of usage which gives 500 execution hours or 5$ credit. It will also take you to the dashboard https://railway.app/dashboard

  3. We will now click on Create a New Project. It will list a lot of options to deploy custom, from templates, or use the services out of the box.

  4. We will go ahead with Deploy from GitHub repo, and select Configure GitHub App and select only the required repository. In this case virendra-oswal-blogs

  5. Once selected, again it will take to New Project, and then Deploy from GitHub repo and select the previously selected Repo shown in UI on the next page as below.

  6. We are selecting our Blog repo as above.

  7. Alright, that's it. Just click Deploy Now as below. (You can set up environment variables if needed in this step or late via settings)

  8. As soon as you trigger, deployment should start and the railway.app is smart enough to know which build tool and project is being built based on Nixpacks it uses.

    If you don't have mono-repo, you can jump directly to step 13.

  9. In our case, we are using mono-repo (I wanted to demo this purposefully), so our deployment fails as below

  10. In the mono-repo case, we will update settings to use the Root path as spring-boot-railway-app. As our repo hosts multiple projects across different blogs

  11. Update Root Directory as below to your folder which hosts pom.xml for your spring boot application.

    If your repository only hosts a Single Spring Boot app, no need to change Root Directory which defaults to /

  12. As soon as we update, deployment will be triggered. As we can new deployment was successful.

  13. You can click on Successful deployment to view Details, Build Logs and Deploy (Startup) logs as below

  14. Now to access the HTTP endpoint, we must Generate a Domain from the settings of the application as below (You can set up a custom domain too :) )

  15. Once generated, you can your /greet URI as below

  16. Voila, our Spring boot is LIVE within 5 minutes. With CI/CD already in place with the below trigger already set on a required branch. (master branch in this case)

Resources


Thank you for reading, If you have reached it so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback and suggestions!

I would love to connect with you on Twitter | LinkedIn

Did you find this article valuable?

Support Virendra Oswal's Blog by becoming a sponsor. Any amount is appreciated!