summaryrefslogtreecommitdiffstats
path: root/vespa-maven-plugin/src/main/java/ai/vespa/hosted/plugin/DeployMojo.java
blob: 7028e41c2d7c62b70446e345bbf438902f0e57b7 (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
51
52
53
54
55
56
57
58
59
60
package ai.vespa.hosted.plugin;

import ai.vespa.hosted.api.Deployment;
import ai.vespa.hosted.api.DeploymentResult;
import com.yahoo.config.provision.zone.ZoneId;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.nio.file.Paths;

/**
 * Deploys a Vespa application package to the hosted Vespa API.
 *
 * @author jonmv
 */
@Mojo(name = "deploy")
public class DeployMojo extends AbstractVespaMojo {

    @Parameter(property = "applicationZip")
    private String applicationZip;

    @Parameter(property = "vespaVersion")
    private String vespaVersion;

    @Parameter(property = "ignoreValidationErrors")
    private String ignoreValidationErrors;

    @Parameter(property = "environment")
    private String environment;

    @Parameter(property = "region")
    private String region;

    @Parameter(property = "repository")
    private String repository;

    @Parameter(property = "branch")
    private String branch;

    @Parameter(property = "commit")
    private String commit;

    @Parameter(property = "build")
    private Long build;

    @Override
    protected void doExecute() {
        Deployment deployment = build == null
                ? Deployment.ofPackage(Paths.get(firstNonBlank(applicationZip, projectPathOf("target", "application.zip"))))
                : Deployment.ofReference(repository, branch, commit, build);
        if ("true".equalsIgnoreCase(ignoreValidationErrors)) deployment = deployment.ignoringValidationErrors(); // TODO unused, GC or fix.
        if (vespaVersion != null) deployment = deployment.atVersion(vespaVersion);

        ZoneId zone = environment == null || region == null ? controller.devZone() : ZoneId.from(environment, region);

        DeploymentResult result = controller.deploy(deployment, id, zone);
        System.out.println("Success: " + result.message());
    }

}