Exemplo n.º 1
0
    public static void Run()
    {
        var containers = new ContainerAPI();

        containers.Begin();
        VagrantTest(containers);
        ContainerTest(containers);
        containers.Stop();
    }
Exemplo n.º 2
0
    private static void ContainerTest(ContainerAPI containers)
    {
        var dockerfile1 =
            "FROM busybox\n" +
            "CMD [\"sh\"]";

        var customId = "1";
        var code     = containers.CreateContainer(customId, null, dockerfile1, new Array <string>());

        if (code == (int)Errors.OK)
        {
            GD.Print("[DIAGNOSTICS B] [OK] Container created successfully.");
        }
        else
        {
            GD.PrintErr(
                $"[DIAGNOSTICS B] [ERROR] Container failed to create, with error: {(Errors) code} (Note that for now, BuildError means literally anything from failed SSH to bad Dockerfile)");
        }


        code = containers.StartContainer(customId);

        if (code == (int)Errors.OK)
        {
            GD.Print("[DIAGNOSTICS B] [OK] Container started successfully.");
        }
        else
        {
            GD.PrintErr($"[DIAGNOSTICS B] [ERROR] Container failed to start, with error: {(Errors) code}");
        }

        code = containers.CreateTTY(customId, out var stdin, out var stdout);

        if (code == (int)Errors.OK)
        {
            GD.Print("[DIAGNOSTICS B] [OK] Successfully created TTY.");
        }
        else
        {
            GD.PrintErr($"[DIAGNOSTICS B] [ERROR] Container failed to create TTY, with error: {(Errors) code}");
        }

        stdin.WriteLine("echo hello");
        stdin.Close();
        var received = stdout.ReadLine();

        if (received == "hello")
        {
            GD.Print("[DIAGNOSTICS B] [OK] Container responding");
        }
        else
        {
            GD.PrintErr("[DIAGNOSTICS B] [ERROR] Container not responding");
        }
    }
Exemplo n.º 3
0
    private static void VagrantTest(ContainerAPI containers)
    {
        var testingOutput = containers.VagrantDebugExecute("echo hello");

        if (testingOutput.StartsWith("hello")) // There might be some SSH output after this
        {
            GD.Print("[DIAGNOSTICS B] [OK] Vagrant box started successfully");
        }
        else
        {
            GD.PrintErr("[DIAGNOSTICS B] [ERROR] Vagrant box failed to start!");
        }
    }
Exemplo n.º 4
0
    private static void _begin()
    {
        if (ContainerApi != null)
        {
            return;
        }

        if (ProjectSettings.HasSetting("global/Diagnostics") && (bool)ProjectSettings.GetSetting("global/Diagnostics"))
        {
            Diagnostics.Run();
        }

        ContainerApi = new ContainerAPI();
        ContainerApi.Begin();
    }
Exemplo n.º 5
0
 public override void _ExitTree()
 {
     ContainerApi.Stop();
     ContainerApi = null;
     Attached     = false;
 }