summaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
blob: c0e5e74f11069cdbe88adad69a454f6be4540c5c (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
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.provision;

import com.yahoo.component.Version;

/**
 * A Docker image.
 *
 * @author mpolden
 */
public class DockerImage {

    private final String name;

    public DockerImage(String name) {
        this.name = name;
    }

    /** Get Docker image tag as version */
    public Version tagAsVersion() {
        String[] parts = asString().split(":");
        if (parts.length < 2) {
            throw new IllegalArgumentException("Could not parse tag from Docker image '" + asString() + "'");
        }
        return Version.fromString(parts[parts.length - 1]);
    }

    /** Returns the Docker image tagged with the given version */
    public DockerImage withTag(Version version) {
        return new DockerImage(name + ":" + version.toFullString());
    }

    public String asString() {
        return name;
    }

}