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());
}
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();
}
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();
}
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();
}
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");
}
Aggregations