Skip to content

Commit

Permalink
Unpin Ubuntu Focal version by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dagguh committed Jun 10, 2024
1 parent afdde11 commit b5a272e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ Dropping a requirement of a major version of a dependency is a new contract.
- Add `CanonicalAmiProvider.Builder.avoidUnattendedUpgrades` for bumping `imageName` to Focal or higher.

### Fixed
- Bump Ubuntu Focal AMI to `ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531`.
The previous one was 2 years old and disappeared: `ubuntu-focal-20.04-amd64-server-20220610`.
- Unpin Ubuntu Focal version in `CanonicalAmiProvider.Builder` by default.
You can still pin a specific release date, e.g. `imageName("ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531")`

## [1.15.0] - 2024-01-23
[1.15.0]: https://github.com/atlassian-labs/aws-resources/compare/release-1.14.0...release-1.15.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ class CanonicalImageIdByNameResolver private constructor(
)
)
.images
.sortedByDescending { it.creationDate }
.map { it.imageId }
.let {
when {
it.isEmpty() -> throw Exception("Failed to find image $imageName in $region")
it.size > 1 -> throw Exception("More than one image found with name $imageName in declared region $region. Selecting any of them automatically could create a security risk, so we can't proceed")
else -> it.first()
}
}
.firstOrNull()
?: throw Exception("Failed to find image containing $imageName in $region")

class Builder(
private val ec2: AmazonEC2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CanonicalAmiProvider private constructor(
}

class Builder {
private val focal = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20240531"
private val focal = "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server"
private var imageName = focal

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,23 @@ class CanonicalImageIdByNameResolverTest {
}

@Test
fun failsWhenMoreThanOneImageIsFound() {
fun picksTheNewestImage() {
val queriedImageName = "name-of-single-image"
val ec2 = object : AmazonEC2 by FakeEc2() {
override fun describeImages(
describeImagesRequest: DescribeImagesRequest?
) = DescribeImagesResult()
.withImages(
Image().withImageId("id-of-image-1"),
Image().withImageId("id-of-image-2")
Image().withImageId("id-of-image-1").withCreationDate("2022-07-07T00:49:01.000Z"),
Image().withImageId("id-of-image-2").withCreationDate("2024-03-21T22:43:23.000Z"),
Image().withImageId("id-of-image-3").withCreationDate("2023-03-01T23:16:36.000Z")
)
}
val resolver = CanonicalImageIdByNameResolver.Builder(ec2)
.build()

val result = try {
resolver.invoke(queriedImageName)
null
} catch (e: Exception) {
e
}
val result = resolver.invoke(queriedImageName)

assertThat(result).isNotNull()
assertThat(result).isEqualTo("id-of-image-2")
}
}

0 comments on commit b5a272e

Please sign in to comment.