Докеризация, отказ от server.yml файлов, проброс .env
This commit is contained in:
13
.env
Normal file
13
.env
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
DB_HOST=localhost # Имя базы данных
|
||||||
|
DB_PORT=5432 # Порт для подключения к базе данных
|
||||||
|
DB_USER=your_user # Имя пользователя базы данных
|
||||||
|
DB_PASSWORD=your_password # Пароль для доступа к базе данных
|
||||||
|
DB_NAME=your_database # Имя базы данных
|
||||||
|
|
||||||
|
PORT=3000 # Порт, на котором будет работать сервер
|
||||||
|
|
||||||
|
# Список серверов CDN и SDU. Разделяются запятой если их несколько
|
||||||
|
# Без пробелов
|
||||||
|
CDN_SERVERS=http://10.211.55.2:7789
|
||||||
|
#SDU - Server Delivery Updates
|
||||||
|
SDU_SERVERS=http://10.211.55.2:7777
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -35,3 +35,6 @@ target
|
|||||||
.project
|
.project
|
||||||
.classpath
|
.classpath
|
||||||
|
|
||||||
|
build/.env
|
||||||
|
build/.env*
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
container_name: rosetta-server
|
|
||||||
ports:
|
|
||||||
- "${PORT:-3000}:${PORT:-3000}"
|
|
||||||
environment:
|
|
||||||
- PORT=${PORT:-3000} # Устанавливаем порт по умолчанию 3000, может быть переопределён через переменную окружения
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:latest
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: your_database
|
|
||||||
POSTGRES_USER: your_user
|
|
||||||
POSTGRES_PASSWORD: your_password
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
28
build/docker-compose.yml
Normal file
28
build/docker-compose.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: Dockerfile
|
||||||
|
container_name: rosetta-server
|
||||||
|
ports:
|
||||||
|
- "${PORT:-3000}:${PORT:-3000}"
|
||||||
|
env_file:
|
||||||
|
- .env
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
|
||||||
|
db:
|
||||||
|
image: postgres:latest
|
||||||
|
environment:
|
||||||
|
POSTGRES_DB: ${DB_NAME:-rosetta}
|
||||||
|
POSTGRES_USER: ${DB_USER:-rosetta}
|
||||||
|
POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#Это docker compose файл для разработки
|
||||||
|
#Он запускает базу и Adminer для управления базой данных
|
||||||
|
|
||||||
version: '3.8'
|
version: '3.8'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
7
pom.xml
7
pom.xml
@@ -40,13 +40,6 @@
|
|||||||
<artifactId>jakarta.persistence-api</artifactId>
|
<artifactId>jakarta.persistence-api</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.1.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Source: https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.yaml</groupId>
|
|
||||||
<artifactId>snakeyaml</artifactId>
|
|
||||||
<version>2.5</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
12
server.yml
12
server.yml
@@ -1,12 +0,0 @@
|
|||||||
#Подключение к БД
|
|
||||||
database:
|
|
||||||
host: db
|
|
||||||
user: your_user
|
|
||||||
password: your_password
|
|
||||||
db: your_database
|
|
||||||
#CDN (транспортные) серверы
|
|
||||||
transport_servers:
|
|
||||||
- http://10.211.55.2:7789
|
|
||||||
#Серверы доставки обновлений (SDU Servers Delivery Updates)
|
|
||||||
update_servers:
|
|
||||||
- http://10.211.55.2:7777
|
|
||||||
@@ -2,8 +2,6 @@ package com.rosetta.im;
|
|||||||
|
|
||||||
import com.rosetta.im.client.ClientManager;
|
import com.rosetta.im.client.ClientManager;
|
||||||
import com.rosetta.im.client.OnlineManager;
|
import com.rosetta.im.client.OnlineManager;
|
||||||
import com.rosetta.im.config.Configuration;
|
|
||||||
import com.rosetta.im.config.ServerConfiguration;
|
|
||||||
import com.rosetta.im.event.EventManager;
|
import com.rosetta.im.event.EventManager;
|
||||||
import com.rosetta.im.executors.Executor0Handshake;
|
import com.rosetta.im.executors.Executor0Handshake;
|
||||||
import com.rosetta.im.executors.Executor10RequestUpdate;
|
import com.rosetta.im.executors.Executor10RequestUpdate;
|
||||||
@@ -73,8 +71,6 @@ public class Boot {
|
|||||||
private ServerAdapter serverAdapter;
|
private ServerAdapter serverAdapter;
|
||||||
private ClientManager clientManager;
|
private ClientManager clientManager;
|
||||||
private OnlineManager onlineManager;
|
private OnlineManager onlineManager;
|
||||||
private Configuration configuration;
|
|
||||||
private ServerConfiguration serverConfiguration;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Конструктор по умолчанию, использует порт 3000 для сервера
|
* Конструктор по умолчанию, использует порт 3000 для сервера
|
||||||
@@ -98,7 +94,6 @@ public class Boot {
|
|||||||
30
|
30
|
||||||
), packetManager, this.serverAdapter);
|
), packetManager, this.serverAdapter);
|
||||||
this.clientManager = new ClientManager(server);
|
this.clientManager = new ClientManager(server);
|
||||||
this.configuration = new Configuration("server.yml");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -139,7 +134,6 @@ public class Boot {
|
|||||||
*/
|
*/
|
||||||
public Boot bootstrap() {
|
public Boot bootstrap() {
|
||||||
try{
|
try{
|
||||||
this.serverConfiguration = this.configuration.loadConfiguration();
|
|
||||||
this.server.start();
|
this.server.start();
|
||||||
this.registerAllPackets();
|
this.registerAllPackets();
|
||||||
this.registerAllExecutors();
|
this.registerAllExecutors();
|
||||||
@@ -196,9 +190,9 @@ public class Boot {
|
|||||||
this.packetManager.registerExecutor(4, new Executor4OnlineState(this.onlineManager, this.clientManager));
|
this.packetManager.registerExecutor(4, new Executor4OnlineState(this.onlineManager, this.clientManager));
|
||||||
this.packetManager.registerExecutor(6, new Executor6Message(this.clientManager, this.packetManager));
|
this.packetManager.registerExecutor(6, new Executor6Message(this.clientManager, this.packetManager));
|
||||||
this.packetManager.registerExecutor(7, new Executor7Read(this.clientManager, this.packetManager));
|
this.packetManager.registerExecutor(7, new Executor7Read(this.clientManager, this.packetManager));
|
||||||
this.packetManager.registerExecutor(10, new Executor10RequestUpdate(this.serverConfiguration));
|
this.packetManager.registerExecutor(10, new Executor10RequestUpdate());
|
||||||
this.packetManager.registerExecutor(11, new Executor11Typeing(this.clientManager, this.packetManager));
|
this.packetManager.registerExecutor(11, new Executor11Typeing(this.clientManager, this.packetManager));
|
||||||
this.packetManager.registerExecutor(15, new Executor15RequestTransport(this.serverConfiguration));
|
this.packetManager.registerExecutor(15, new Executor15RequestTransport());
|
||||||
this.packetManager.registerExecutor(16, new Executor16PushNotification());
|
this.packetManager.registerExecutor(16, new Executor16PushNotification());
|
||||||
this.packetManager.registerExecutor(17, new Executor17GroupCreate());
|
this.packetManager.registerExecutor(17, new Executor17GroupCreate());
|
||||||
this.packetManager.registerExecutor(18, new Executor18GroupInfo());
|
this.packetManager.registerExecutor(18, new Executor18GroupInfo());
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
package com.rosetta.im.config;
|
|
||||||
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
import org.yaml.snakeyaml.LoaderOptions;
|
|
||||||
import org.yaml.snakeyaml.Yaml;
|
|
||||||
|
|
||||||
import com.rosetta.im.exception.ConfigurationException;
|
|
||||||
|
|
||||||
public class Configuration {
|
|
||||||
|
|
||||||
private String serverConfigName;
|
|
||||||
|
|
||||||
public Configuration(String serverConfigName) {
|
|
||||||
this.serverConfigName = serverConfigName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServerConfiguration loadConfiguration() throws ConfigurationException, Exception {
|
|
||||||
if(!Files.exists(Paths.get(this.serverConfigName))){
|
|
||||||
/**
|
|
||||||
* Файл конфигурации с переданным названием не найден
|
|
||||||
*/
|
|
||||||
throw new ConfigurationException(this.serverConfigName + " is missing");
|
|
||||||
}
|
|
||||||
|
|
||||||
LoaderOptions options = new LoaderOptions();
|
|
||||||
Yaml yaml = new Yaml(options);
|
|
||||||
|
|
||||||
InputStream inputStream = Files.newInputStream(Paths.get(this.serverConfigName));
|
|
||||||
/**
|
|
||||||
* SnakeYAML автоматически загрузит обьект ServerConfiguration через рефлексию
|
|
||||||
* обратите внимание название полей в ServerConfiguration должны совпадать с названиями в
|
|
||||||
* server.yml
|
|
||||||
*/
|
|
||||||
ServerConfiguration serverConfiguration = yaml.loadAs(inputStream, ServerConfiguration.class);
|
|
||||||
return serverConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.rosetta.im.config;
|
|
||||||
|
|
||||||
public class DatabaseConfiguration {
|
|
||||||
|
|
||||||
public String host;
|
|
||||||
public String user;
|
|
||||||
public String password;
|
|
||||||
public String db;
|
|
||||||
|
|
||||||
public String getHost() {
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHost(String host) {
|
|
||||||
this.host = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUser(String user) {
|
|
||||||
this.user = user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDb() {
|
|
||||||
return db;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDb(String db) {
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package com.rosetta.im.config;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Этот файл отвечает за конфигурацию которая хранится в файле server.yml
|
|
||||||
*/
|
|
||||||
public class ServerConfiguration {
|
|
||||||
|
|
||||||
public DatabaseConfiguration database;
|
|
||||||
|
|
||||||
public List<String> transport_servers;
|
|
||||||
|
|
||||||
public List<String> update_servers;
|
|
||||||
|
|
||||||
public List<String> getUpdateServers() {
|
|
||||||
return update_servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUpdateServers(List<String> update_servers) {
|
|
||||||
this.update_servers = update_servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseConfiguration getDatabase() {
|
|
||||||
return database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDatabase(DatabaseConfiguration database) {
|
|
||||||
this.database = database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getTransportServers() {
|
|
||||||
return transport_servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTransportServers(List<String> transport_servers) {
|
|
||||||
this.transport_servers = transport_servers;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,8 +9,21 @@ public class HibernateUtil {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
sessionFactory = new Configuration().configure().buildSessionFactory();
|
Configuration cfg = new Configuration().configure();
|
||||||
|
|
||||||
|
String host = System.getenv("DB_HOST");
|
||||||
|
String port = System.getenv("DB_PORT");
|
||||||
|
String user = System.getenv("DB_USER");
|
||||||
|
String pass = System.getenv("DB_PASSWORD");
|
||||||
|
String name = System.getenv("DB_NAME");
|
||||||
|
String url = String.format("jdbc:postgresql://%s:%s/%s", host, port, name);
|
||||||
|
cfg.setProperty("hibernate.connection.url", url);
|
||||||
|
cfg.setProperty("hibernate.connection.username", user);
|
||||||
|
cfg.setProperty("hibernate.connection.password", pass);
|
||||||
|
|
||||||
|
sessionFactory = cfg.buildSessionFactory();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
throw new ExceptionInInitializerError("Error initializing Hibernate: " + e.getMessage());
|
throw new ExceptionInInitializerError("Error initializing Hibernate: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.rosetta.im.executors;
|
package com.rosetta.im.executors;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.rosetta.im.config.ServerConfiguration;
|
|
||||||
import com.rosetta.im.packet.Packet10RequestUpdate;
|
import com.rosetta.im.packet.Packet10RequestUpdate;
|
||||||
import com.rosetta.im.util.RandomUtil;
|
import com.rosetta.im.util.RandomUtil;
|
||||||
|
|
||||||
@@ -17,12 +17,6 @@ import io.orprotocol.packet.PacketExecutor;
|
|||||||
*/
|
*/
|
||||||
public class Executor10RequestUpdate extends PacketExecutor<Packet10RequestUpdate> {
|
public class Executor10RequestUpdate extends PacketExecutor<Packet10RequestUpdate> {
|
||||||
|
|
||||||
private ServerConfiguration serverConfiguration;
|
|
||||||
|
|
||||||
public Executor10RequestUpdate(ServerConfiguration serverConfiguration) {
|
|
||||||
this.serverConfiguration = serverConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceived(Packet10RequestUpdate packet, Client client) throws Exception, ProtocolException {
|
public void onPacketReceived(Packet10RequestUpdate packet, Client client) throws Exception, ProtocolException {
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +31,7 @@ public class Executor10RequestUpdate extends PacketExecutor<Packet10RequestUpdat
|
|||||||
*
|
*
|
||||||
* TODO: Логика проверки на доступность (health)
|
* TODO: Логика проверки на доступность (health)
|
||||||
*/
|
*/
|
||||||
List<String> cdnServers = this.serverConfiguration.getUpdateServers();
|
List<String> cdnServers = Arrays.asList(System.getenv("SDU_SERVERS").split(","));
|
||||||
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
||||||
packet.setServer(selectedServer);
|
packet.setServer(selectedServer);
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.rosetta.im.executors;
|
package com.rosetta.im.executors;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.rosetta.im.Failures;
|
import com.rosetta.im.Failures;
|
||||||
import com.rosetta.im.client.tags.ECIAuthentificate;
|
import com.rosetta.im.client.tags.ECIAuthentificate;
|
||||||
import com.rosetta.im.config.ServerConfiguration;
|
|
||||||
import com.rosetta.im.packet.Packet15RequestTransport;
|
import com.rosetta.im.packet.Packet15RequestTransport;
|
||||||
import com.rosetta.im.util.RandomUtil;
|
import com.rosetta.im.util.RandomUtil;
|
||||||
|
|
||||||
@@ -14,12 +14,6 @@ import io.orprotocol.packet.PacketExecutor;
|
|||||||
|
|
||||||
public class Executor15RequestTransport extends PacketExecutor<Packet15RequestTransport> {
|
public class Executor15RequestTransport extends PacketExecutor<Packet15RequestTransport> {
|
||||||
|
|
||||||
private ServerConfiguration serverConfiguration;
|
|
||||||
|
|
||||||
public Executor15RequestTransport(ServerConfiguration serverConfiguration){
|
|
||||||
this.serverConfiguration = serverConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPacketReceived(Packet15RequestTransport packet, Client client) throws Exception, ProtocolException {
|
public void onPacketReceived(Packet15RequestTransport packet, Client client) throws Exception, ProtocolException {
|
||||||
ECIAuthentificate eciAuthentificate = client.getTag(ECIAuthentificate.class);
|
ECIAuthentificate eciAuthentificate = client.getTag(ECIAuthentificate.class);
|
||||||
@@ -36,7 +30,7 @@ public class Executor15RequestTransport extends PacketExecutor<Packet15RequestTr
|
|||||||
*
|
*
|
||||||
* TODO: Логика проверки на доступность (health)
|
* TODO: Логика проверки на доступность (health)
|
||||||
*/
|
*/
|
||||||
List<String> cdnServers = this.serverConfiguration.getTransportServers();
|
List<String> cdnServers = Arrays.asList(System.getenv("CDN_SERVERS").split(","));
|
||||||
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
||||||
packet.setServer(selectedServer);
|
packet.setServer(selectedServer);
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,10 +3,6 @@
|
|||||||
<hibernate-configuration>
|
<hibernate-configuration>
|
||||||
<session-factory>
|
<session-factory>
|
||||||
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
|
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
|
||||||
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/your_database</property>
|
|
||||||
<property name="hibernate.connection.username">your_user</property>
|
|
||||||
<property name="hibernate.connection.password">your_password</property>
|
|
||||||
|
|
||||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||||
<!--Зарегистрированные таблицы-->
|
<!--Зарегистрированные таблицы-->
|
||||||
<mapping class="com.rosetta.im.database.entity.User"/>
|
<mapping class="com.rosetta.im.database.entity.User"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user