I did something similar to demonstrate, modestly, technical compositions [Github Pssilva: 2017] (work in progress). But I adapted to contribute to the community and thus try to answer the questions above.
What the flow would look like?
Workflow is usually a subjective thing, so I will describe a generic flow that I used in my environment:
1. Docker environment in Virtualbox:
Assuming you already have a VM with Ubuntu 16.04.2 LTS (Xenial Xerus)16.04.2 LTS (Xenial Xeru)
with GIT, and the SSH server installed and properly configured. Then, we can install Docker.
$ssh [SEU_USER]@[IP_HOST] -p 22
$sudo su
#echo "deb [arch=amd64] https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main" > /etc/apt/sources.list.d/docker.list
#apt-cache policy docker-engine
#apt-get update
#apt-get install linux-image-generic-lts-$(lsb_release -cs)
#reboot
$ssh [SEU_USER]@[IP_HOST] -p 22
$sudo apt-get update
$sudo apt-get install docker-engine
$sudo service docker start
$sudo service docker status
$sudo gpasswd -a $(whoami) docker
$exit
$ssh [SEU_USER]@[IP_HOST] -p 22
2. Testing the Docker: Helo Word
.
$ssh [SEU_USER]@[IP_HOST] -p 22
$docker run oskarhane/hello echo "Hello, let me out of here"
$docker ps -a
Ready, after testing we can clean the containers and images.
$docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
$docker rmi $(docker images -a -q)
3. Create the Spring Boot project
3.1 Installing plugins in the IDE
In my case I use Eclipse IDE Luna Service Release 2 (4.4.2), Eclipse Java EE IDE for Web Developers.
And the main plugins I use are:
- The Spring Tool (STS)
- m2e - Maven Integration for Eclipse
- Gradle IDE & Enide Gradle for Eclipse in one Operation.
3.2 Creating the project:
For this test here, using the STS plugin, create a project like this one from the image:
Important, see Location: /Users/[SEU_USER]/Projects/microservicesSpringProject
That’s where we clone the repository.
3.3 Edit the file: /microservicesSpringProject/src/main/java/br/com/microservicesSpringProject/Microservicesspringprojectapplication.java
Leaving as low as:
package br.com.microservicesSpringProject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class MicroservicesSpringProjectApplication {
@RequestMapping("/")
public String home() {
return "My Microserver: Stackoverflow";
}
public static void main(String[] args) {
SpringApplication.run(MicroservicesSpringProjectApplication.class, args);
}
}
3.4 Build Application:
$cd /Users/[SEU_USER]/projects/microservicesSpringProject
$mvn package && java -jar target/microservicesSpringProject-0.0.1-SNAPSHOT.jar
Just to test the application, access the link: localhost:8080
.
IMPORTANT: the file: /Users/[SEU_USER]/projects/microservicesSpringProject/target/microservicesSpringProject-0.0.1-SNAPSHOT.jar
4. Creating the project repository
4.1 In Virtual Machine, assuming you have already configured your git server [Git: 2017 - b]
$ssh [SEU_USER]@[IP_HOST] -p 22
$mkdir -p /opt/microservicesSpringProject.git
$cd /opt/microservicesSpringProject.git
$git --bare init --shared=[DEV_GROUP_PERMISSION]
$chmod 0777 -Rf /opt/microservicesSpringProject.git
$chown [SEU_USER] -Rf /opt/microservicesSpringProject.git
4.2 On Host machine, physical machine.
$cd /Users/[SEU_USER]/projects/microservicesSpringProject
$chmod 0777 /Users/[SEU_USER]/projects/microservicesSpringProject
$git init
$echo "#[NOME_PROJETO]" > README.md
$git add .
$git commit -m 'initial commit'
$git remote add origin ssh://[SEU_USER]@[IP_SERVER]:22/opt/microservicesSpringProject.git
$git push origin master
5. Create your own Docker image: Create the Dockerfile file
Here we can answer: How would the Dockerfiles look?.
The same Dockerfile file can be reused to generate multiple images.
The dockerfile file [Docker: 2017 - the] can be done in several ways, the following format met me [Docker: 2017 - b]:
# escape=\ (backslash)
# My Microservices
#
# VERSION 0.0.1
# AUTHOR Paulo Sergio da Silva
# EMAIL [email protected]
FROM ubuntu
VOLUME /tmp
LABEL Description="This image is used to build a application whith Architecture Microservices." Vendor="PSSILVA Products" Version="1.0"
RUN apt-get update && apt-get install -y inotify-tools apache2 openssh-server git
RUN apt-get clean all
RUN apt-get install -y default-jre
RUN apt-get install -y default-jdk
RUN apt-get install -y openjdk-8-jre
RUN apt-get install -y openjdk-8-jdk
RUN apt-get install -y software-properties-common && add-apt-repository ppa:maxmind/ppa && apt-get update && apt-get -y install libmaxminddb0 libmaxminddb-dev mmdb-bin
RUN apt-get clean all
RUN apt-get update
CMD ["mkdir","-p","/opt/spring-1.5.1.RELEASE"]
#COPY spring-1.5.1.RELEASE/* /opt/spring-1.5.1.RELEASE/
#CMD ["ln","-s","./opt/spring-1.5.1.RELEASE/bash/spring","/etc/bash_completion.d/spring"]
#CMD ["ln","-s","./opt/spring-1.5.1.RELEASE/zsh/_spring","/usr/local/share/zsh/site-functions/_spring"]
ADD microservicesSpringProject-0.0.1-SNAPSHOT.jar /root/microservicesSpringProject-0.0.1-SNAPSHOT.jar
RUN sh -c 'touch /root/microservicesSpringProject-0.0.1-SNAPSHOT.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /root/microservicesSpringProject-0.0.1-SNAPSHOT.jar" ]
#CMD ["java","-jar","/root/microservicesSpringProject-0.0.1-SNAPSHOT.jar"]
For versioning only, create the Dockerfile file in the /Users/[SEU_USER]/Projects/Microservices
$mkdir -p /Users/[SEU_USER]/projects/microservicesSpringProject/docker-image/spring-1.5.1.RELEASE
$cd /Users/[SEU_USER]/projects/microservicesSpringProject/docker-image
$vim Dockerfile
In Virtual Machine, create the file and build (build) the Docker image.
$ssh [SEU_USER]@[IP_HOST] -p 22
$mkdir -p ~/projects/microservicesSpringProject/docker-image/spring-1.5.1.RELEASE
$cd ~/projects/microservicesSpringProject/docker-image
//O comando abaixo envia a aplicação Spring Boot (.jar) da Máquina Física - MF para a Máquina Virtual.
$scp -P22 -v -r -C /Users/[SEU_USER]/projects/microservicesSpringProject/target/microservicesSpringProject-0.0.1-SNAPSHOT.jar [SEU_USER]@[IP_HOST]:/home/[SEU_USER]/projects/microservicesSpringProject/docker-image
$vim Dockerfile
$docker build -t ubuntu:MicroservicesSpringBoot .
After processing above, we can check the installed Docker images:
$docker images
Now, still in Virtual Machine, we can run the Spring Boot application:
$docker run -e "JAVA_OPTS=-agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n" -p 8080:8080 -p 5005:5005 -t -i ubuntu:MicroservicesSpringBoot java -jar /root/microservicesSpringProject-0.0.1-SNAPSHOT.jar
After the above command, we can access the Spring Boot application running in the Docker container from within the VM by accessing the link: [IP_HOST]:8080
.
We can enter the container and work on the server as follows:
$docker run -t -i ubuntu:MicroservicesSpringBoot /bin/bash
6. Send image Docker: hub.docker.com
Whereas you already have an account on hub.docker.com
[hub.Docker: 2017]. And bearing in mind that reuse increases productivity, it is strongly indicated as good practice we have to send the Docker container to my repository.
$docker login
$docker tag [IMAGE_ID] [LOGIN_HUB_DOCKER]/[NOME_REPO]:latest
$docker push LOGIN_HUB_DOCKER]/[NOME_REPO]
7. Automation of the Process.
Here, I try to answer the following questions: How to organize the execution order? (Using shellscript, maybe or would fit in a Docker-Compose?)
But unfortunately I will deal with a more conceptual than empirical approach to the subject Continuous Integration - IC [Stackoverflow - CI: 2017]. For not having much confidence in what little I know, I am seeking to implement the guidelines and good practices [Alan Mark Berg: 2015] used in the Jenkins environment.
I believe that is it. Thank you for the question and for that, for the opportunity to learn and contribute.
Reference:
[Sébastien Goasguen: 2016], Docker Cookbook: SOLUTIONS AND EXAMPLES FOR BUILDING DISTRIBUTED APPLICATIONS.
[Alan Mark Berg: 2015], Jenkins Continuous Integration Cookbook: Second Edition
[Docker: 2017 - a], Available at: Dockerfile Best Practices. Accessed: 01 Apr 2017
[Docker: 2017 - b], Available at: Dockerfile Examples. Accessed: 01 Apr 2017
[Docker: 2017 - c], Available at: Paas Docker: Image Docker created with the intention of implementing a Platform as a Service - Paas. Accessed: 02 Apr 2017
[Git: 2017 - a], Available at: Git Essential Getting a Git Repository. Accessed: 01 Apr 2017
[Git: 2017 - b], Available at: Git on Server - Configuring Server. Accessed: 01 Apr 2017
[Christian Posta: 2016], Available in: Microservices for Java Developers: A Hands-on Introduction to Frameworks and Containers. Accessed: 01 Apr 2017
[Markus Eisele: 2016], Available in: Modern Java EE Design Patterns: Building Scalable Architecture for Sustainable Enterprise Development.
[Spring: 2017], Available in: Spring Boot with Docker: Site with tutorial. Accessed: 02 Apr 2017
[Github Pssilva: 2017], Available in: Github Pssilva: Meu modesto repositório Github. Accessed: 02 Apr 2017
[hub.Docker: 2017], Available in: Hub Docker: repository Docker. Accessed: 02 Apr 2017
[Stackoverflow - CI: 2017], Available in: Continuous Integration - IC: repository Docker. Accessed: 02 Apr 2017
Do you recommend installing a git server? Why? What is the build integration done in the IDE? Why dockerfile in commented commands (#COPY)?
– Murillo Goulart
@Murillogoulart, first: the git server understands it to be good practice, and is essential in automation and release management in the build in the Docker container. The commented commands on dockerfile is the installation of Spring Boot CLI. Which is also important for automation of the build process and integration testing. There are other ways to install, but I did it this way to have more control. And I thought I’d leave it out there 'cause I might escape the scope of the answer.
– pss1suporte
Your answer was quite extensive, but still I could not identify the following need: "A next step (and no less important) would be to create an integration of the execution of these steps with an IDE (Netbeans or Eclipse for example) so that this development flow with Docker is transparent during the process."
– Murillo Goulart
Steps like creating the Docker image cannot be manual, for example.
– Murillo Goulart
Because the question was this about the flow. So I thought I better focus on the flow. But in the 7. Automation of the Process I approached conceptually the best way to integrate the flow using Jenkins.
– pss1suporte
Creating the image is to demonstrate the power one has to create an image. Soon after I indicate: 6. Send the image Docker: hub.docker.com. With this use the image already ready in automation when necessary.
– pss1suporte
As little as I know, Devops' activities are to prepare the environment so that automated processes run transparently beyond the scope of development work. And developer just follows the scripts running without interfering too much.
– pss1suporte
Thanks for the answer! Gave me a way.
– Rafael Weber
@Rafaelweber, OK ! But I want to improve the answer. As soon as I finish here some tests in the Jenkins environment. And testing integration between Docker containers.
– pss1suporte