Feature: adds Docker packaging with docker profile + Clean: unused dependencies and testing

This commit is contained in:
fecaille
2016-03-25 14:22:00 +01:00
parent c776f5d0f8
commit 1c00864580
7 changed files with 88 additions and 323 deletions

199
pom.xml
View File

@@ -6,7 +6,7 @@
<version>1.0.0-SNAPSHOT</version>
<name>UI service project</name>
<description>Default tools to build UI BFF</description>
<packaging>jar</packaging>
<packaging>${packaging.type}</packaging>
<url>http://www.open-groupe.com</url>
<scm>
@@ -23,6 +23,7 @@
<java.version>1.8</java.version>
<maven.deploy.skip>true</maven.deploy.skip>
<project.scm.id>jazzhub</project.scm.id>
<docker.image.prefix>opensaas</docker.image.prefix>
<jasmine.version>2.4.1</jasmine.version>
<jasmine-ajax.version>3.2.0</jasmine-ajax.version>
@@ -45,64 +46,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<!-- Persistence -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jasmine</artifactId>
<version>${jasmine.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery-mockjax</artifactId>
<version>1.5.3</version>
<scope>test</scope>
</dependency>
<!-- Monitoring -->
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -222,22 +165,6 @@
</targetPath>
</configuration>
</execution>
<execution>
<id>Compile test resources</id>
<phase>process-test-resources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<extension>jsx</extension>
<sourcePath>
${project.basedir}/src/test/resources/static/js
</sourcePath>
<targetPath>
${project.basedir}/src/test/resources/static/js/compiled
</targetPath>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
@@ -260,64 +187,6 @@
<extraConfigFile>${project.basedir}/src/main/wro/wro.properties</extraConfigFile>
</configuration>
</plugin>
<!-- Testing -->
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>0.7</version>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
<configuration>
<version>2.1.1</version>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<webDriverClassName>org.openqa.selenium.phantomjs.PhantomJSDriver</webDriverClassName>
<webDriverCapabilities>
<capability>
<name>phantomjs.binary.path</name>
<value>${phantomjs.binary}</value>
</capability>
</webDriverCapabilities>
<preloadSources>
<preloadSource>/webjars/jquery.js</preloadSource>
<preloadSource>/webjars/react-with-addons.js</preloadSource>
<preloadSource>/webjars/react-dom.js</preloadSource>
<preloadSource>/webjars/jquery.mockjax.js</preloadSource>
<preloadSource>${project.basedir}/src/test/resources/jasmine/config.js</preloadSource>
</preloadSources>
<jsSrcDir>${project.build.directory}/classes/static/js</jsSrcDir>
<sourceIncludes>
<include>**/*.js</include>
</sourceIncludes>
<sourceExcludes>
<exclude>**/react-bootstrap.js</exclude>
<exclude>**/app.render.js</exclude>
</sourceExcludes>
<jsTestSrcDir>${project.basedir}/src/test/resources/static/js</jsTestSrcDir>
<specIncludes>
<include>**/*.spec.js</include>
</specIncludes>
<customRunnerTemplate>${project.basedir}/src/test/resources/jasmine/ReactJsSpecRunner.htmltemplate</customRunnerTemplate>
</configuration>
</plugin>
<!-- Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -380,19 +249,6 @@
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<versionRange>[0.7,)</versionRange>
<goals>
<goal>install</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
@@ -400,4 +256,55 @@
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>webapp</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<packaging.type>war</packaging.type>
</properties>
</profile>
<profile>
<id>docker</id>
<properties>
<packaging.type>jar</packaging.type>
</properties>
<build>
<finalName>app</finalName>
<plugins>
<!-- Docker -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.2.3</version>
<configuration>
<goal>package</goal>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@@ -0,0 +1,34 @@
FROM alpine:3.2
ENV JRE=jre1.8.0_77 \
JAVA_HOME=/opt/jre
# That's an 1.8.0_60 JRE from OpenJDK.net
# Courtesy to https://github.com/frol/docker-alpine-oraclejdk8 from where the setup of glibc is borrowed
RUN apk add --update wget curl ca-certificates && \
cd /tmp && \
wget -q "https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-2.21-r2.apk" \
"https://circle-artifacts.com/gh/andyshinn/alpine-pkg-glibc/6/artifacts/0/home/ubuntu/alpine-pkg-glibc/packages/x86_64/glibc-bin-2.21-r2.apk" && \
apk add --allow-untrusted glibc-2.21-r2.apk glibc-bin-2.21-r2.apk && \
/usr/glibc/usr/bin/ldconfig /lib /usr/glibc/usr/lib && \
echo 'hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4' >> /etc/nsswitch.conf && \
mkdir /opt && \
curl -sL -o /tmp/${JRE}.tgz --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" -q "http://download.oracle.com/otn-pub/java/jdk/8u77-b03/jre-8u77-linux-x64.tar.gz" && \
cd /opt && tar xzf /tmp/${JRE}.tgz && \
ln -s /opt/${JRE} /opt/jre && \
ln -s /opt/jre/bin/java /usr/bin/java && \
apk del wget curl ca-certificates && \
cd /opt/jre/lib/amd64 && rm libjavafx_* libjfx* libfx* && \
cd /opt/jre/lib/ && rm -rf ext/jfxrt.jar jfxswt.jar javafx.properties font* && \
rm /tmp/* /var/cache/apk/*
VOLUME /tmp
EXPOSE 8080
ADD app.jar /
RUN sh -c 'touch /app.jar'
CMD ["sh"]
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

View File

@@ -1,37 +0,0 @@
package com.opengroupe.cloud.saas.config;
import org.springframework.context.annotation.Bean;
import org.thymeleaf.extras.springsecurity4.dialect.SpringSecurityDialect;
import org.thymeleaf.spring4.SpringTemplateEngine;
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
import org.thymeleaf.templateresolver.ServletContextTemplateResolver;
import org.thymeleaf.templateresolver.TemplateResolver;
import org.thymeleaf.templateresolver.UrlTemplateResolver;
@org.springframework.context.annotation.Configuration
public class WebMvcConfiguration {
// @Bean
// public TemplateResolver templateResolver() {
// TemplateResolver templateResolver = new ThymeleafViewResolver().;
// templateResolver.setPrefix("/resources/templates");
// templateResolver.setSuffix(".html");
// templateResolver.setTemplateMode("HTML5");
// templateResolver.setCacheable(false);
// return templateResolver;
// }
// @Bean
// public UrlTemplateResolver urlTemplateResolver() {
// return new UrlTemplateResolver();
// }
// @Bean
// public SpringTemplateEngine templateEngine() {
// SpringTemplateEngine templateEngine = new SpringTemplateEngine();
//// templateEngine.addTemplateResolver(templateResolver());
// templateEngine.addTemplateResolver(urlTemplateResolver());
// templateEngine.addDialect(new SpringSecurityDialect());
// return templateEngine;
// }
}

View File

@@ -1,20 +0,0 @@
package com.opengroupe.cloud.saas.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.GET, "/**").anonymous()
.antMatchers(HttpMethod.POST, "/api/**").anonymous()
.anyRequest().permitAll();
}
}

View File

@@ -23,12 +23,9 @@
<li><a href="#" th:href="@{/task}">Tasks</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li th:if="${#authorization.expression('!isAuthenticated()')}">
<li>
<a href="/signin" th:href="@{/signin}">Sign in</a>
</li>
<li th:if="${#authorization.expression('isAuthenticated()')}">
<a href="/logout" th:href="@{/logout}">Logout</a>
</li>
</ul>
</div>
</div>

View File

@@ -1,64 +0,0 @@
package com.opengroupe.cloud.saas.rest;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockServletContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MockServletContext.class)
@WebAppConfiguration
public class CommentControllerTest {
private MockMvc mvc;
@Before
public void setUp() throws Exception {
mvc = MockMvcBuilders.standaloneSetup(new CommentController()).build();
}
@Test
public void getHello() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().string(equalTo("Greetings from Spring Boot!")));
}
@Test
public void getEmptyComment() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/api/comments").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(0)));
}
@Test
public void postComment() throws Exception {
mvc.perform(MockMvcRequestBuilders.post("/api/comments")
.accept(MediaType.APPLICATION_JSON)
.param("id", "1")
.param("author", "Lao Tzu")
.param("text", "The journey of a thousand miles begins with one step"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(1)))
.andExpect(jsonPath("$[0].id", is(1)))
.andExpect(jsonPath("$[0].author", is("Lao Tzu")))
.andExpect(jsonPath("$[0].text", is("The journey of a thousand miles begins with one step")));
}
}

View File

@@ -1,52 +0,0 @@
package com.opengroupe.cloud.saas.web;
import static org.hamcrest.Matchers.equalTo;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import javax.annotation.Resource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import com.opengroupe.cloud.saas.Application;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ViewControllerTest {
private MockMvc mvc;
@Resource
WebApplicationContext wac;
@Before
public void setUp() throws Exception {
// Process mock annotations
MockitoAnnotations.initMocks(this);
mvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void getDefaultGreetings() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/greeting"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.TEXT_HTML_VALUE + ";charset=UTF-8"))
.andExpect(model().attribute("name", equalTo("World")))
.andExpect(view().name("greeting"));
}
}