Search in sources :

Example 16 with Profile

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile in project halyard by spinnaker.

the class LocalService method stageProfilesCommand.

default String stageProfilesCommand(DeploymentDetails details, GenerateService.ResolvedConfiguration resolvedConfiguration) {
    Map<String, Profile> profiles = resolvedConfiguration.getProfilesForService(getService().getType());
    List<String> allCommands = new ArrayList<>();
    for (Map.Entry<String, Profile> entry : profiles.entrySet()) {
        Profile profile = entry.getValue();
        String source = profile.getStagedFile(getSpinnakerStagingPath(details.getDeploymentName()));
        String dest = profile.getOutputFile();
        String user = profile.getUser();
        String group = profile.getGroup();
        allCommands.add(String.format("mkdir -p $(dirname %s)", dest));
        allCommands.add(String.format("cp -p %s %s", source, dest));
        allCommands.add(String.format("chown %s:%s %s", user, group, dest));
        allCommands.add(String.format("chmod 640 %s", dest));
        for (String requiredFile : profile.getRequiredFiles()) {
            allCommands.add(String.format("chown %s:%s %s", user, group, requiredFile));
            allCommands.add(String.format("chmod 640 %s", requiredFile));
        }
        if (profile.isExecutable()) {
            allCommands.add(String.format("chmod +x %s", dest));
        }
    }
    return Strings.join(allCommands, "\n");
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Example 17 with Profile

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile in project halyard by spinnaker.

the class GoogleDistributedService method stageProfiles.

@Override
default List<ConfigSource> stageProfiles(AccountDeploymentDetails<GoogleAccount> details, ResolvedConfiguration resolvedConfiguration) {
    String deploymentName = details.getDeploymentName();
    SpinnakerRuntimeSettings runtimeSettings = resolvedConfiguration.getRuntimeSettings();
    SpinnakerService thisService = getService();
    ServiceSettings thisServiceSettings = resolvedConfiguration.getServiceSettings(thisService);
    Map<String, String> env = new HashMap<>();
    Integer version = getRunningServiceDetails(details, runtimeSettings).getLatestEnabledVersion();
    if (version == null) {
        version = 0;
    } else {
        version++;
    }
    List<ConfigSource> configSources = new ArrayList<>();
    String stagingPath = getSpinnakerStagingPath(deploymentName);
    GoogleVaultServerService vaultService = getVaultServerService();
    VaultServerService.Vault vault = vaultService.connectToPrimaryService(details, runtimeSettings);
    for (SidecarService sidecarService : getSidecars(runtimeSettings)) {
        for (Profile profile : sidecarService.getSidecarProfiles(resolvedConfiguration, thisService)) {
            if (profile == null) {
                throw new HalException(Problem.Severity.FATAL, "Service " + sidecarService.getService().getCanonicalName() + " is required but was not supplied for deployment.");
            }
            String secretName = secretName(profile.getName(), version);
            String mountPoint = Paths.get(profile.getOutputFile()).toString();
            Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
            VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
            secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
            configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
        }
    }
    Map<String, Profile> serviceProfiles = resolvedConfiguration.getProfilesForService(thisService.getType());
    Set<String> requiredFiles = new HashSet<>();
    for (Map.Entry<String, Profile> entry : serviceProfiles.entrySet()) {
        Profile profile = entry.getValue();
        requiredFiles.addAll(profile.getRequiredFiles());
        env.putAll(profile.getEnv());
        String mountPoint = profile.getOutputFile();
        String secretName = secretName("profile-" + profile.getName(), version);
        Path stagedFile = Paths.get(profile.getStagedFile(stagingPath));
        VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(stagedFile.toFile(), mountPoint);
        secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
        configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    }
    for (String file : requiredFiles) {
        String mountPoint = Paths.get(file).toString();
        String secretName = secretName("dependencies-" + file, version);
        VaultConfigMount vaultConfigMount = VaultConfigMount.fromLocalFile(Paths.get(file).toFile(), mountPoint);
        secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
        configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    }
    env.putAll(thisServiceSettings.getEnv());
    String envSourceFile = env.entrySet().stream().reduce("", (s, e) -> String.format("%s\n%s=%s", s, e.getKey(), e.getValue()), (s1, s2) -> String.join("\n", s1, s2));
    String mountPoint = getEnvFile();
    String secretName = secretName("env", version);
    VaultConfigMount vaultConfigMount = VaultConfigMount.fromString(envSourceFile, mountPoint);
    secretName = vaultService.writeVaultConfig(deploymentName, vault, secretName, vaultConfigMount);
    configSources.add(new ConfigSource().setId(secretName).setMountPath(mountPoint));
    return configSources;
}
Also used : Path(java.nio.file.Path) SidecarService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.SidecarService) HashMap(java.util.HashMap) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) ServiceSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings) ArrayList(java.util.ArrayList) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile) ConfigSource(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource) Map(java.util.Map) HashMap(java.util.HashMap) VaultServerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.VaultServerService) VaultConfigMount(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.distributed.VaultConfigMount) HashSet(java.util.HashSet)

