[FEATURE] Адекватная поддержка Docker.

This commit is contained in:
Zaxar163 2019-11-28 17:14:06 +01:00
parent aa4d4881c8
commit 37e3991a9a
No known key found for this signature in database
GPG key ID: 1FE4F2E1F053831B
3 changed files with 23 additions and 8 deletions

View file

@ -247,15 +247,22 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO
public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null; public static final Class<? extends LauncherBinary> defaultLauncherEXEBinaryClass = null;
public static class LaunchServerDirectories { public static class LaunchServerDirectories {
public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles",
TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries",
LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile";
public Path updatesDir; public Path updatesDir;
public Path profilesDir; public Path profilesDir;
public Path launcherLibrariesDir;
public Path launcherLibrariesCompileDir;
public Path dir; public Path dir;
public Path trustStore; public Path trustStore;
public void collect() { public void collect() {
if (updatesDir == null) updatesDir = dir.resolve("updates"); if (updatesDir == null) updatesDir = dir.resolve(UPDATES_NAME);
if (profilesDir == null) profilesDir = dir.resolve("profiles"); if (profilesDir == null) profilesDir = dir.resolve(PROFILES_NAME);
if (trustStore == null) trustStore = dir.resolve("truststore"); if (trustStore == null) trustStore = dir.resolve(TRUSTSTORE_NAME);
if (launcherLibrariesDir == null) launcherLibrariesDir = dir.resolve(LAUNCHERLIBRARIES_NAME);
if (launcherLibrariesCompileDir == null) launcherLibrariesCompileDir = dir.resolve(LAUNCHERLIBRARIESCOMPILE_NAME);
} }
} }
@ -273,8 +280,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
this.runtime = runtimeConfig; this.runtime = runtimeConfig;
this.certificateManager = certificateManager; this.certificateManager = certificateManager;
taskPool = new Timer("Timered task worker thread", true); taskPool = new Timer("Timered task worker thread", true);
launcherLibraries = dir.resolve("launcher-libraries"); launcherLibraries = directories.launcherLibrariesDir;
launcherLibrariesCompile = dir.resolve("launcher-libraries-compile"); launcherLibrariesCompile = directories.launcherLibrariesCompileDir;
config.setLaunchServer(this); config.setLaunchServer(this);

View file

@ -44,6 +44,7 @@
public class LaunchServerStarter { public class LaunchServerStarter {
public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned"); public static final boolean allowUnsigned = Boolean.getBoolean("launchserver.allowUnsigned");
public static final boolean inDocker = Boolean.getBoolean("launchserver.dockered");
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
JVMHelper.checkStackTrace(LaunchServerStarter.class); JVMHelper.checkStackTrace(LaunchServerStarter.class);
@ -177,9 +178,15 @@ public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOExcept
} }
} }
}; };
LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories();
directories.dir = dir;
if (inDocker) {
Path parentLibraries = StarterAgent.libraries.toAbsolutePath().normalize().getParent();
directories.launcherLibrariesCompileDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIESCOMPILE_NAME);
directories.launcherLibrariesDir = parentLibraries.resolve(LaunchServer.LaunchServerDirectories.LAUNCHERLIBRARIES_NAME);
}
LaunchServer server = new LaunchServerBuilder() LaunchServer server = new LaunchServerBuilder()
.setDir(dir) .setDirectories(directories)
.setEnv(env) .setEnv(env)
.setCommandHandler(localCommandHandler) .setCommandHandler(localCommandHandler)
.setPrivateKey(privateKey) .setPrivateKey(privateKey)

View file

@ -9,6 +9,7 @@
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.jar.JarFile; import java.util.jar.JarFile;
@ -59,7 +60,7 @@ public static boolean isAgentStarted() {
public static void premain(String agentArgument, Instrumentation inst) { public static void premain(String agentArgument, Instrumentation inst) {
StarterAgent.inst = inst; StarterAgent.inst = inst;
libraries = Paths.get("libraries"); libraries = Paths.get(Optional.ofNullable(agentArgument).map(e -> e.trim()).filter(e -> !e.isEmpty()).orElse("libraries"));
isStarted = true; isStarted = true;
try { try {
Files.walkFileTree(libraries, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor()); Files.walkFileTree(libraries, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor());