CI/CD - Integrating and Deploying Continuously


Deploy and Integrate
We build an API, it's working well in our machine but we want to host the app in another machine that will serve the API to the outside world, what do we need? what comes to our head is Continuous Integration / Continuous Deployment.
But first and foremost, what tools do we need? Let's take as an example a Java Spring App and how can we do this in the simplest way to better understand how the Continuous Integrations/Deployment works:
1 - We need to compile and build the app with a building tool (Maven, in this example).
mvn clean package
2 - Pack the final result as Docker container
docker buildx build --platform linux/amd64 -t appname .
In my case i am doing the build in a Mac OS that's why i am targeting the build for a Linux system.
But how the build is going to be done? well, we need a set of instructions, that instructions by default reside in a Dockerfile file
FROM eclipse-temurin:22-jdk-alpine
WORKDIR /app
COPY target/*.jar /app/application.jar
ENTRYPOINT ["java","-Dspring.profiles.active=dev","-jar","/app/application.jar"]
- Specify the base image used
- Set the working directory, all the subsequent docker commands will be executed in this directory
- Copy the content generated by the maven command into a directory inside the container
- Defines the command that will be executed when the container starts
3 - Send the container to a Registry to be used by others
Since we do not have a server to share docker images, we need to setup a registry in our machine (this only needs to be executed once, then we can stop/start this container when we need to share images):
docker run -d -p 5005:5000 --name registry registry:2
Tag the image:
docker tag appname localhost:5005/appname:latest
Push it to the Registry:
docker push localhost:5005/appname:latest
4 - Call the Registry in the other machine and run it as a Docker Container
sudo docker run -d --restart unless-stopped -p 8811:8811 --name appname 192.168.1.233:5005/appname:latest
What we did in all these steps was "Integration" and "Deployment", we are missing the "Continuous" part
Automate the "Integration" and "Deploy" to be ... Continuous ...
The nest article we will talk about how to how to automate all of this ...
Subscribe to my newsletter
Read articles from GrepTips directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by