Общая система сборки у репозиториев, определение порта
This commit is contained in:
10
Dockerfile
10
Dockerfile
@@ -1,10 +0,0 @@
|
|||||||
FROM openjdk:27-ea-jdk-slim-trixie
|
|
||||||
|
|
||||||
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
|
|
||||||
COPY rosetta-server.jar server.jar
|
|
||||||
|
|
||||||
|
|
||||||
CMD ["java", "-jar", "server.jar"]
|
|
||||||
12
build/Dockerfile
Normal file
12
build/Dockerfile
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
FROM eclipse-temurin:21-jre-alpine
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Копируем готовый JAR со всеми зависимостями
|
||||||
|
COPY app.jar ./app.jar
|
||||||
|
|
||||||
|
# Открываем порт (может быть переопределён через ENV)
|
||||||
|
EXPOSE ${PORT:-3000}
|
||||||
|
|
||||||
|
# Запускаем приложение с портом из окружения
|
||||||
|
CMD ["sh", "-c", "java -jar app.jar ${PORT:-3000}"]
|
||||||
23
build/docker-compose.prod.yml
Normal file
23
build/docker-compose.prod.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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"
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
version: '3.8'
|
|
||||||
|
|
||||||
services:
|
|
||||||
app:
|
|
||||||
build: .
|
|
||||||
ports:
|
|
||||||
- "8881:8881"
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
|
|
||||||
db:
|
|
||||||
image: postgres:latest
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: your_database
|
|
||||||
POSTGRES_USER: your_user
|
|
||||||
POSTGRES_PASSWORD: your_password
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
78
pom.xml
78
pom.xml
@@ -47,6 +47,82 @@
|
|||||||
<artifactId>snakeyaml</artifactId>
|
<artifactId>snakeyaml</artifactId>
|
||||||
<version>2.5</version>
|
<version>2.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<!-- Сборка исполняемого JAR со всеми зависимостями -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.6.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.rosetta.im.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
<finalName>app</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<!-- Удаляем папку build/classes перед сборкой -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-clean-plugin</artifactId>
|
||||||
|
<version>3.3.2</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>pre-clean</phase>
|
||||||
|
<configuration>
|
||||||
|
<excludeDefaultDirectories>true</excludeDefaultDirectories>
|
||||||
|
<filesets>
|
||||||
|
<fileset>
|
||||||
|
<directory>${project.basedir}/build</directory>
|
||||||
|
<includes>
|
||||||
|
<include>classes/</include>
|
||||||
|
</includes>
|
||||||
|
</fileset>
|
||||||
|
</filesets>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>clean</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<!-- Копирование готового JAR в папку build/ -->
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-antrun-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<configuration>
|
||||||
|
<target>
|
||||||
|
<mkdir dir="${project.basedir}/build"/>
|
||||||
|
<copy file="${project.build.directory}/app.jar" todir="${project.basedir}/build/" overwrite="true"/>
|
||||||
|
<echo message="> JAR в build/app.jar, готов к деполю на сервер"/>
|
||||||
|
</target>
|
||||||
|
</configuration>
|
||||||
|
<goals>
|
||||||
|
<goal>run</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
@@ -62,14 +62,14 @@ public class Boot {
|
|||||||
private Configuration configuration;
|
private Configuration configuration;
|
||||||
private ServerConfiguration serverConfiguration;
|
private ServerConfiguration serverConfiguration;
|
||||||
|
|
||||||
public Boot() {
|
public Boot(int port) {
|
||||||
this.packetManager = new PacketManager();
|
this.packetManager = new PacketManager();
|
||||||
this.eventManager = new EventManager();
|
this.eventManager = new EventManager();
|
||||||
this.onlineManager = new OnlineManager();
|
this.onlineManager = new OnlineManager();
|
||||||
this.logger = new Logger(LogLevel.INFO);
|
this.logger = new Logger(LogLevel.INFO);
|
||||||
this.serverAdapter = new ServerAdapter(this.eventManager);
|
this.serverAdapter = new ServerAdapter(this.eventManager);
|
||||||
this.server = new Server(new Settings(
|
this.server = new Server(new Settings(
|
||||||
8881,
|
port,
|
||||||
30
|
30
|
||||||
), packetManager, this.serverAdapter);
|
), packetManager, this.serverAdapter);
|
||||||
this.clientManager = new ClientManager(server);
|
this.clientManager = new ClientManager(server);
|
||||||
|
|||||||
@@ -2,13 +2,37 @@ package com.rosetta.im;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
int port = resolvePort(args);
|
||||||
/**
|
/**
|
||||||
* Регистрация всех пакетов и их обработчиков
|
* Регистрация всех пакетов и их обработчиков
|
||||||
*/
|
*/
|
||||||
Boot boot = new Boot();
|
Boot boot = new Boot(port);
|
||||||
/**
|
/**
|
||||||
* Стартуем сервер
|
* Стартуем сервер
|
||||||
*/
|
*/
|
||||||
boot.bootstrap();
|
boot.bootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int resolvePort(String[] args) {
|
||||||
|
// Если порт указан аргументом — используем его.
|
||||||
|
if (args != null && args.length > 0) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(args[0]);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Если порт задан в окружении — используем его.
|
||||||
|
String envPort = System.getenv("PORT");
|
||||||
|
if (envPort != null && !envPort.isBlank()) {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(envPort);
|
||||||
|
} catch (NumberFormatException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Значение по умолчанию.
|
||||||
|
return 8080;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user