Skip to content
Snippets Groups Projects
Commit 5de708e3 authored by Mirco Nasuti's avatar Mirco Nasuti
Browse files

Merge branch 'docker_build' into extract_config

parents 8a88500e 5cebfce5
No related branches found
No related tags found
No related merge requests found
# This Dockerfile encapsulate the MIP portal backend application for development purposes.
# We use it to bootstrap the generation of the Hibernate mapping file and the application jar.
FROM maven:3-jdk-8
COPY ./src/docker/init/build-in-docker.sh /build-in-docker.sh
CMD mkdir /opt/portal/
VOLUME /opt/portal/
WORKDIR /opt/portal/
CMD ["/build-in-docker.sh"]
## Introduction
This is the MIP implementation.
This is the MIP backend.
## Usage
Build the project with `./build` and run it with `./run`.
* Build the project: `./build.sh`
* Run the project: `./run.sh`
* Show live logs: `./log.sh` (CTRL+C to quit)
* Stop and remove the running container: `./halt.sh`
## API Documentation using Swagger (Springfox)
## Generate PDF API documentation on build
The API documentation is available at `<BASE URL>/swagger-ui.html`. A JSON version is available at `<BASE URL>/v2/api-docs`
## TODO
* Implement SoapUI tests;
* Clean code (both back-end front-end);
* Sync with original Swagger description;
* Externalize configuration (DB parameters, security enabled/disabled, ...);
* Make user tests with multiple users;
* Fix bugs.
## BUGS
* Export PDF does not work;
### Maintenance
* To keep an updated API documentation, the developers should keep synchronized both the auto-generated swagger file (from Java annotations) with the hand written one. You can follow this method to get a YAML description from the Java-annotated code:
* Add annotations to the Java code;
* Get JSON from `<BASE URL>/v2/api-docs`;
* Convert JSON to YAML on [http://jsontoyaml.com](http://jsontoyaml.com).
\ No newline at end of file
Uncomment the following line in src/docker/build/build-in-docker.sh :
`mvn swagger2markup:convertSwagger2markup asciidoctor:process-asciidoc`
#!/bin/bash -e
#!/usr/bin/env bash
if groups $USER | grep &>/dev/null '\bdocker\b'; then
DOCKER_COMPOSE="docker-compose"
else
DOCKER_COMPOSE="sudo docker-compose"
fi
# TODO: Cannot clean otherwise the build fails because of Hibernate schema generation
mvn package
cp target/mip.jar src/docker/build/
$DOCKER_COMPOSE build
./halt.sh
docker-compose -f ./docker-compose_build.yml build
docker-compose -f ./docker-compose_build.yml up
# Build the application and regenerate the Hibernate mapping
portaldb:
image: postgres:9.5.3
container_name: portaldb
ports:
- "55432:5432"
volumes:
- ./src/test/db/sql:/docker-entrypoint-initdb.d/
environment:
POSTGRES_PASSWORD: test
portal-backend:
build: .
volumes:
- ./:/portal/
- ./.m2/:/root/.m2/
links:
- portaldb
ports:
- "8080:8080"
version: '2'
portaldb:
image: postgres:9.5.3
container_name: portaldb
ports:
- "55432:5432"
volumes:
- ./src/test/db/sql:/docker-entrypoint-initdb.d/
environment:
POSTGRES_PASSWORD: test
portal-backend:
build: ./src/docker/build
volumes:
- ./src/test/docker/:/opt/portal/config/
- ./target/:/opt/portal/lib/
links:
- portaldb
ports:
- "8080:8080"
services:
backend:
container_name: backend
build:
context: .
dockerfile: ./src/docker/run/Dockerfile
ports:
- "8080:8080"
version: '2'
services:
backend_build:
container_name: backend_build
build: ./src/docker/build/
volumes:
- ./:/opt/portal/
- .m2:/root/.m2/
ports:
- "8080:8080"
#!/usr/bin/env bash
docker-compose kill
docker-compose rm -f
log.sh 0 → 100755
#!/usr/bin/env bash
docker-compose logs -f backend
......@@ -5,7 +5,7 @@
<groupId>org.hbp.mip</groupId>
<artifactId>backend-services</artifactId>
<version>0.1.0</version>
<version>DOCKER_BUILD</version>
<packaging>jar</packaging>
<name>backend-services</name>
......
#!/bin/bash -e
#!/usr/bin/env bash
# Run the backend in a Docker container and start the database.
# The current project is compiler inside the Docker container
if groups $USER | grep &>/dev/null '\bdocker\b'; then
DOCKER_COMPOSE="docker-compose"
else
DOCKER_COMPOSE="sudo docker-compose"
fi
# Create a symlink to the local Maven repository
[ -L .m2 ] || ln -s -t . ~/.m2
$DOCKER_COMPOSE --file=docker-compose.init.yml --project-name=portal-backend-init up
echo "Need to set the current user as owner of the files generated in target directory..."
sudo chown -R $USER:$USER ./target
echo "Done"
docker-compose build
docker-compose up -d
*.jar
# This Dockerfile encapsulate the MIP portal backend application for development purposes.
FROM maven:3-jdk-8
RUN apt-get update && apt-get install -y wget
RUN wget https://github.com/jwilder/dockerize/releases/download/v0.2.0/dockerize-linux-amd64-v0.2.0.tar.gz
RUN tar -C /usr/local/bin -xzvf dockerize-linux-amd64-v0.2.0.tar.gz
COPY mip.sh /opt/portal/
COPY mip.jar /opt/portal/lib/
RUN chmod +x /opt/portal/mip.sh
EXPOSE 8080
VOLUME /opt/portal/config/
VOLUME /opt/portal/lib/
COPY ./build-in-docker.sh /build-in-docker.sh
VOLUME /opt/portal/
WORKDIR /opt/portal/
CMD ["/usr/local/bin/dockerize", "-timeout", "240s", "-wait", "tcp://portaldb:5432", "/opt/portal/mip.sh"]
CMD ["bash", "/build-in-docker.sh"]
#!/usr/bin/env bash
rm -r target/
mvn package -DskipTests -P dev
# Uncomment to generate a PDF API documentation
# mvn swagger2markup:convertSwagger2markup asciidoctor:process-asciidoc
#!/usr/bin/env bash
/usr/bin/java -DconfigFile=/opt/portal/config/application.yml -jar /opt/portal/lib/mip.jar
#!/bin/sh -e
echo ">>> Building inside Docker"
cd /portal
mvn package
echo ">>> Press Ctrl+C to stop, build is complete"
FROM frolvlad/alpine-oraclejdk8:slim
COPY ./target/backend-services-DOCKER_BUILD.jar backend.jar
CMD ["java", "-jar", "backend.jar"]
package org.hbp.mip.utils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class CustomLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint {
public CustomLoginUrlAuthenticationEntryPoint(String url) {
super(url);
}
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
}
}
start java -jar target\backend-services-0.0.1-SNAPSHOT.jar --spring.config.location=config\application.yml
\ No newline at end of file
#!/bin/sh
if groups $USER | grep &>/dev/null '\bdocker\b'; then
DOCKER_COMPOSE="docker-compose"
else
DOCKER_COMPOSE="sudo docker-compose"
fi
$DOCKER_COMPOSE rm -f
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment