Skip to main content

Posts

Building Docker Image with Maven

 Building Docker Image with Maven You are a DevOps Engineer working for ABC Infotech. A client has requested you to build a Docker image using Maven plugin, so that when you package your Maven project. Docker image will be built, and the generated artifacts will be deployed in local git repository  1. Create a Maven java project using CLI with the following configurations - groupId=javaApp  - artifactId maven-docker-image  2. Replace the 'Hello World!' message in the 'App.java' file with 'Hurray! You have successfully built a docker image using Maven' 3. Configure your 'pom.xml' to deploy the generated artifacts in the local git repository to build a docker image 4. The project should be deployed in the local repositary with the following details: - id = maven.repo - name = Maven Artifacts - URL = file:///home/labuser/Desktop/Remote/mavenArtifacts 5. The name of the jar file, repository name af the image should be same as the project artifactId...

Create & Dockerize a Flask app with Redis

  Create & Dockerize a Flask app with Redis For this project we would create everything from scratch. Section 1 : We would create the Flask app Section 2 : We would deploy the app as service, along with redis using docker and docker-compose. Section 1 Creating a flask app that returns the count number of times the page was visited. Create a  requirements.txt file, and paste the following dependency name Flask redis Import dependencies using pip install --no-cache-dir -r requirements.txt Create a  app.py file  from flask import Flask from redis import Redis app = Flask(__name__) redis = Redis(host='db_service', port=6379) @app.route('/') def hello():     visit_count = redis.incr('visit_count')     return f"Hello, this page has been visited {visit_count} times." if __name__ == '__main__':     app.run(host='0.0.0.0') We can test the app locally for this we need to: Install virtualenv if it's not already installed: sudo apt-get up...

Springboot e-commerce

 Springboot e-commerce git:  https://github.com/HazraSoham/WingsT4Springboot User.java - renamed to EcomUser.java Below is the code snippet how EcomUser.java should be, add constructor and getters and setters also. Have many-to-many with Role Have one-to-one with Cart Have one-to-many with Product @Entity public class EcomUser {           @Id @GeneratedValue (strategy = GenerationType. IDENTITY ) private Integer ecomUserId ; private String username ; private String password ; @ManyToMany (fetch = FetchType. EAGER , cascade = CascadeType. ALL ) @JoinTable (name = "UserRole" , joinColumns = @JoinColumn (name = "ecomUserId" ), inverseJoinColumns = @JoinColumn (name = "roleId" )) private Set<Role> roles ; Role.java - shown below the class, add getter and setters also Have many-to-many with User @Entity public class Role { @Id @GeneratedValue (strategy = GenerationType. IDENTITY ) private Integer roleId ; private S...

Restaurant API using SpringBoot

 Restaurant API using Spring Boot github repo:  https://github.com/HazraSoham/Kickoff-Springboot-ResturantAPI.git Controller - Add  @RestController  annotation the class      @Autowired private RestaurantService restaurantService ; //to create a restaurant @PostMapping ( "/restaurant/add" ) public ResponseEntity<Object> postRestaurant( @RequestBody Restaurant restaurant ){ return restaurantService .postRestaurant( restaurant ); } //to get a restaurant by id @GetMapping ( "/restaurant/get/{id}" ) public ResponseEntity<Object>getRestaurantById( @PathVariable int id ){ return restaurantService .getRestaurantById( id ); } //to get restaurants which are equal to or greater than the given rating @GetMapping ( "/restaurant/ratings" ) public ResponseEntity<Stream<Restaurant>> getGreaterRating( @RequestParam ( "rating" ) Double rating ){ return r...

Build Flask image using docker & docker-compose

 Build Flask Image using docker & docker-compose 1. Create a Dockerfile to build Flask image with Flask application, 'requirements.txt' and expose it in port 5000. 2. Create a 'docker-compose.json' file to create two services named 'python_web_app' and 'db_service' 3. The 'python_web_app' service  should be built from Dockerfile and specify the port as 5000 4. the 'db_service' should be built from image 'redis:alpine' 5. Add a volume to the 'python_web_app' service that mounts the current directory to the working directory inside the container and set the flask envireonment in debug mode. 6. Visit 'http:localhost:5000" to check weather the Flask application is running fine. The container name of 'python_web_app' service should be 'web_container' and container name of 'db_service' should be 'db_container' Here are the instructions for each of the tasks mentioned: Create a file na...