aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/jshipit/JshipIT.java
blob: 30065a09c8dc8ea7e80c875e73836298fe4a7294 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package io.github.jshipit;

import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class JshipIT {

    public int finishedCount;
    public int downloadThreads;

    public JshipIT(String[] args) {
        DockerAPIHelper api = new DockerAPIHelper("registry.getcryst.al","crystal/misc", "docker", "latest");
        JsonNode manifest = null;

        System.out.println("API Token: " + api.getApiToken());
        try {
            manifest = api.fetchManifestJson();
        } catch (IOException e) {

        }

        System.out.println("Manifest: " + manifest);

        Path path = Path.of("./tmp_"+api.getImage()+"_"+api.getTag());
        try {
            Files.createDirectory(path);
        } catch (IOException e) {
            System.out.println("Failed to create directory: " + path);
            e.printStackTrace();
            return;
        }

        finishedCount = 0;
        downloadThreads = 0;

        JsonNode layers = manifest.get("layers");
        for (JsonNode layer : layers) {
            System.out.println("Layer: " + layer);
            try {
                api.fetchBlob(layer.get("digest").asText(), path.toString());
                downloadThreads = downloadThreads+1;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}