In this tutorial, we will see how to deploy a Spring Boot Kotlin application with Docker and the ScaleDynamics Platform.
Spring Boot is a Java-based web application framework that is designed to build simple, stand-alone, production-grade applications. It is built on top of the conventional Spring framework. In Spring Boot everything is auto-configured. It also support Kotlin, which in our case is the language used in the application we will deploy.
Docker is a containerization platform that allows you to run applications in a container. It is used to build and run applications on the cloud.
Our goal will be to clone the Spring Petclinic sample application, use the Docker app to run it locally and then deploy it on the ScaleDynamics Platform.
To follow along, you will need:
- Docker on your system to run the application locally.
- Node.js and yarn / npm installed. You can go here to download the latest version of Node.js and npm.
- Git installed.
Setup the project
The project we will clone is the Spring Petclinic sample appication in Kotlin. You can find the repository here.
Now let's get the project by running the following command:
git clone https://github.com/spring-petclinic/spring-petclinic-kotlin.git
The project is now ready, let's run it locally with Docker !
Run the application locally
First of all, you need to launch the Docker app on your system.
Build the image
Before being able to run the application, we need to build the image. The project has already a ready to use Dockerfile, so we just need to run the following command inside the project directory:
# the `--tag` option is used to name the image. docker build . --tag spring-petclinic-kotlin
I got some error on a Mac M1 chip:
If you encountered the same issue, you can modify the Dockerfile like this:
FROM gradle:7.4.1 AS build COPY --chown=gradle:gradle . /home/gradle/src WORKDIR /home/gradle/src RUN gradle build FROM openjdk:8-jre-slim EXPOSE 8080 COPY --from=build /home/gradle/src/build/libs/spring-petclinic-kotlin-2.6.2.jar /app/ RUN bash -c 'touch /app/spring-petclinic-kotlin-2.6.2.jar' ENTRYPOINT ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Djava.security.egd=file:/dev/./urandom","-jar","/app/spring-petclinic-kotlin-2.6.2.jar"]
Those modifications include:
- changing the gradle image
- changing the name of the jar built by gradle
Now the image is ready to be run.
Run the image
You can run this docker image using the docker application directly or with the command:
docker run -p 8080:8080 spring-petclinic-kotlin
The application is now running on localhost:8080, you can now access it in your browser. It should look like:
Let's deploy it !
Account creation and resource selection
To deploy this server on ScaleDynamics's cloud, you need an account and create an environment with a resource for it. The cloud resource provides virtual CPU and storage capacities used to execute the app. In this tutorial we will use a free shared resource available on ScaleDynamics’s cloud. These are the best one for testing. In this tutorial we will see later how you can upgrade to a dedicated production resource on the public cloud provider and region of your choice.
If you don't have an account, feel free to create one here (it's free and no credit card are required). Once your account is created, sign in.
Let's create a project and an environment on the ScaleDynamics's console. Select your organization, create a new project, then create a new environment. Now we need to choose what kind of service we need for our deployment. There are four types:
- managed HTTP docker
- managed Node.js server
- managed Node.js module
- static assets hosting
For our application, we use docker to run it. Let's pick the managed HTTP docker. You can learn more on the other types in the ScaleDynamics documentation.
Deploy the application
The environment has the resource needed, let's deploy on it.
Log into your account and select your organization via the prompt:
npx warp login
Finally, we can run the deployment command:
npx warp deploy
You can see that the Dockerfile was detected by the SDK. You can just follow the prompt, select the project you created, then the environment. The prompt will also ask you for a hostname, you can leave it blank for a random name or use the one you want. Finally, you can select a host. and then it will do it's magic.
This command will dump something like this:
You can now open your browser and go to the URL and TADA ! Your application is live !
This was a simple example of deploying a simple application with docker on the ScaleDynamics Platform. You can pretty much go with any other language, framework or library you want to use.
If you are interested in CI/CD, there is a tutorial on how to implement it here.
Top comments (1)
Thanks for a great tutorial !!!
Anyway, I've found some issues during building a docker image because a project version in Github repository was changed to 2.7.0, therefore I fixed a Dockerfile as below.