TechBrain Review Newsletter 2024-07/08
Przemys?aw Chmielecki, PhD
Passionate Cloud Architect helping in cloud migration and DevSecOps transformation | 5x University Graduate | 5x lang ???????????????????? | 5x? (Azure, AWS, GCP, Alibaba, Oracle) | K8S | Python | .NET | PM | Stoicism
Hey there ??
?? Welcome to the TechBrain Review newsletter, Issue No. 7-8, July-August 2024! ??
This time a bit late due to vacation period, but I would like to present doubled package of goods:
#Technology
Use containers technology to develop and test locally
Docker containers provide an isolated environment for developing and testing applications (Java/Python/.NET/other), ensuring consistency across different environments. Here’s a guide to effectively use tools within Docker for sandbox development and testing.
1. Install Docker
2. Create simple Java app
In this example I'll use Java 21 and Maven.
Java servlet
package com.example;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>Hello, World! (Java 21)</h1>");
out.println("</body></html>");
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="https://maven.apache.org/POM/4.0.0"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>hello-world-java21</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>hello-world-java21</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
</plugin>
</plugins>
</build>
</project>
3. Create Dockerfile
FROM tomcat:11.0-jdk21
# Remove default Tomcat applications
RUN rm -rf /usr/local/tomcat/webapps/*
# Copy our WAR file to the webapps directory
COPY target/hello-world-java21.war /usr/local/tomcat/webapps/ROOT.war
# Expose the default Tomcat port
EXPOSE 8080
# Start Tomcat
CMD ["catalina.sh", "run"]
4. Build Java app
mvn clean package
5. Build the Docker Image
Navigate to the directory containing your Dockerfile and run the following command:
docker build -t hello-world-java21 .
6. Run the container
Once the image is built, you can run it using:
docker run -d -p 8080:8080 --name hello-world-java21-container hello-world-java21
7. Integrating with CI/CD
Docker integrates seamlessly with CI/CD pipelines, allowing for automated testing and deployment. In your pipeline configuration, add steps to build and run your Docker image.
8. Sandbox Development
Using Docker, you can quickly spin up containers for different versions of your application, test new features, and share your development environment with your team, ensuring everyone works in identical conditions.
9. Testing with Docker
Containers are perfect for testing. You can run unit tests, integration tests, and even performance tests within containers. This ensures that your tests run in a consistent environment, eliminating the "it works on my machine" problem.
Conclusion
Docker containers are powerful tools for Java development and testing. They provide isolated environments, ensuring consistency across different stages of the development lifecycle. By using Docker, you can streamline your development process, facilitate collaboration, and enhance the reliability of your Java applications.
领英推荐
#Management
Pomodoro technique
The Pomodoro Technique, developed by Francesco Cirillo in the late 1980s, offers a simple yet powerful method to enhance focus and productivity. Named after the tomato-shaped kitchen timer Cirillo used, the Pomodoro Technique breaks work into manageable intervals, traditionally 25 minutes, separated by short breaks.
How It Works
Benefits
Tips for Success
The Pomodoro Technique’s blend of focused work and regular breaks is a straightforward yet transformative method to boost efficiency. Whether tackling complex projects or managing daily chores, this technique helps maintain a balanced approach to productivity, making it an invaluable tool for anyone looking to master their time.
#(Self)Development
RESTful vacation
Understanding the importance of rest and vacation is crucial for fostering self-development and enhancing the learning curve. Regular rest and vacation periods provide essential mental and physical rejuvenation, preventing burnout and maintaining high levels of productivity and creativity. Breaks from routine work environments allow individuals to reset their minds, reducing stress and increasing overall well-being. This downtime is vital for cognitive processes, as it enables the brain to consolidate information, improve memory retention, and facilitate problem-solving abilities.
Vacations also offer opportunities for new experiences and perspectives, which can stimulate creativity and innovation. Engaging in different activities and environments during vacations can inspire fresh ideas and insights that can be applied to professional and personal life. Furthermore, rest and relaxation enhance emotional resilience, allowing individuals to handle stress and challenges more effectively upon returning to work.
Overall, taking time off from work fosters a balanced lifestyle, contributing to long-term professional success and personal fulfillment. By prioritizing rest and vacations, individuals can improve their learning curve, stay motivated, and achieve continuous self-development, ultimately leading to enhanced performance and satisfaction in their roles.
#Misc
Books that influenced me the most. Part 4
Marcus Aurelius' book, "Meditations," is a series of personal writings by the Roman Emperor, reflecting on Stoic philosophy and guidance for personal growth and ethical conduct. Written during his military campaigns between 170 and 180 AD, it provides a profound insight into the mind of a ruler grappling with the responsibilities of leadership while striving for personal virtue. The work is divided into twelve books, each offering thoughts and aphorisms on topics such as self-discipline, rationality, and the nature of the human condition. "Meditations" is not just a historical document but a timeless manual for inner peace and resilience.
Three key takeaways for modern users are:
Thanks for reading this newsletter! I hope it was useful and you enjoyed it ?? I'm going to share more content related to Multi-Cloud Architecture (Azure, AWS, GCP, Alibaba, and Oracle), DevSecOps transformation, Productivity tips, and Education (5x University graduate in IT, Philosophy, Cognitive Science, Sociology and Education; getting more fluency in 5x languages ????????????????????).
Dr Przemys?aw Chmielecki
Rendez-vous dans le prochain épisode! Merci, très chers, d'être ici! ??
I encourage you to subscribe to this newsletter ?? and stay tuned for new technical and productivity content ??