Search in sources :

Example 1 with ContainerDefinition

use of com.amazonaws.services.ecs.model.ContainerDefinition in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilder method build.

public ContainerDefinition build() {
    final ElasticAgentProfileProperties elasticAgentProfileProperties = request.elasticProfile();
    final Integer memoryReservation = elasticAgentProfileProperties.platform() == LINUX ? elasticAgentProfileProperties.getReservedMemory() : null;
    return new ContainerDefinition().withName(taskName).withImage(image(elasticAgentProfileProperties.getImage())).withMemory(elasticAgentProfileProperties.getMaxMemory()).withMemoryReservation(memoryReservation).withEnvironment(environmentFrom()).withDockerLabels(labelsFrom()).withCommand(elasticAgentProfileProperties.getCommand()).withCpu(elasticAgentProfileProperties.getCpu()).withPrivileged(elasticAgentProfileProperties.platform() != WINDOWS && elasticAgentProfileProperties.isPrivileged()).withLogConfiguration(pluginSettings.logConfiguration());
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) ElasticAgentProfileProperties(com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)

Example 2 with ContainerDefinition

use of com.amazonaws.services.ecs.model.ContainerDefinition in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilderTest method shouldBuildContainerDefinitionWithPrivilegedModeOffEvenIfItIsSetToTrueForWindows.

@Test
void shouldBuildContainerDefinitionWithPrivilegedModeOffEvenIfItIsSetToTrueForWindows() {
    when(elasticAgentProfileProperties.getImage()).thenReturn("windowsservercore");
    when(elasticAgentProfileProperties.isPrivileged()).thenReturn(true);
    when(elasticAgentProfileProperties.platform()).thenReturn(WINDOWS);
    ContainerDefinitionBuilder builder = new ContainerDefinitionBuilder().withName("foo").pluginSettings(pluginSettings).createAgentRequest(createAgentRequest);
    final ContainerDefinition containerDefinition = builder.build();
    assertThat(containerDefinition.isPrivileged()).isFalse();
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) Test(org.junit.jupiter.api.Test)

Example 3 with ContainerDefinition

use of com.amazonaws.services.ecs.model.ContainerDefinition in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilderTest method shouldBuildContainerDefinitionPrivilegedModeOnForLinux.

@Test
void shouldBuildContainerDefinitionPrivilegedModeOnForLinux() {
    when(elasticAgentProfileProperties.getImage()).thenReturn("alpine");
    when(elasticAgentProfileProperties.isPrivileged()).thenReturn(true);
    when(elasticAgentProfileProperties.platform()).thenReturn(LINUX);
    ContainerDefinitionBuilder builder = new ContainerDefinitionBuilder().withName("foo").pluginSettings(pluginSettings).createAgentRequest(createAgentRequest);
    final ContainerDefinition containerDefinition = builder.build();
    assertThat(containerDefinition.isPrivileged()).isTrue();
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) Test(org.junit.jupiter.api.Test)

Example 4 with ContainerDefinition

use of com.amazonaws.services.ecs.model.ContainerDefinition in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilderTest method shouldBuildContainerDefinitionPrivilegedModeOffForLinux.

@Test
void shouldBuildContainerDefinitionPrivilegedModeOffForLinux() {
    when(elasticAgentProfileProperties.getImage()).thenReturn("alpine");
    when(elasticAgentProfileProperties.isPrivileged()).thenReturn(false);
    when(elasticAgentProfileProperties.platform()).thenReturn(LINUX);
    ContainerDefinitionBuilder builder = new ContainerDefinitionBuilder().withName("foo").pluginSettings(pluginSettings).createAgentRequest(createAgentRequest);
    final ContainerDefinition containerDefinition = builder.build();
    assertThat(containerDefinition.isPrivileged()).isFalse();
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) Test(org.junit.jupiter.api.Test)

Example 5 with ContainerDefinition

use of com.amazonaws.services.ecs.model.ContainerDefinition in project gocd-ecs-elastic-agent by gocd.

the class ContainerDefinitionBuilderTest method shouldBuildContainerDefinitionWithLabels.

@Test
void shouldBuildContainerDefinitionWithLabels() {
    when(elasticAgentProfileProperties.getImage()).thenReturn("alpine");
    when(createAgentRequest.environment()).thenReturn("some-environment");
    when(elasticAgentProfileProperties.toJson()).thenReturn("elastic-profile-in-json");
    when(jobIdentifier.toJson()).thenReturn("job-identifier-in-json");
    ContainerDefinitionBuilder builder = new ContainerDefinitionBuilder().withName("foo").pluginSettings(pluginSettings).withServerId("gocd-server-id").createAgentRequest(createAgentRequest);
    final ContainerDefinition containerDefinition = builder.build();
    assertThat(containerDefinition.getDockerLabels()).containsEntry(CREATED_BY_LABEL_KEY, PLUGIN_ID).containsEntry(ENVIRONMENT_LABEL_KEY, "some-environment").containsEntry(CONFIGURATION_LABEL_KEY, "elastic-profile-in-json").containsEntry(LABEL_JOB_IDENTIFIER, "job-identifier-in-json").containsEntry(LABEL_SERVER_ID, "gocd-server-id");
}
Also used : ContainerDefinition(com.amazonaws.services.ecs.model.ContainerDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

ContainerDefinition (com.amazonaws.services.ecs.model.ContainerDefinition)9 Test (org.junit.jupiter.api.Test)7 ElasticAgentProfileProperties (com.thoughtworks.gocd.elasticagent.ecs.domain.ElasticAgentProfileProperties)2 Instance (com.amazonaws.services.ec2.model.Instance)1 ContainerInstance (com.amazonaws.services.ecs.model.ContainerInstance)1 KeyValuePair (com.amazonaws.services.ecs.model.KeyValuePair)1 LogConfiguration (com.amazonaws.services.ecs.model.LogConfiguration)1 LOG (com.thoughtworks.gocd.elasticagent.ecs.ECSElasticPlugin.LOG)1 ContainerInstanceHelper (com.thoughtworks.gocd.elasticagent.ecs.aws.ContainerInstanceHelper)1 EC2Config (com.thoughtworks.gocd.elasticagent.ecs.aws.EC2Config)1 ContainerInstanceMatcher (com.thoughtworks.gocd.elasticagent.ecs.aws.matcher.ContainerInstanceMatcher)1 InstanceMatcher (com.thoughtworks.gocd.elasticagent.ecs.aws.matcher.InstanceMatcher)1 PENDING (com.thoughtworks.gocd.elasticagent.ecs.domain.EC2InstanceState.PENDING)1 RUNNING (com.thoughtworks.gocd.elasticagent.ecs.domain.EC2InstanceState.RUNNING)1 Platform (com.thoughtworks.gocd.elasticagent.ecs.domain.Platform)1 WINDOWS (com.thoughtworks.gocd.elasticagent.ecs.domain.Platform.WINDOWS)1 PluginSettings (com.thoughtworks.gocd.elasticagent.ecs.domain.PluginSettings)1 Util (com.thoughtworks.gocd.elasticagent.ecs.utils.Util)1 Util.toMap (com.thoughtworks.gocd.elasticagent.ecs.utils.Util.toMap)1 MessageFormat.format (java.text.MessageFormat.format)1