diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..1b9c7a68f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM ubuntu:latest +MAINTAINER evgenyidf + +RUN apt-get update --fix-missing && apt-get install -y default-jre + +RUN mkdir /var/spring-petclinic +COPY target/spring-petclinic*.jar /var/spring-petclinic/spring-petclinic.jar + +EXPOSE 8080 + +VOLUME [".", "/"] + +CMD ["java -jar /var/spring-petclinic/spring-petclinic.jar"] \ No newline at end of file diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..dff6c3de4 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,28 @@ +pipeline { + agent { docker { image 'maven:3.3.3' } } + stages { + stage('build and test') { + steps { + echo 'Building..' + } + steps { + sh 'mvn package' + } + } + stage('docker image build') { + steps { + echo 'Docker compose..' + } + steps { + sh 'docker-compose down && docker-compose up --build -d' + } + } + } + + post { + failure { + mail bcc: '', body: "Example
\n\
Project: ${env.JOB_NAME}
Build Number: ${env.BUILD_NUMBER}
URL de build: ${env.BUILD_URL}", cc: '', charset: 'UTF-8', from: '', mimeType: 'text/html', replyTo: '', subject: "ERROR CI: Project name -> ${env.JOB_NAME}", to: "foo@gmail.com"; + } + } + +} \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 0f4a7fc30..842d378f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,3 +1,12 @@ +jenkins: + image: jenkinsci/blueocean + ports: + - "8081:8080" + - "50000:50000" + environment: + - jenkins-data=/var/jenkins_home + + mysql: image: mysql:5.7 ports: @@ -7,3 +16,21 @@ mysql: - MYSQL_DATABASE=petclinic volumes: - "./conf.d:/etc/mysql/conf.d:ro" + +petclinic1: + build: . + ports: + - "8082:8080" + +petclinic2: + build: . + ports: + - "8083:8080" + +nginx: + build: ./nginx + links: + - petclinic1:petclinic1 + - petclinic2:petclinic2 + ports: + - "8080:8080" diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100644 index 000000000..e187c5dd0 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,6 @@ +# Set nginx base image +FROM nginx:latest +MAINTAINER evgenyidf + +# Copy custom configuration file from the current directory +COPY nginx.conf /etc/nginx/nginx.conf \ No newline at end of file diff --git a/nginx/nginx.conf b/nginx/nginx.conf new file mode 100644 index 000000000..85dbcee71 --- /dev/null +++ b/nginx/nginx.conf @@ -0,0 +1,21 @@ +events { + worker_connections 4096; ## Default: 1024 +} + +http { + + upstream localhost { + # These are references to our backend containers, facilitated by + # Compose, as defined in docker-compose.yml + server petclinic1:8082; + server petclinic2:8083; + } + server { + listen 8080; + server_name localhost; + location / { + proxy_pass http://localhost; + proxy_set_header Host $host; + } + } +} diff --git a/pom.xml b/pom.xml index 0469ceaf7..5692d4308 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,9 @@ spring-petclinic 2.0.0.BUILD-SNAPSHOT + + jar + org.springframework.boot spring-boot-starter-parent @@ -17,6 +20,11 @@ + 1.8 + 2.5 + 4.12 + 1.2.17 + 1.8 UTF-8 UTF-8 @@ -108,6 +116,31 @@ spring-boot-devtools true + + + junit + junit + ${junit.version} + test + + + joda-time + joda-time + ${jodatime.version} + + + log4j + log4j + ${log4j.version} + + + + + javax.xml.bind + jaxb-api + 2.3.0 + + @@ -202,7 +235,58 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + ${jdk.version} + ${jdk.version} + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + **/log4j.properties + + + + true + org.springframework.samples.petclinic.PetClinicApplication + dependency-jars/ + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.5.1 + + + copy-dependencies + package + + copy-dependencies + + + + runtime + ${project.build.directory}/dependency-jars/ + + + + + diff --git a/src/Dockerfile b/src/Dockerfile new file mode 100644 index 000000000..6282b256c --- /dev/null +++ b/src/Dockerfile @@ -0,0 +1,16 @@ +FROM ubuntu:latest +MAINTAINER evgenyidf + +RUN apt-get update --fix-missing && apt-get install -y default-jre + +RUN mkdir -p /var/spring-petclinic/jars + +WORKDIR /var/spring-petclinic +COPY ../target/spring-petclinic*.jar /var/spring-petclinic/spring-petclinic.jar +COPY ../target/dependency-jars/*.jar /var/spring-petclinic/jars + +RUN ls -la /var/spring-petclinic/spring-petclinic-2.0.0.BUILD-SNAPSHOT.jar + +EXPOSE 8080 + +#ENTRYPOINT ["java -cp /var/spring-petclinic.jar"] \ No newline at end of file diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties new file mode 100644 index 000000000..6dce7998d --- /dev/null +++ b/src/main/resources/log4j.properties @@ -0,0 +1,7 @@ +# Root logger option +log4j.rootLogger=DEBUG, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n