Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed docker build issue in mvn pom #11

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM java:8
FROM maven:3-jdk-8

MAINTAINER Patrick Chanezon <[email protected]>

EXPOSE 8080

COPY spring-doge/target/*.jar /usr/src/spring-doge/spring-doge.jar
WORKDIR /usr/src/spring-doge
CMD java -Dserver.port=8080 -Dspring.data.mongodb.uri=$MONGODB_URI -jar spring-doge.jar
COPY . /usr/src/spring-doge
RUN mvn install && cp spring-doge/target/*.jar spring-doge.jar
CMD java -Dserver.port=8080 -Dspring.data.mongodb.uri=$MONGODB_URI -jar spring-doge.jar
9 changes: 9 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM java:8

MAINTAINER Patrick Chanezon <[email protected]>

EXPOSE 8080

COPY spring-doge/target/*.jar /usr/src/spring-doge/spring-doge.jar
WORKDIR /usr/src/spring-doge
CMD java -Dserver.port=8080 -Dspring.data.mongodb.uri=$MONGODB_URI -jar spring-doge.jar
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Spring Doge - Such Boot!


```
cf push -p target/demo-0.0.1-SNAPSHOT.jar -b https://github.com/cloudfoundry/java-buildpack.git doge

Expand All @@ -11,7 +12,23 @@ https://gist.github.com/relaxdiego/7539911

https://github.com/pivotal-cf/java-8-buildpack/blob/master/docs/example-java_main.md

## Building and running with Docker
## Building and running the application using docker and docker-compose

The maven build for this project integrates with Docker using the [Spotify Maven plugin](https://github.com/spotify/docker-maven-plugin). You need to have Docker installed and configured. See [Installing Docker](https://docs.docker.com/installation/).

In order to build a docker image:
```
mvn package
```

You can customize the Docker Hub user for your image (by default it will create chanezon/spring-doge) in spring-doge/pom.xml.

Then to run the app:
```
docker-compose -f spring-doge/target/docker-compose.yml up
```

## Old Building and running with Docker

You can use STS or a locally installation of maven to build spring-doge. However, if you need to build that on a new machine where you don't have all your development environment setup, you can build it with the maven Docker container.

Expand All @@ -23,7 +40,7 @@ This will create the spring-doge jar file in target.
Then, you can build a container for the app and run the app and a Mongodb database in containers with the following commands:

```
docker build -t chanezon/spring-doge .
docker build -t foo/spring-doge .
docker-compose up
```

Expand Down
12 changes: 12 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
web:
image: chanezon/spring-doge
ports:
- 8080
links: ["mongo"]
environment:
- MONGODB_URI=mongodb://mongo:27017/test
labels:
- "interlock.hostname=spring-doge"
- "interlock.domain=chanezon.com"
mongo:
image: mongo
9 changes: 9 additions & 0 deletions docker-compose.run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
web:
image: chanezon/spring-doge
ports:
- "8080:8080"
links: ["mongo"]
environment:
- MONGODB_URI=mongodb://mongo:27017/test
mongo:
image: mongo
8 changes: 6 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
web:
image: chanezon/spring-doge
image: chanezon/sts:3.7.5
volumes:
- ./..:/workspace
- maven:/root/.m2
ports:
- "8080:8080"
- "8090:8080"
links: ["mongo"]
environment:
- DISPLAY=$DISPLAY_MAC
- MONGODB_URI=mongodb://mongo:27017/test
mongo:
image: mongo
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.M1</version>
<version>1.3.0.M2</version>
</parent>
<groupId>io.spring.doge</groupId>
<artifactId>spring-doge-parent</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion spring-doge-web/src/main/resources/templates/client.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<div ng-controller="ClientController" class="ng-cloak">

<h1>Upload an Image</h1>
<h1>Upload an Image and have fun!</h1>

<div>
Open the <a target="doge-monitor" href="/monitor">monitor page
Expand Down
173 changes: 102 additions & 71 deletions spring-doge/pom.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.doge</groupId>
<artifactId>spring-doge-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.spring.doge</groupId>
<artifactId>spring-doge-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>
<name>spring-doge</name>
<artifactId>spring-doge</artifactId>
<properties>
<main.basedir>${basedir}/..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cloud</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-doge-photo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-doge-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-doge</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<name>spring-doge</name>
<artifactId>spring-doge</artifactId>
<properties>
<docker.image.prefix>chanezon</docker.image.prefix>
<main.basedir>${basedir}/..</main.basedir>
</properties>
<dependencies>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-doge-photo</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>spring-doge-web</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-graphite</artifactId>
<version>${dropwizard-metrics.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-remote-shell</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.3.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>spring-doge</finalName>
<resources>
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/docker</directory>
<include>*.yml</include>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
9 changes: 9 additions & 0 deletions spring-doge/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM java:8

MAINTAINER Patrick Chanezon <[email protected]>

EXPOSE 8080

WORKDIR /usr/src
ADD spring-doge.jar app.jar
CMD java -Dserver.port=8080 -Dspring.data.mongodb.uri=$MONGODB_URI -jar app.jar
10 changes: 10 additions & 0 deletions spring-doge/src/main/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
mongo:
image: mongo

web:
image: ${docker.image.prefix}/${project.artifactId}
ports:
- "8080:8080"
links: ["mongo"]
environment:
- MONGODB_URI=mongodb://mongo:27017/test