Example 18 with Profile

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile in project halyard by spinnaker.

the class GenerateService method mergeProfilesAndPreserveProperties.

private void mergeProfilesAndPreserveProperties(Map<String, Profile> existingProfiles, Map<String, Profile> newProfiles) {
    for (Map.Entry<String, Profile> entry : newProfiles.entrySet()) {
        String name = entry.getKey();
        Profile newProfile = entry.getValue();
        if (existingProfiles.containsKey(name)) {
            Profile existingProfile = existingProfiles.get(name);
            newProfile.assumeMetadata(existingProfile);
        }
        existingProfiles.put(name, newProfile);
    }
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Example 19 with Profile

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile in project halyard by spinnaker.

the class ClouddriverBootstrapProfileFactory method setProfile.

@Override
@SuppressWarnings("unchecked")
protected void setProfile(Profile profile, DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    super.setProfile(profile, deploymentConfiguration, endpoints);
    DeploymentEnvironment deploymentEnvironment = deploymentConfiguration.getDeploymentEnvironment();
    if (deploymentEnvironment.getType() != DeploymentEnvironment.DeploymentType.Distributed) {
        throw new IllegalStateException("There is no need to produce a bootstrapping clouddriver for a non-remote deployment of Spinnaker. This is a bug.");
    }
    // We need to make modifications to this deployment configuration, but can't use helpful objects
    // like the accountService on a clone. Therefore, we'll make the modifications in place and
    // restore to the original state when the modifications are written out.
    Providers originalProviders = deploymentConfiguration.getProviders().cloneNode(Providers.class);
    Providers modifiedProviders = deploymentConfiguration.getProviders();
    String deploymentName = deploymentConfiguration.getName();
    String bootstrapAccountName = deploymentEnvironment.getAccountName();
    Account bootstrapAccount = accountService.getAnyProviderAccount(deploymentName, bootstrapAccountName);
    bootstrapAccount.makeBootstrappingAccount(artifactSourcesConfig);
    Provider bootstrapProvider = (Provider) bootstrapAccount.getParent();
    disableAllProviders(modifiedProviders);
    bootstrapProvider.setEnabled(true);
    bootstrapProvider.setAccounts(Collections.singletonList(bootstrapAccount));
    if (bootstrapAccount instanceof ContainerAccount) {
        ContainerAccount containerAccount = (ContainerAccount) bootstrapAccount;
        List<DockerRegistryAccount> bootstrapRegistries = containerAccount.getDockerRegistries().stream().map(ref -> (DockerRegistryAccount) accountService.getProviderAccount(deploymentName, DOCKER_REGISTRY, ref.getAccountName())).collect(Collectors.toList());
        DockerRegistryProvider dockerProvider = modifiedProviders.getDockerRegistry();
        dockerProvider.setEnabled(true);
        dockerProvider.setAccounts(bootstrapRegistries);
    }
    if (bootstrapAccount instanceof SupportsConsul) {
        SupportsConsul consulAccount = (SupportsConsul) bootstrapAccount;
        ConsulConfig config = consulAccount.getConsul();
        if (config == null) {
            config = new ConsulConfig();
            consulAccount.setConsul(config);
        }
        consulAccount.getConsul().setEnabled(true);
    } else {
        log.warn("Attempting to perform a distributed deployment to account \"" + bootstrapAccount.getName() + "\" without a discovery mechanism");
    }
    List<String> files = backupRequiredFiles(modifiedProviders, deploymentConfiguration.getName());
    profile.appendContents(yamlToString(modifiedProviders)).appendContents("services.fiat.enabled: false").appendContents(profile.getBaseContents()).setRequiredFiles(files);
    deploymentConfiguration.setProviders(originalProviders);
}
Also used : ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) ConfigNotFoundException(com.netflix.spinnaker.halyard.config.error.v1.ConfigNotFoundException) NodeIterator(com.netflix.spinnaker.halyard.config.model.v1.node.NodeIterator) Autowired(org.springframework.beans.factory.annotation.Autowired) SpinnakerArtifact(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerArtifact) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) ProviderService(com.netflix.spinnaker.halyard.config.services.v1.ProviderService) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) ConsulConfig(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) DeploymentConfiguration(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) Collectors(java.util.stream.Collectors) SupportsConsul(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.SupportsConsul) ConfigProblemBuilder(com.netflix.spinnaker.halyard.config.problem.v1.ConfigProblemBuilder) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) AccountService(com.netflix.spinnaker.halyard.config.services.v1.AccountService) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) Problem(com.netflix.spinnaker.halyard.core.problem.v1.Problem) Optional(java.util.Optional) Collections(java.util.Collections) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) Account(com.netflix.spinnaker.halyard.config.model.v1.node.Account) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) DeploymentEnvironment(com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentEnvironment) DockerRegistryAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryAccount) ConsulConfig(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.ConsulConfig) Providers(com.netflix.spinnaker.halyard.config.model.v1.node.Providers) Provider(com.netflix.spinnaker.halyard.config.model.v1.node.Provider) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider) ContainerAccount(com.netflix.spinnaker.halyard.config.model.v1.providers.containers.ContainerAccount) SupportsConsul(com.netflix.spinnaker.halyard.config.model.v1.providers.consul.SupportsConsul) DockerRegistryProvider(com.netflix.spinnaker.halyard.config.model.v1.providers.dockerRegistry.DockerRegistryProvider)

Example 20 with Profile

use of com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile in project halyard by spinnaker.

the class Front50Service method getProfiles.

@Override
public List<Profile> getProfiles(DeploymentConfiguration deploymentConfiguration, SpinnakerRuntimeSettings endpoints) {
    List<Profile> profiles = super.getProfiles(deploymentConfiguration, endpoints);
    String filename = "front50.yml";
    String path = Paths.get(getConfigOutputPath(), filename).toString();
    Profile profile = front50ProfileFactory.getProfile(filename, path, deploymentConfiguration, endpoints);
    profiles.add(profile);
    return profiles;
}
Also used : Profile(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)

Aggregations

Profile (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.profile.Profile)23 ArrayList (java.util.ArrayList)9 SpinnakerRuntimeSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings)8 Map (java.util.Map)8 ServiceSettings (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ServiceSettings)6 HashMap (java.util.HashMap)6 DeploymentConfiguration (com.netflix.spinnaker.halyard.config.model.v1.node.DeploymentConfiguration)5 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)5 Collections (java.util.Collections)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ArtifactService (com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService)3 ConfigSource (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.ConfigSource)3 SpinnakerService (com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService)3 File (java.io.File)3 Paths (java.nio.file.Paths)3 HashSet (java.util.HashSet)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 KubernetesUtil (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil)2 KubernetesImageDescription (com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.description.servergroup.KubernetesImageDescription)2