feat(ecs): mount efsVolumeConfiguration task volumes as shared local volumes (#1569)

* feat(ecs): mount efsVolumeConfiguration task volumes as shared local volumes

ECS task definitions can declare EFS-backed volumes via
`efsVolumeConfiguration`, but Floci modelled only `host` volumes — an EFS
volume's mountPoint resolved to no source path and was skipped, so the
container launched without the mount. Terraform/ECS workloads that rely on
a shared EFS working directory (e.g. provisioner tasks reading/writing
/mnt/efs) had no filesystem at the mount path.

Parse and round-trip `efsVolumeConfiguration` (fileSystemId, rootDirectory,
transitEncryption, transitEncryptionPort, authorizationConfig) in
Register/DescribeTaskDefinition, and materialise an EFS volume as a shared
local Docker named volume `floci-efs-<fileSystemId>` mounted at the
container path (read-only/read-write per the mountPoint). Containers that
mount the same file system share persistent storage that survives task
restarts — the local stand-in for an EFS mount, since Docker cannot mount a
real EFS file system. This mirrors the documented LocalStack EFS-simulation
pattern at the ECS layer.

Tests cover the volume->named-volume resolution by access mode and the
efsVolumeConfiguration JSON round-trip.

* chore: re-trigger CI

Unrelated flaky CodeBuildTest.batchGetBuilds_eventuallySucceeds; root-cause
fix in floci-io/floci#1577.
This commit is contained in:
Alex Banna authored and GitHub committed 2026-06-25 22:42:34 -05:00
1 parent eea1e70d93
commit 56f846988f
7 files changed
+213 -17

No files matched your search

@@ -238,13 +238,21 @@ public class ContainerBuilder {
}
/**
* Adds a named volume mount.
* Adds a read-write named volume mount.
*/
public Builder withNamedVolume(String volumeName, String containerPath) {
return withNamedVolume(volumeName, containerPath, false);
}
/**
* Adds a named volume mount, read-only when {@code readOnly} is true.
*/
public Builder withNamedVolume(String volumeName, String containerPath, boolean readOnly) {
this.mounts.add(new Mount()
.withType(MountType.VOLUME)
.withSource(volumeName)
.withTarget(containerPath));
.withTarget(containerPath)
.withReadOnly(readOnly));
return this;
}
@@ -25,6 +25,7 @@ import io.github.hectorvent.floci.services.ecs.model.ServiceDeployment;
import io.github.hectorvent.floci.services.ecs.model.ServiceRevision;
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
import io.github.hectorvent.floci.services.ecs.model.TaskSet;
import io.github.hectorvent.floci.services.ecs.model.EfsVolumeConfiguration;
import io.github.hectorvent.floci.services.ecs.model.Volume;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -951,6 +952,31 @@ public class EcsJsonHandler {
host.put("sourcePath", v.hostSourcePath());
vNode.set("host", host);
}
if (v.efs() != null) {
EfsVolumeConfiguration e = v.efs();
ObjectNode efs = objectMapper.createObjectNode();
efs.put("fileSystemId", e.fileSystemId());
if (e.rootDirectory() != null) {
efs.put("rootDirectory", e.rootDirectory());
}
if (e.transitEncryption() != null) {
efs.put("transitEncryption", e.transitEncryption());
}
if (e.transitEncryptionPort() != null) {
efs.put("transitEncryptionPort", e.transitEncryptionPort());
}
if (e.accessPointId() != null || e.iam() != null) {
ObjectNode auth = objectMapper.createObjectNode();
if (e.accessPointId() != null) {
auth.put("accessPointId", e.accessPointId());
}
if (e.iam() != null) {
auth.put("iam", e.iam());
}
efs.set("authorizationConfig", auth);
}
vNode.set("efsVolumeConfiguration", efs);
}
vols.add(vNode);
}
n.set("volumes", vols);
@@ -1292,11 +1318,32 @@ public class EcsJsonHandler {
}
for (JsonNode item : node) {
String hostSourcePath = item.path("host").path("sourcePath").asText(null);
result.add(new Volume(item.path("name").asText(), hostSourcePath));
EfsVolumeConfiguration efs = parseEfsVolumeConfiguration(item.path("efsVolumeConfiguration"));
result.add(new Volume(item.path("name").asText(), hostSourcePath, efs));
}
return result;
}
private EfsVolumeConfiguration parseEfsVolumeConfiguration(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
String fileSystemId = node.path("fileSystemId").asText(null);
if (fileSystemId == null) {
return null;
}
Integer transitEncryptionPort = node.path("transitEncryptionPort").isNumber()
? node.path("transitEncryptionPort").asInt() : null;
JsonNode auth = node.path("authorizationConfig");
return new EfsVolumeConfiguration(
fileSystemId,
node.path("rootDirectory").asText(null),
node.path("transitEncryption").asText(null),
transitEncryptionPort,
auth.path("accessPointId").asText(null),
auth.path("iam").asText(null));
}
private List<MountPoint> parseMountPoints(JsonNode node) {
List<MountPoint> result = new ArrayList<>();
if (!node.isArray()) {
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.ecs.model.Container;
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
import io.github.hectorvent.floci.services.ecs.model.ContainerOverride;
import io.github.hectorvent.floci.services.ecs.model.EcsTask;
import io.github.hectorvent.floci.services.ecs.model.EfsVolumeConfiguration;
import io.github.hectorvent.floci.services.ecs.model.MountPoint;
import io.github.hectorvent.floci.services.ecs.model.NetworkBinding;
import io.github.hectorvent.floci.services.ecs.model.PortMapping;
@@ -74,12 +75,20 @@ public class EcsContainerManager {
List<Closeable> logStreams = new ArrayList<>();
List<Container> runtimeContainers = new ArrayList<>();
// Task-level volumes: map volume name -> host source path, consumed by per-container mountPoints.
// Task-level volumes consumed by per-container mountPoints: host volumes map their
// name -> absolute host source path; efsVolumeConfiguration volumes map their
// name -> EFS configuration (materialised below as a shared local Docker volume).
Map<String, String> volumeSourcePaths = new LinkedHashMap<>();
Map<String, EfsVolumeConfiguration> efsVolumes = new LinkedHashMap<>();
if (taskDef.getVolumes() != null) {
for (Volume v : taskDef.getVolumes()) {
if (v.name() != null && v.hostSourcePath() != null) {
if (v.name() == null) {
continue;
}
if (v.hostSourcePath() != null) {
volumeSourcePaths.put(v.name(), v.hostSourcePath());
} else if (v.efs() != null) {
efsVolumes.put(v.name(), v.efs());
}
}
}
@@ -142,16 +151,28 @@ public class EcsContainerManager {
// so it must be an absolute host path. Unresolved volume references are skipped.
if (def.getMountPoints() != null) {
for (MountPoint mp : def.getMountPoints()) {
String sourcePath = volumeSourcePaths.get(mp.sourceVolume());
if (sourcePath == null || mp.containerPath() == null) {
LOG.warnv("Skipping mountPoint with unresolved volume {0} on container {1}",
mp.sourceVolume(), def.getName());
if (mp.containerPath() == null) {
continue;
}
if (mp.readOnly()) {
specBuilder.withReadOnlyBind(sourcePath, mp.containerPath());
String sourcePath = volumeSourcePaths.get(mp.sourceVolume());
EfsVolumeConfiguration efs = efsVolumes.get(mp.sourceVolume());
if (sourcePath != null) {
// Host volume: bind-mount an absolute path on the Docker host.
if (mp.readOnly()) {
specBuilder.withReadOnlyBind(sourcePath, mp.containerPath());
} else {
specBuilder.withBind(sourcePath, mp.containerPath());
}
} else if (efs != null) {
// EFS volume: a shared local Docker named volume, so every task
// container that mounts the same EFS file system shares persistent
// storage — the local stand-in for an EFS mount (Docker cannot mount
// a real EFS file system).
specBuilder.withNamedVolume(efsVolumeName(efs.fileSystemId()),
mp.containerPath(), mp.readOnly());
} else {
specBuilder.withBind(sourcePath, mp.containerPath());
LOG.warnv("Skipping mountPoint with unresolved volume {0} on container {1}",
mp.sourceVolume(), def.getName());
}
}
}
@@ -407,6 +428,11 @@ public class EcsContainerManager {
return slash >= 0 ? taskArn.substring(slash + 1) : taskArn;
}
/** Name of the local Docker named volume backing an EFS file system. */
private static String efsVolumeName(String fileSystemId) {
return "floci-efs-" + fileSystemId;
}
// Inner enum to avoid import cycle — mirrors model.TaskStatus for readability
private enum TaskStatus {RUNNING}
}
@@ -0,0 +1,25 @@
package io.github.hectorvent.floci.services.ecs.model;
/**
* The {@code efsVolumeConfiguration} of an ECS task-definition volume:
* {@code {"fileSystemId": ..., "rootDirectory": ..., "transitEncryption": ...,
* "transitEncryptionPort": ..., "authorizationConfig": {"accessPointId": ..., "iam": ...}}}.
*
* <p>A container references the owning {@link Volume} by name via a {@link MountPoint}.
* Docker cannot mount a real Amazon EFS file system, so Floci materialises an EFS-backed
* volume as a shared local Docker <em>named volume</em> ({@code floci-efs-<fileSystemId>}):
* every container that mounts the same file system shares persistent storage that survives
* task restarts — the local equivalent of an EFS mount.
*
* <p>{@code rootDirectory}, {@code transitEncryption}, {@code transitEncryptionPort} and
* {@code authorizationConfig} are modelled for RegisterTaskDefinition/DescribeTaskDefinition
* round-trip fidelity (so Terraform sees no drift) but have no effect on the local mount.
*/
public record EfsVolumeConfiguration(
String fileSystemId,
String rootDirectory,
String transitEncryption,
Integer transitEncryptionPort,
String accessPointId,
String iam) {
}
@@ -1,10 +1,20 @@
package io.github.hectorvent.floci.services.ecs.model;
/**
* A task-level volume in an ECS task definition. Only the EC2-launch-type
* {@code host} volume shape is modelled: {@code {"name": ..., "host": {"sourcePath": ...}}}.
* {@code hostSourcePath} is the absolute path on the Docker host that the volume
* binds to; a container references this volume by {@code name} via a {@link MountPoint}.
* A task-level volume in an ECS task definition. Two shapes are modelled:
* <ul>
* <li>EC2-launch-type {@code host} volume — {@code {"name": ..., "host": {"sourcePath": ...}}};
* {@code hostSourcePath} is the absolute path on the Docker host that the volume binds to.</li>
* <li>{@code efsVolumeConfiguration} volume — {@code {"name": ..., "efsVolumeConfiguration": {...}}};
* see {@link EfsVolumeConfiguration}.</li>
* </ul>
* The two are mutually exclusive. A container references the volume by {@code name} via a
* {@link MountPoint}.
*/
public record Volume(String name, String hostSourcePath) {
public record Volume(String name, String hostSourcePath, EfsVolumeConfiguration efs) {
/** Convenience constructor for a {@code host} volume (no EFS configuration). */
public Volume(String name, String hostSourcePath) {
this(name, hostSourcePath, null);
}
}