Rework Docker support
- Use multi-stage build for the application image - Utilize connection pool init timeout for waiting on database container startup, "docker-compose-wait" dependency is no longer required - Override database host through environment variable - used in docker-compose - Rename database scripts for explicit ordering (db container loads them alphabetically)
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
/docs
|
||||||
|
/handbook
|
||||||
|
/tools
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,6 +2,7 @@
|
|||||||
.idea/
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
/target
|
/target
|
||||||
|
/docker-db-data
|
||||||
|
|
||||||
# build files
|
# build files
|
||||||
|
|
||||||
|
|||||||
27
Dockerfile
27
Dockerfile
@@ -1,13 +1,20 @@
|
|||||||
# Docker support, thanks to xinyifly
|
# Initial Docker support thanks to xinyifly
|
||||||
|
|
||||||
FROM openjdk:8u171-jdk-alpine
|
#
|
||||||
RUN apk -U add tini
|
# Build stage
|
||||||
WORKDIR /mnt
|
#
|
||||||
|
FROM maven:3.6.3-jdk-8 AS build
|
||||||
|
COPY src /home/app/src
|
||||||
|
COPY pom.xml /home/app
|
||||||
|
RUN mvn -f /home/app/pom.xml clean package
|
||||||
|
|
||||||
|
#
|
||||||
|
# Package stage
|
||||||
|
#
|
||||||
|
FROM openjdk:8
|
||||||
|
COPY --from=build /home/app/target/Cosmic.jar /usr/local/lib/Cosmic.jar
|
||||||
COPY ./ ./
|
COPY ./ ./
|
||||||
RUN sh ./posix-compile.sh
|
|
||||||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.6.0/wait /wait
|
|
||||||
RUN chmod +x /wait
|
|
||||||
|
|
||||||
EXPOSE 8484 7575 7576 7577
|
EXPOSE 8484 7575 7576 7577
|
||||||
ENTRYPOINT ["tini", "--"]
|
ENTRYPOINT ["java", "-jar", "/usr/local/lib/Cosmic.jar"]
|
||||||
CMD /wait && sh ./posix-launch.sh
|
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,8 @@ server:
|
|||||||
USE_THREAD_TRACKER: false #[SEVERE] This deadlock auditing thing will bloat the memory as fast as the time frame one takes to lose track of a raindrop on a tempesting day. Only for debugging purposes.
|
USE_THREAD_TRACKER: false #[SEVERE] This deadlock auditing thing will bloat the memory as fast as the time frame one takes to lose track of a raindrop on a tempesting day. Only for debugging purposes.
|
||||||
|
|
||||||
#Database Configuration
|
#Database Configuration
|
||||||
DB_URL: "jdbc:mysql://localhost:3306/cosmic"
|
DB_URL_FORMAT: "jdbc:mysql://%s:3306/cosmic"
|
||||||
|
DB_HOST: "localhost"
|
||||||
DB_USER: "cosmic_server"
|
DB_USER: "cosmic_server"
|
||||||
DB_PASS: "snailshell"
|
DB_PASS: "snailshell"
|
||||||
INIT_CONNECTION_POOL_TIMEOUT: 60 # Seconds
|
INIT_CONNECTION_POOL_TIMEOUT: 60 # Seconds
|
||||||
|
|||||||
@@ -1,20 +1,22 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
maplestory:
|
maplestory:
|
||||||
network_mode: "host"
|
|
||||||
build: .
|
build: .
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
ports:
|
||||||
|
- "8484:8484"
|
||||||
|
- "7575-7577:7575-7577"
|
||||||
environment:
|
environment:
|
||||||
WAIT_HOSTS: localhost:3306
|
DB_HOST: "db"
|
||||||
|
|
||||||
db:
|
db:
|
||||||
network_mode: "host"
|
image: mysql:8.0.23
|
||||||
image: mysql:5.6
|
|
||||||
environment:
|
environment:
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
|
MYSQL_RANDOM_ROOT_PASSWORD: "true"
|
||||||
MYSQL_DATABASE: "cosmic"
|
MYSQL_DATABASE: "cosmic"
|
||||||
MYSQL_USER: "root"
|
MYSQL_USER: "cosmic_server"
|
||||||
MYSQL_PASSWORD: ""
|
MYSQL_PASSWORD: "snailshell"
|
||||||
volumes:
|
volumes:
|
||||||
|
- ./docker-db-data:/var/lib/mysql
|
||||||
- ./sql:/docker-entrypoint-initdb.d
|
- ./sql:/docker-entrypoint-initdb.d
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ public class ServerConfig {
|
|||||||
public boolean USE_THREAD_TRACKER;
|
public boolean USE_THREAD_TRACKER;
|
||||||
|
|
||||||
//Database Configuration
|
//Database Configuration
|
||||||
public String DB_URL;
|
public String DB_URL_FORMAT;
|
||||||
|
public String DB_HOST;
|
||||||
public String DB_USER;
|
public String DB_USER;
|
||||||
public String DB_PASS;
|
public String DB_PASS;
|
||||||
public int INIT_CONNECTION_POOL_TIMEOUT;
|
public int INIT_CONNECTION_POOL_TIMEOUT;
|
||||||
|
|||||||
@@ -27,10 +27,19 @@ public class DatabaseConnection {
|
|||||||
return dataSource.getConnection();
|
return dataSource.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getDbUrl() {
|
||||||
|
// Environment variables override what's defined in the config file
|
||||||
|
// This feature is used for the Docker support
|
||||||
|
String hostOverride = System.getenv("DB_HOST");
|
||||||
|
String host = hostOverride != null ? hostOverride : YamlConfig.config.server.DB_HOST;
|
||||||
|
String dbUrl = String.format(YamlConfig.config.server.DB_URL_FORMAT, host);
|
||||||
|
return dbUrl;
|
||||||
|
}
|
||||||
|
|
||||||
private static HikariConfig getConfig() {
|
private static HikariConfig getConfig() {
|
||||||
HikariConfig config = new HikariConfig();
|
HikariConfig config = new HikariConfig();
|
||||||
|
|
||||||
config.setJdbcUrl(YamlConfig.config.server.DB_URL);
|
config.setJdbcUrl(getDbUrl());
|
||||||
config.setUsername(YamlConfig.config.server.DB_USER);
|
config.setUsername(YamlConfig.config.server.DB_USER);
|
||||||
config.setPassword(YamlConfig.config.server.DB_PASS);
|
config.setPassword(YamlConfig.config.server.DB_PASS);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user