diff --git a/src/main/java/io/github/hectorvent/floci/services/ec2/AmiImageResolver.java b/src/main/java/io/github/hectorvent/floci/services/ec2/AmiImageResolver.java index 38b1d8bb16..8d52a1e40e 100644 --- a/src/main/java/io/github/hectorvent/floci/services/ec2/AmiImageResolver.java +++ b/src/main/java/io/github/hectorvent/floci/services/ec2/AmiImageResolver.java @@ -64,6 +64,7 @@ public class AmiImageResolver { return switch (architecture) { case "arm64" -> "linux/arm64"; case "x86_64" -> "linux/amd64"; + case "i386" -> "linux/386"; default -> null; }; } diff --git a/src/main/resources/ec2/instance-type-catalog.yaml b/src/main/resources/ec2/instance-type-catalog.yaml index 20ea294dcd..d18790abb5 100644 --- a/src/main/resources/ec2/instance-type-catalog.yaml +++ b/src/main/resources/ec2/instance-type-catalog.yaml @@ -4,6 +4,7 @@ instanceTypes: memoryMib: 512 supportedArchitectures: - x86_64 + - i386 currentGeneration: true encryptionInTransitSupported: false defaultNetworkCardIndex: 0 @@ -17,6 +18,7 @@ instanceTypes: memoryMib: 1024 supportedArchitectures: - x86_64 + - i386 currentGeneration: true encryptionInTransitSupported: false defaultNetworkCardIndex: 0 @@ -30,6 +32,7 @@ instanceTypes: memoryMib: 2048 supportedArchitectures: - x86_64 + - i386 currentGeneration: true encryptionInTransitSupported: false defaultNetworkCardIndex: 0 @@ -43,6 +46,7 @@ instanceTypes: memoryMib: 4096 supportedArchitectures: - x86_64 + - i386 currentGeneration: true encryptionInTransitSupported: false defaultNetworkCardIndex: 0 diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ExternalImageCatalogTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ExternalImageCatalogTest.java index 430a5359e2..88611b169b 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ExternalImageCatalogTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ExternalImageCatalogTest.java @@ -35,6 +35,23 @@ class Ec2ExternalImageCatalogTest { assertTrue(new Ec2ImageCatalog().findByIdOrAlias("ami-local-worker").isEmpty()); } + @Test + void i386CatalogImageLaunchesOnTheLinux386Platform() throws Exception { + Path catalog = directory.resolve("i386.yaml"); + Files.writeString(catalog, """ + defaultDockerImage: example/base:1 + images: + - imageId: ami-local-i386 + dockerImage: i386/alpine:3 + name: local-i386 + description: local i386 + architecture: i386 + creationDate: 2025-11-05T00:00:00.000Z + """); + AmiImageResolver resolver = new AmiImageResolver(new Ec2ImageCatalog(catalog)); + assertEquals("linux/386", resolver.resolveImage("ami-local-i386").dockerPlatform()); + } + @Test void missingOrInvalidFileFailsInsteadOfSilentlyUsingBundledImages() throws Exception { assertThrows(IllegalStateException.class, diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2InstanceTypeCatalogTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2InstanceTypeCatalogTest.java index 6595c134f4..babad3528f 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2InstanceTypeCatalogTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2InstanceTypeCatalogTest.java @@ -131,6 +131,20 @@ class Ec2InstanceTypeCatalogTest { assertTrue(error.getMessage().contains("maximumNetworkInterfaces")); } + @Test + void t2FamilySupportsI386AndX86_64() { + for (String name : List.of("t2.nano", "t2.micro", "t2.small", "t2.medium")) { + assertEquals(Set.of("i386", "x86_64"), + Set.copyOf(instanceTypeCatalog.find(name).orElseThrow().supportedArchitectures), name); + } + // AWS's 32-bit-capable t2 list stops at medium + for (String name : List.of("t2.large", "t2.xlarge", "t2.2xlarge")) { + assertEquals(List.of("x86_64"), instanceTypeCatalog.find(name).orElseThrow().supportedArchitectures, name); + } + // launch-time default architecture must stay x86_64 (first entry) + assertEquals("x86_64", instanceTypeCatalog.find("t2.micro").orElseThrow().supportedArchitectures.get(0)); + } + @Test void burstableFamiliesCarryTheirDocumentedDefaultCreditOption() { assertEquals(Optional.of("standard"), Ec2InstanceTypeCatalog.defaultCpuCredits("t2.micro")); @@ -162,7 +176,6 @@ class Ec2InstanceTypeCatalogTest { assertEquals(vcpu, instanceType.vcpu, name); assertEquals(memoryMib, instanceType.memoryMib, name); - assertEquals(List.of("x86_64"), instanceType.supportedArchitectures, name); assertEquals(ipv4PerInterface, instanceType.ipv4AddressesPerInterface, name); assertEquals(maxInterfaces, instanceType.networkCards.get(0).maximumNetworkInterfaces, name); assertTrue(instanceType.currentGeneration, name); diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java index bceb7acc7e..0b060a5c75 100644 --- a/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/ec2/Ec2ServiceTest.java @@ -3378,18 +3378,9 @@ class Ec2ServiceTest { @Test void runInstancesRejectsIncompatibleInstanceTypeForCreatedArmImage() { - Ec2ImageCatalog catalog = mock(Ec2ImageCatalog.class); - Ec2ImageCatalog.CatalogImage source = new Ec2ImageCatalog.CatalogImage(); - source.imageId = "ami-arm-source"; - source.architecture = "arm64"; - source.rootDeviceName = "/dev/xvda"; - when(catalog.findByIdOrAlias("ami-arm-source")).thenReturn(Optional.of(source)); - AmiImageResolver resolver = mock(AmiImageResolver.class); - when(resolver.resolveImage("ami-arm-source")) - .thenReturn(new ResolvedAmiImage("arm-image", ResolvedAmiImage.DEFAULT_RUNTIME, false, - "linux/arm64")); - Ec2Service service = liveService(capturingContainerManager(), resolver, catalog); + Ec2Service service = serviceWithCatalogImage(resolver, "ami-arm-source", "arm64", "arm-image", + "linux/arm64"); Reservation sourceReservation = service.runInstances("us-east-1", "ami-arm-source", "t4g.medium", 1, 1, null, List.of(), null, null, List.of(), null, null); @@ -3409,6 +3400,35 @@ class Ec2ServiceTest { assertEquals("arm64", compatible.getInstances().getFirst().getArchitecture()); } + @Test + void runInstancesAcceptsI386ImageOnT2MediumAndRefusesItOnT2Large() { + Ec2Service service = serviceWithCatalogImage(mock(AmiImageResolver.class), "ami-i386", "i386", + "i386/alpine:3", "linux/386"); + + Reservation medium = service.runInstances("us-east-1", "ami-i386", "t2.medium", 1, 1, + null, List.of(), null, null, List.of(), null, null); + assertEquals("i386", medium.getInstances().getFirst().getArchitecture()); + + AwsException error = assertThrows(AwsException.class, + () -> service.runInstances("us-east-1", "ami-i386", "t2.large", 1, 1, + null, List.of(), null, null, List.of(), null, null)); + assertEquals("InvalidParameterValue", error.getErrorCode()); + } + + private Ec2Service serviceWithCatalogImage(AmiImageResolver resolver, String imageId, String architecture, + String dockerImage, String dockerPlatform) { + Ec2ImageCatalog catalog = mock(Ec2ImageCatalog.class); + Ec2ImageCatalog.CatalogImage source = new Ec2ImageCatalog.CatalogImage(); + source.imageId = imageId; + source.architecture = architecture; + source.rootDeviceName = "/dev/xvda"; + when(catalog.findByIdOrAlias(imageId)).thenReturn(Optional.of(source)); + when(resolver.resolveImage(imageId)) + .thenReturn(new ResolvedAmiImage(dockerImage, ResolvedAmiImage.DEFAULT_RUNTIME, false, + dockerPlatform)); + return liveService(capturingContainerManager(), resolver, catalog); + } + @Test void dryRunValidatesImagesBeforeReportingSuccess() { Ec2ContainerManager manager = mock(Ec2ContainerManager.class);