Motivation needs to be raised

Hello everyone! Sometimes it happens that studying is very difficult and motivation needs to be boosted, and generics and lambda expressions have completely sucked out your strength. That's why, a couple of days ago, while stuck in a mobile game, I suddenly caught myself thinking that I could make my life and that of several hundred other people easier. That's why it was decided to make my own app

Backstory. A couple of months ago I came across a completely pointless mobile game in which you, as a player, hit a tree, get items that you put on your hero, level up and spend peaches (currency) on it. But the game is as pointless as it is entertaining (and I'm not describing all aspects of the game now). So, playing day after day for an hour a day, I caught myself thinking that I wanted to predict how much time I would spend on lvlup and how quickly I would “dress” in cool armor.

Having started researching what I could do and how to implement it quickly, at first I simply made a console application that did calculations and wrote it all to the console.

Even a child could handle this, I thought. Something more complex was needed, after all, I had managed to tighten up the base in these two months. So I started implementing the desktop.

A normal cycle, nothing special, and output to the console.

A normal cycle, nothing special, and output to the console.

After googling and smoking bamboo, I realized that I need to connect the Java library Swing. Then an hour or two in the documentation and I already write the following:

  There's nothing special here, just set up the window, add buttons, text, etc.

There's nothing special here, just set up the window, add buttons, text, etc.

Next, we take values ​​from the fields, check them for errors and make calculations.

Don't forget to handle errors, the first project work taught us a lot)

We launch all this and voila, we have a whole desktop application in which we can count and it even works.

But even this was not enough for me, because most users of this game will not run the exe file on the computer and count peaches. A convenient solution was needed, convenient for all mobile users. Therefore, it was decided to make a web application, using all the accumulated experience.

Again Google, again bamboo and here is the solution. Spring. Yes, yes, don't be surprised. So we go to spring initializr, configure what we need (Spring web and Thymeleaf template engine) and click Generate.

Then YouTube, Google, Spring documentation and StackOverflow to figure out how and what to cheat here. As a result, we got the following logic – on the server we do calculations, work with two requests: the first get, when loading the main page and post /calculate for calculations, on the front we have html and css, with a template engine that can transfer data from the fields.

We add attributes for the get request to our model.

And we calculate in post /calculate.

Next, I set up a template (and remembered html) so that all the values ​​that the user enters are transferred to the backend, calculations are performed and the result is returned.

As a result, we have the following result

Great, cool, I'm even proud of myself, but there is one BUT. Only I can use this, because it is deployed locally, on my computer. To do this, all this needs to be deployed on the server. And how to deploy a jar on the server? That's right, Docker. And here I am a complete layman, I did not know how, nor why, nor why all this is needed. So then half a day of googling, settings, documentation and videos to figure it out. I will omit many details, I will go through the main ones. I created a Dockerfile in my project, installed Docker Desktop and launched the container.

Dockerfile

Everything works, the container starts, you can go to the application. Now you need to run it on the server (fortunately, my father already has Ubuntu configured with nginx on board) and configure gitlab so that when pushing to the main branch, automatic assembly and deployment occurs.

Having previously configured nginx for my project, specifying all ports, hosts and other details, I proceeded to configure CI/CD

Here I will also omit many nuances, how I fought with the jar being pre-built, reverse proxy, etc. I will show how the yaml file is implemented in the project.

In it I indicated that we are deploying all this stuff, collecting the jar file, building the docker, deleting the image if it already exists and if we have a running one, we stop it. Well, all this is for the main branch.

Everything works as it should and with each push, I see the launch of jobs

And the web application is now available at

To sum it up: with such a trivial idea as making a basic, simple calculator, I encountered a lot of frameworks, nuances, ideas and options for their implementation. I gained some experience in Java, Spring, Docker, Gitlab CI/CD, worked with git and a lot more. I want to say – don't be afraid to do something, even if it doesn't work out and take on such micro-pet projects to gain experience 🙂

And yes, I don’t claim that I did everything right and didn’t make mistakes, I’m just learning like all of us.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *