MicroservicesFoundations_CertificateOfCompletion
Tag Archives: devops
Containerize Spring Boot App with Docker
- Add docker maven plugin to pom.xml
<plugin> <groupId>com.spotify</groupId> <artifactId>dockerfile-maven-plugin</artifactId> <version>1.4.0</version> <configuration> <repository>${docker.image.prefix}/${project.artifactId}</repository> <buildArgs> <JAR_FILE>target/${project.build.finalName}.jar</JAR_FILE> </buildArgs> </configuration> </plugin>
- Create Dockerfile at the root of the project
FROM openjdk:8-jdk-alpine VOLUME /tmp ARG JAR_FILE COPY ${JAR_FILE} app.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
- Build docker image
mvn clean install dockerfile:build
- Login to docker hub and push the image to docker hub (Optional Step)
docker login -u <username>
mvn dockerfile:push
- Verify the image is built and available
docker images
- Run Spring Boot App from docker
docker run –rm -d –restart -p 8080:8080 ${docker.image.prefix}/${project.artifactId}
Deploy Flask Application to Apache Webserver
- Install mod_wsgi
sudo apt-get install libapache2-mod-wsgi
- Enable wsgi module
sudo a2enmod wsgi
sudo systemctl restart apache2
- Create .wsgi file with below content
from yourapp import app as application
- Configure a new site in Apache2
<VirtualHost 127.0.0.1:80> ServerName site.api WSGIDaemonProcess site user=www-data group=www-data threads=5 home=/var/www/site WSGIScriptAlias / /var/www/site/app.wsgi <Directory /var/www/site> WSGIProcessGroup site WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> WSGIPassAuthorization On </VirtualHost>
- Enable the site and reload Apache2