Skip to content

Commit

Permalink
docker
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetancollaud committed Feb 10, 2018
1 parent 6a4a786 commit 27ee2d6
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 1,047 deletions.
5 changes: 2 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM frolvlad/alpine-oraclejdk8:slim

EXPOSE 8080
EXPOSE 8282
EXPOSE 8081

COPY data/ /data
ADD target/*.jar app.jar
RUN sh -c 'touch /app.jar'
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]

HEALTHCHECK --start-period=10s --interval=5s --timeout=3s --retries=2 \
CMD wget --spider http://localhost:8081/actuator/health
CMD wget --spider http://localhost:8081/health
20 changes: 0 additions & 20 deletions backend/docker-compose.yml

This file was deleted.

4 changes: 4 additions & 0 deletions backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ public MessageConverter jacksonJmsMessageConverter() {
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
registry.addMapping("/**").allowedOrigins("localhost:8080");
}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ch.fablabs.fabjam.cocktail.boot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
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;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Configuration
@EnableWebSecurity
public class WebConfig extends WebSecurityConfigurerAdapter {

@Bean
public FilterRegistrationBean httpFilter() {
return new FilterRegistrationBean(new Filter() {
@Override
public void init(FilterConfig filterConfig) throws ServletException {

}

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, PUT, DELETE, GET, OPTIONS");
}

@Override
public void destroy() {

}
});
}


@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable();
http
.authorizeRequests().anyRequest().permitAll();
// http
// .authorizeRequests()
// .antMatchers("/wl/*").permitAll()
// .antMatchers("/dev/*").permitAll()
// .antMatchers("/wl/system/*").hasRole("SYSTEM")
// .and()
// .httpBasic();
// http
// .headers()
// .cacheControl().disable()
// .frameOptions().sameOrigin();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void checkForLine() {
String line = buffer.substring(0, newLine).replace("\r", "");
buffer.delete(0, newLine + 1);
LOG.trace("Read: {}", line);
if (jmsTemplate != null) {
if (jmsTemplate != null && line != null && line.length() > 0) {
jmsTemplate.convertAndSend(JmsTopic.SERIAL_INPUT, line);
}
}
Expand Down
2 changes: 2 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ spring.data.mongodb.host=mongodb
spring.data.mongodb.port=27017
spring.data.mongodb.database=baromatic

management.port=8081

serial.port=/dev/ttsUSB0

spring.jms.pub-sub-domain=true
Expand Down
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.0'
services:
proxy:
image: traefik
container_name: baromatic-proxy
ports:
- "80:80"
- "8082:8082"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./traefik.toml:/etc/traefik/traefik.toml
backend:
image: gaetancollaud/bar-o-matic-backend
container_name: baromatic-backend
build: ./backend
#links:
# - mongodb:mongodb
#TODO add devices
labels:
- "traefik.frontend.rule=PathPrefix:/api"
- "traefik.enable=true"
- "traefik.port=8080"
frontend:
image: gaetancollaud/bar-o-matic-frontend
container_name: baromatic-frontend
build: ./frontend
labels:
- "traefik.frontend.rule=PathPrefix:/"
- "traefik.enable=true"
- "traefik.port=80"
mongodb:
image: mongo
container_name: cocktail-mongo
user: root
ports:
- 27017:27017
volumes:
- "./data/mongo:/data/db"
13 changes: 13 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM nginx:alpine

# install curl
RUN apk add --no-cache curl

# create health check
HEALTHCHECK --interval=5s --timeout=2s CMD curl --fail -A "docker-healthcheck-curl/1.0.0" http://localhost:80/ || exit 1

# Configure for angular fallback routes
COPY nginx.conf /etc/nginx/nginx.conf

# Copy built app to wwwroot
COPY dist /usr/share/nginx/html
2 changes: 1 addition & 1 deletion frontend/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
},
dev: {
env: require('./dev.env'),
port: 8080,
port: 8081,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
Expand Down
21 changes: 21 additions & 0 deletions frontend/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events {
# events context
}

http{
include /etc/nginx/mime.types;

server {
listen 80 default_server;
access_log /var/log/nginx.access.log;
error_log /var/log/nginx.error.log;
root /usr/share/nginx/html;
charset utf-8;

add_header X-Frame-Options "SAMEORIGIN";

location / {
try_files $uri /index.html;
}
}
}
Loading

0 comments on commit 27ee2d6

Please sign in to comment.