diff options
author | axtloss <axtlos@getcryst.al> | 2023-05-29 23:56:25 +0200 |
---|---|---|
committer | axtloss <axtlos@getcryst.al> | 2023-05-29 23:56:25 +0200 |
commit | 3bfe8ba05a429e726001b88c63f736f1bbed3509 (patch) | |
tree | 0e7d3cb0e38ea9111c7c05e63d3b05cfeda74825 /src/main/java/io/github/jshipit/ContainerManager.java | |
parent | 87cc052844e2cacca591edd68884f1e7f6c49a3a (diff) | |
download | jshipit-3bfe8ba05a429e726001b88c63f736f1bbed3509.tar.gz jshipit-3bfe8ba05a429e726001b88c63f736f1bbed3509.tar.bz2 |
Allow bind mounting from host into container
Diffstat (limited to 'src/main/java/io/github/jshipit/ContainerManager.java')
-rw-r--r-- | src/main/java/io/github/jshipit/ContainerManager.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/io/github/jshipit/ContainerManager.java b/src/main/java/io/github/jshipit/ContainerManager.java index 07dae9c..d276f75 100644 --- a/src/main/java/io/github/jshipit/ContainerManager.java +++ b/src/main/java/io/github/jshipit/ContainerManager.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.*; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -18,24 +19,27 @@ public class ContainerManager { private String containerApiRepo; private String containerCommand; + private List<String> containerMounts; private OCIDataStore dataStore; - public ContainerManager(String containerName, String containerImage, String containerTag, String containerApiRepo, String containerRepo, OCIDataStore dataStore) { + public ContainerManager(String containerName, String containerImage, String containerTag, String containerApiRepo, String containerRepo, List<String> containerMounts, OCIDataStore dataStore) { this.containerName = containerName; this.containerImage = containerImage; this.containerTag = containerTag; this.containerApiRepo = containerApiRepo; this.containerRepo = containerRepo; + this.containerMounts = containerMounts; this.dataStore = dataStore; } - public ContainerManager(String containerName, String containerCommand, OCIDataStore dataStore) { + public ContainerManager(String containerName, String containerCommand, List<String> containerMounts, OCIDataStore dataStore) { this.containerName = containerName; this.containerImage = dataStore.getContainerImage(containerName); this.containerTag = dataStore.getContainerTag(containerName); this.containerApiRepo = dataStore.getContainerApiRepo(containerName); this.containerRepo = dataStore.getContainerRepo(containerName); this.containerCommand = containerCommand; + this.containerMounts = containerMounts; this.dataStore = dataStore; } @@ -135,6 +139,14 @@ public class ContainerManager { } bwrapCommand.add("--bind "+containerDirectory+"/root / --chdir /"); // Bind the root to / inside the bwrap namespace + + if (this.containerMounts != null) { + for (String mount : containerMounts) { + bwrapCommand.add("--bind "+mount.split(":")[0]+" "+mount.split(":")[1]); // Bind the mount to the destination specified in the config file + } + } + + bwrapCommand.add("--ro-bind /etc/resolv.conf /etc/resolv.conf"); // Bind the host resolv.conf to the container bwrapCommand.add("--share-net"); // Share the network namespace bwrapCommand.add("--unshare-uts --hostname "+ (!hostname.isBlank() ? hostname : this.containerName+"-"+this.containerImage)); // Unshare the UTS namespace and set the hostname bwrapCommand.add("/bin/sh -c '"+(this.containerCommand != null ? this.containerCommand : cmd)+"'"); // Run the command specified in the config file or the command specified in the constructor |