summaryrefslogtreecommitdiffstats
path: root/config-provisioning/src/main/java/com/yahoo/config/provision/DockerImage.java
blob: 2c6c9d8241918d3d72efa7e1eb7fc745c414b540 (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
// Copyright 2016 Yahoo Inc. 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 {

    public static final DockerImage defaultImage = new DockerImage("docker-registry.ops.yahoo.com:4443/vespa/ci");

    private final String name;

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

    /** Get Docker image tag as version */
    public Version tagAsVersion() {
        String[] parts = toString().split(":");
        if (parts.length < 2) {
            throw new IllegalArgumentException("Could not parse tag from Docker image '" + toString() + "'");
        }
        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());
    }

    @Override
    public String toString() {
        return name;
    }
}