aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/jshipit/JshipIT.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/jshipit/JshipIT.java')
-rwxr-xr-xsrc/main/java/io/github/jshipit/JshipIT.java71
1 files changed, 60 insertions, 11 deletions
diff --git a/src/main/java/io/github/jshipit/JshipIT.java b/src/main/java/io/github/jshipit/JshipIT.java
index 1383d48..9ba74d0 100755
--- a/src/main/java/io/github/jshipit/JshipIT.java
+++ b/src/main/java/io/github/jshipit/JshipIT.java
@@ -1,12 +1,11 @@
package io.github.jshipit;
import com.beust.jcommander.JCommander;
-import com.fasterxml.jackson.databind.JsonNode;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import com.beust.jcommander.Parameter;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
public class JshipIT {
@@ -15,34 +14,84 @@ public class JshipIT {
CommandStart commandStart = new CommandStart();
CommandCreate commandCreate = new CommandCreate();
CommandPull commandPull = new CommandPull();
+ CommandDelete commandDelete = new CommandDelete();
JCommander commands = JCommander.newBuilder()
.addCommand("create", commandCreate)
.addCommand("pull", commandPull)
.addCommand("start", commandStart)
.addCommand("shell", commandShell)
+ .addCommand("delete", commandDelete)
.build();
commands.parse(args);
- OCIDataStore dataStore = new OCIDataStore("./tmp");
+ OCIDataStore dataStore = new OCIDataStore(System.getenv("HOME") + "/.local/share/dataStore");
if (commands.getParsedCommand() == null) {
commands.usage();
System.exit(1);
} else if (commands.getParsedCommand().equals("create")) {
- ContainerManager containerManager = new ContainerManager(commandCreate.containerName, commandCreate.containerImage, commandCreate.containerTag, commandCreate.containerApiRepo, commandCreate.containerRepo, dataStore);
+ if (commandCreate.containerName == null) {
+ System.out.println("Container name is required");
+ System.exit(1);
+ }
+ List<String> image = new ArrayList<String>(Arrays.asList(commandCreate.containerImage.split("/")));
+ String containerImage = image.get(image.size() - 1).split(":")[0];
+ String apiRepo = image.get(0);
+ image.remove(0);
+ image.remove(image.size() - 1);
+ String containerRepo = String.join("/", image);
+
+ switch (apiRepo) {
+ case "docker.io":
+ apiRepo = "registry.docker.io";
+ break;
+ case "ghcr.io":
+ apiRepo = "ghcr.io";
+ break;
+ case "quay.io":
+ apiRepo = "quay.io";
+ break;
+ default:
+ break;
+ }
+
+
+ ContainerManager containerManager = new ContainerManager(commandCreate.containerName, containerImage, commandCreate.containerImage.split(":")[1], apiRepo, containerRepo, dataStore);
containerManager.createContainer();
} else if (commands.getParsedCommand().equals("pull")) {
- dataStore.createImage(commandPull.containerApiRepo, commandPull.containerRepo, commandPull.containerImage, commandPull.containerTag);
+
+ List<String> image = new ArrayList<String>(Arrays.asList(commandPull.containerImage.split("/")));
+ String containerImage = image.get(image.size() - 1).split(":")[0];
+ String apiRepo = image.get(0);
+ image.remove(0);
+ image.remove(image.size() - 1);
+ String containerRepo = String.join("/", image);
+
+ switch (apiRepo) {
+ case "docker.io":
+ apiRepo = "registry.docker.io";
+ break;
+ case "ghcr.io":
+ apiRepo = "ghcr.io";
+ break;
+ case "quay.io":
+ apiRepo = "quay.io";
+ break;
+ default:
+ break;
+ }
+ System.out.println("Pulling image " + containerImage + " from " + apiRepo + "/" + containerRepo);
+ dataStore.createImage(apiRepo, containerRepo, containerImage, commandPull.containerImage.split(":")[1]);
} else if (commands.getParsedCommand().equals("start")) {
ContainerManager containerManager = new ContainerManager(commandStart.containerName, commandStart.containerCommand, dataStore);
containerManager.runCommand();
} else if (commands.getParsedCommand().equals("shell")) {
ContainerManager containerManager = new ContainerManager(commandShell.containerName, "/bin/sh", dataStore); // A proper linux system should always have /bin/sh, skill issue if it doesn't
containerManager.runCommand();
+ } else if (commands.getParsedCommand().equals("delete")) {
+ ContainerManager containerManager = new ContainerManager(commandDelete.containerName, null, dataStore);
+ containerManager.deleteContainer();
}
-
-
-
}
} \ No newline at end of file