Search in sources :

Example 1 with TemplatedResource

use of com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource in project halyard by spinnaker.

the class KubernetesV2Service method getNamespaceYaml.

default String getNamespaceYaml(GenerateService.ResolvedConfiguration resolvedConfiguration) {
    ServiceSettings settings = resolvedConfiguration.getServiceSettings(getService());
    String name = getNamespace(settings);
    TemplatedResource namespace = new JinjaJarResource("/kubernetes/manifests/namespace.yml");
    namespace.addBinding("name", name);
    return namespace.toString();
}
Also used : JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) HasServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings) KubernetesSharedServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)

Example 2 with TemplatedResource

use of com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource in project halyard by spinnaker.

the class KubernetesV2Utils method createSecret.

public static String createSecret(KubernetesAccount account, String namespace, String name, List<SecretMountPair> files) {
    Map<String, String> contentMap = new HashMap<>();
    for (SecretMountPair pair : files) {
        String contents;
        try {
            contents = new String(Base64.getEncoder().encode(IOUtils.toByteArray(new FileInputStream(pair.getContents()))));
        } catch (IOException e) {
            throw new HalException(Problem.Severity.FATAL, "Failed to read required config file: " + pair.getContents().getAbsolutePath() + ": " + e.getMessage(), e);
        }
        contentMap.put(pair.getName(), contents);
    }
    name = name + "-" + Math.abs(contentMap.hashCode());
    TemplatedResource secret = new JinjaJarResource("/kubernetes/manifests/secret.yml");
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("files", contentMap);
    bindings.put("name", name);
    bindings.put("namespace", namespace);
    secret.extendBindings(bindings);
    apply(account, secret.toString());
    return name;
}
Also used : HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) JinjaJarResource(com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream)

Example 3 with TemplatedResource

use of com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource in project halyard by spinnaker.

the class LocalDebianServiceProvider method getInstallCommand.

@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands) {
    Map<String, Object> bindings = new HashMap<>();
    List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
    List<String> upstartNames = getLocalServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((LocalDebianService) i).getUpstartServiceName()).filter(Objects::nonNull).collect(Collectors.toList());
    List<String> systemdServiceConfigs = upstartNames.stream().map(n -> n + ".service").collect(Collectors.toList());
    List<String> serviceInstalls = serviceTypes.stream().map(t -> installCommands.get(t.getCanonicalName())).collect(Collectors.toList());
    TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh");
    bindings.put("services", Strings.join(upstartNames, " "));
    bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " "));
    String upstartInit = resource.setBindings(bindings).toString();
    BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName());
    resource = new StringReplaceJarResource("/debian/install.sh");
    bindings = new HashMap<>();
    bindings.put("prepare-environment", "true");
    bindings.put("install-redis", "true");
    bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
    bindings.put("install-commands", String.join("\n", serviceInstalls));
    bindings.put("service-action", "restart");
    bindings.put("upstart-init", upstartInit);
    return resource.setBindings(bindings).toString();
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) java.util(java.util) ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) Autowired(org.springframework.beans.factory.annotation.Autowired) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) LocalServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.LocalServiceProvider) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource)

Example 4 with TemplatedResource

use of com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource in project halyard by spinnaker.

the class LocalGitDeckService method commitWrapperScripts.

@Override
public void commitWrapperScripts() {
    Map<String, Object> bindings = new HashMap<>();
    bindings.put("git-root", getGitRoot());
    bindings.put("scripts-dir", getScriptsDir());
    bindings.put("artifact", getArtifact().getName());
    bindings.put("start-command", getStartCommand());
    TemplatedResource scriptResource = new StringReplaceJarResource("/git/deck-start.sh");
    scriptResource.setBindings(bindings);
    String script = scriptResource.toString();
    new RemoteAction().setScript(script).commitScript(Paths.get(getScriptsDir(), getArtifact().getName() + "-start.sh"));
    scriptResource = new StringReplaceJarResource("/git/stop.sh");
    scriptResource.setBindings(bindings);
    script = scriptResource.toString();
    new RemoteAction().setScript(script).commitScript(Paths.get(getScriptsDir(), getArtifact().getName() + "-stop.sh"));
}
Also used : StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) HashMap(java.util.HashMap) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction)

Example 5 with TemplatedResource

use of com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource in project halyard by spinnaker.

the class BakeDebianService method installArtifactCommand.

default String installArtifactCommand(DeploymentDetails deploymentDetails) {
    Map<String, Object> bindings = new HashMap<>();
    String artifactName = getArtifact().getName();
    bindings.put("artifact", artifactName);
    bindings.put("version", deploymentDetails.getArtifactVersion(artifactName));
    // pin as well as install at a particular version to ensure `apt-get uprade` doesn't accidentally upgrade to `nightly`
    TemplatedResource pinResource = new StringReplaceJarResource("/debian/pin.sh");
    TemplatedResource installResource = new StringReplaceJarResource("/debian/install-component.sh");
    String ensureStopped = String.join("\n", "set +e", "service " + getUpstartServiceName() + " stop", "set -e");
    pinResource.setBindings(bindings);
    installResource.setBindings(bindings);
    return Strings.join("\n", pinResource, installResource, ensureStopped);
}
Also used : StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) HashMap(java.util.HashMap) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)

Aggregations

TemplatedResource (com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource)16 HashMap (java.util.HashMap)12 StringReplaceJarResource (com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource)11 RemoteAction (com.netflix.spinnaker.halyard.core.RemoteAction)6 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)5 GenerateService (com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService)5 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)5 Collectors (java.util.stream.Collectors)5 JinjaJarResource (com.netflix.spinnaker.halyard.core.resource.v1.JinjaJarResource)4 DeploymentDetails (com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails)4 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)4 Strings (io.fabric8.utils.Strings)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Component (org.springframework.stereotype.Component)4 ArtifactSourcesConfig (com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig)3 BillOfMaterials (com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials)3 HasServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.HasServiceSettings)3 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)3 KubernetesSharedServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.kubernetes.KubernetesSharedServiceSettings)3 LocalServiceProvider (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.LocalServiceProvider)3