mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
fix(ecs): round-trip command and entryPoint on container definitions (#2446)
RegisterTaskDefinition already parsed containerDefinitions[].command and .entryPoint, and EcsContainerManager honoured both when launching the container — but containerDefinitionNode never rendered them, so DescribeTaskDefinition silently omitted both keys. The practical consequence is data loss on the describe -> register round trip that tooling relies on to cut a new revision: the overrides disappear from the JSON and the new revision falls back to the image's default entrypoint. The container still starts, so nothing surfaces until whatever the entrypoint was meant to do turns out not to have happened. Serialize both sparsely, matching the surrounding portMappings / mountPoints style, so definitions that set neither stay byte-identical. Tests: a parse+serialize unit test in the EcsJsonHandlerVolumesTest style (round trip plus an absent-stays-absent guard), and an end-to-end register -> describe case in EcsIntegrationTest. Refs #2445
This commit is contained in:
1 parent
257e004600
commit
5c45c146c7
3 files changed
+172
No files matched your search
@@ -1035,6 +1035,18 @@ public class EcsJsonHandler {
|
||||
n.set("portMappings", pms);
|
||||
}
|
||||
|
||||
if (def.getEntryPoint() != null && !def.getEntryPoint().isEmpty()) {
|
||||
ArrayNode entryPoint = objectMapper.createArrayNode();
|
||||
def.getEntryPoint().forEach(entryPoint::add);
|
||||
n.set("entryPoint", entryPoint);
|
||||
}
|
||||
|
||||
if (def.getCommand() != null && !def.getCommand().isEmpty()) {
|
||||
ArrayNode command = objectMapper.createArrayNode();
|
||||
def.getCommand().forEach(command::add);
|
||||
n.set("command", command);
|
||||
}
|
||||
|
||||
if (def.getEnvironment() != null && !def.getEnvironment().isEmpty()) {
|
||||
ArrayNode envArr = objectMapper.createArrayNode();
|
||||
for (KeyValuePair kv : def.getEnvironment()) {
|
||||
|
||||
@@ -1186,4 +1186,57 @@ class EcsIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* A container definition registered with {@code entryPoint} and {@code command} must echo
|
||||
* both back on DescribeTaskDefinition. Without this, re-registering a task definition from
|
||||
* describe output silently drops the overrides and the new revision falls back to the
|
||||
* image's default entrypoint.
|
||||
*/
|
||||
@Test
|
||||
@Order(70)
|
||||
void registerAndDescribeTaskDefinitionRoundTripsCommandAndEntryPoint() {
|
||||
String arn = ecs("RegisterTaskDefinition")
|
||||
.body("""
|
||||
{
|
||||
"family": "entrypoint-roundtrip",
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "app",
|
||||
"image": "alpine:latest",
|
||||
"essential": true,
|
||||
"entryPoint": ["/bin/sh", "-c"],
|
||||
"command": ["fetch-ca && exec agent --serve"]
|
||||
},
|
||||
{
|
||||
"name": "sidecar",
|
||||
"image": "alpine:latest",
|
||||
"essential": false
|
||||
}
|
||||
]
|
||||
}
|
||||
""")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.containerDefinitions[0].entryPoint", contains("/bin/sh", "-c"))
|
||||
.body("taskDefinition.containerDefinitions[0].command", contains("fetch-ca && exec agent --serve"))
|
||||
.extract()
|
||||
.path("taskDefinition.taskDefinitionArn");
|
||||
|
||||
ecs("DescribeTaskDefinition")
|
||||
.body("""
|
||||
{"taskDefinition": "%s"}
|
||||
""".formatted(arn))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("taskDefinition.containerDefinitions[0].entryPoint", contains("/bin/sh", "-c"))
|
||||
.body("taskDefinition.containerDefinitions[0].command", contains("fetch-ca && exec agent --serve"))
|
||||
// A container that set neither keeps both keys absent, as real AWS does.
|
||||
.body("taskDefinition.containerDefinitions[1]", not(hasKey("entryPoint")))
|
||||
.body("taskDefinition.containerDefinitions[1]", not(hasKey("command")));
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package io.github.hectorvent.floci.services.ecs;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Unit tests for the RegisterTaskDefinition JSON wire path in {@link EcsJsonHandler}:
|
||||
* per-container {@code command} and {@code entryPoint} must be parsed from the request,
|
||||
* stored on the container definition, and serialized back in the response.
|
||||
*
|
||||
* <p>Both fields were already parsed and honoured when launching the container
|
||||
* ({@code EcsContainerManager}), but never rendered by {@code containerDefinitionNode} — so
|
||||
* re-registering a task definition from DescribeTaskDefinition output silently dropped them
|
||||
* and the new revision fell back to the image's default entrypoint.
|
||||
*
|
||||
* <p>{@link EcsService} is mocked to echo the parsed container definitions back inside a
|
||||
* task definition, so the test exercises parse + serialize without any Docker/Quarkus context.
|
||||
*/
|
||||
class EcsJsonHandlerCommandEntryPointTest {
|
||||
|
||||
private EcsService service;
|
||||
private ObjectMapper objectMapper;
|
||||
private EcsJsonHandler handler;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
objectMapper = new ObjectMapper();
|
||||
service = mock(EcsService.class);
|
||||
// Echo the parsed container definitions (arg index 1) back inside a task definition.
|
||||
when(service.registerTaskDefinition(anyString(), any(), any(), any(), any(), any(), any(), any(), any(), anyString()))
|
||||
.thenAnswer(inv -> {
|
||||
TaskDefinition td = new TaskDefinition();
|
||||
td.setFamily(inv.getArgument(0));
|
||||
td.setRevision(1);
|
||||
td.setStatus("ACTIVE");
|
||||
td.setContainerDefinitions(inv.getArgument(1, List.class));
|
||||
return td;
|
||||
});
|
||||
|
||||
handler = new EcsJsonHandler(service, objectMapper);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerTaskDefinitionRoundTripsCommandAndEntryPoint() throws Exception {
|
||||
String requestJson = """
|
||||
{
|
||||
"family": "entrypoint-family",
|
||||
"containerDefinitions": [
|
||||
{
|
||||
"name": "app",
|
||||
"image": "alpine:latest",
|
||||
"entryPoint": ["/bin/sh", "-c"],
|
||||
"command": ["fetch-ca && exec agent --serve"]
|
||||
}
|
||||
]
|
||||
}
|
||||
""";
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
|
||||
JsonNode container = objectMapper.valueToTree(response.getEntity())
|
||||
.path("taskDefinition").path("containerDefinitions").get(0);
|
||||
|
||||
JsonNode entryPoint = container.path("entryPoint");
|
||||
assertTrue(entryPoint.isArray() && entryPoint.size() == 2, "entryPoint expected with two elements");
|
||||
assertEquals("/bin/sh", entryPoint.get(0).asText());
|
||||
assertEquals("-c", entryPoint.get(1).asText());
|
||||
|
||||
JsonNode command = container.path("command");
|
||||
assertTrue(command.isArray() && command.size() == 1, "command expected with one element");
|
||||
assertEquals("fetch-ca && exec agent --serve", command.get(0).asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void containerDefinitionOmitsCommandAndEntryPointWhenNotProvided() throws Exception {
|
||||
String requestJson = """
|
||||
{
|
||||
"family": "plain-family",
|
||||
"containerDefinitions": [
|
||||
{"name": "app", "image": "alpine:latest"}
|
||||
]
|
||||
}
|
||||
""";
|
||||
JsonNode request = objectMapper.readTree(requestJson);
|
||||
|
||||
Response response = handler.handle("RegisterTaskDefinition", request, "us-east-1");
|
||||
JsonNode container = objectMapper.valueToTree(response.getEntity())
|
||||
.path("taskDefinition").path("containerDefinitions").get(0);
|
||||
|
||||
// Sparse serialization: absent input stays absent on the response, as real AWS does.
|
||||
assertTrue(container.path("entryPoint").isMissingNode(), "entryPoint must stay absent");
|
||||
assertTrue(container.path("command").isMissingNode(), "command must stay absent");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user