Skip to content

Commit

Permalink
Merge pull request NIBLCO#4 from NIBLCO/docker
Browse files Browse the repository at this point in the history
Docker
  • Loading branch information
jenga201 authored Sep 28, 2023
2 parents b3b66ae + 268d024 commit 562801a
Show file tree
Hide file tree
Showing 23 changed files with 34 additions and 2,007 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM maven:3.5-jdk-8 AS build
COPY src /usr/src/app/src
COPY pom.xml /usr/src/app
RUN mvn -f /usr/src/app/pom.xml clean package

FROM gcr.io/distroless/java
COPY --from=build /usr/src/app/target/nibl-api.jar /usr/app/nibl-api.jar

ENTRYPOINT ["java","-jar","/usr/app/nibl-api.jar"]
49 changes: 15 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
# Intro
The NIBL API will be used to view XDCC bots and search for pack listings

This is written in Spring Boot (of which I have little experience) and uses a MySQL database.
This is written in Spring Boot and uses a MySQL database.

Documentation on RESTful calls is handled in Swagger

#### Swagger URL
http://{Server IP}:8080/swagger-ui.html
http://{Server IP}/swagger-ui.html

# Setup

## Required Software
1) Java 1.8
2) Maven
3) MySQL
Docker

## Database
1) Import the database schema (db/schema.sql) and data (db/data.sql)
2) Update the mysql username and password (src/main/resources/application.properties)

Yes, I know the schema is not perfect, it was written in 2007.
I will eventually update the schema to JPA standards while rewriting the software that populates it.

## App
1) mvn clean install
2) java -jar target/nibl-api.jar

# Debug

## Database
JPA is good about throwing errors if the database structure does not map to annotations
or Java objects properly.

You should see errors during start-up which tell you what is wrong.

## App
Log levels can be adjusted in the application.yml file.

Defaults are;

org.springframework.boot.env.PropertySourcesLoader: ERROR
org.springframework.web: ERROR
com.nibl: ERROR
org.hibernate.SQL: ERROR


Uses the same database from ircBot

## Run App
```
sudo docker build -f Dockerfile -t niblapi . \
&& \
sudo docker run -d \
--net='my-bridge' \
--name=niblapi \
-v /opt/niblapi/logs/:'/logs':'rw' \
niblapi
```
5 changes: 2 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<version>2.1.5.RELEASE</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -63,7 +63,6 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
Expand All @@ -87,6 +86,7 @@
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
Expand All @@ -95,7 +95,6 @@
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.23.2</version>
</dependency>
</dependencies>

Expand Down
62 changes: 0 additions & 62 deletions src/main/java/com/nibl/api/ApplicationConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package com.nibl.api;

import java.util.ArrayList;
import java.util.List;

import org.apache.catalina.connector.Connector;
import org.apache.commons.lang3.StringUtils;
import org.apache.coyote.http11.Http11NioProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
Expand All @@ -22,59 +13,6 @@ public class ApplicationConfiguration {

private static Logger log = LoggerFactory.getLogger(ApplicationConfiguration.class);

public class EmbeddedTomcatConfiguration {

@Value("${server.additionalPorts}")
private String additionalPorts;

@Value("${server.ssl.key-store}")
private String absoluteKeyStore;

@Value("${server.ssl.key-store-password}")
private String keystorePass;

@Value("${server.ssl.keyStoreType}")
private String keystoreType;

@Value("${server.ssl.keyAlias}")
private String keyAlias;

@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
Connector[] additionalConnectors = this.additionalConnector();
if (additionalConnectors != null && additionalConnectors.length > 0) {
tomcat.addAdditionalTomcatConnectors(additionalConnectors);
}
return tomcat;
}

private Connector[] additionalConnector() {
if (StringUtils.isBlank(this.additionalPorts)) {
return null;
}
String[] ports = this.additionalPorts.split(",");
List<Connector> result = new ArrayList<>();
for (String port : ports) {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();

connector.setScheme("https");
connector.setPort(Integer.valueOf(port));
connector.setSecure(true);

protocol.setSSLEnabled(true);
protocol.setKeystoreFile(absoluteKeyStore);
protocol.setKeystorePass(keystorePass);
protocol.setKeystoreType(keystoreType);
protocol.setKeyAlias(keyAlias);

result.add(connector);
}
return result.toArray(new Connector[] {});
}
}

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurerAdapter() {
Expand Down

This file was deleted.

75 changes: 0 additions & 75 deletions src/main/java/com/nibl/api/anilist/domain/AccessToken.java

This file was deleted.

44 changes: 0 additions & 44 deletions src/main/java/com/nibl/api/anilist/domain/Airing.java

This file was deleted.

Loading

0 comments on commit 562801a

Please sign in to comment.