Skip to content

Commit

Permalink
amazon linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmosmann committed Dec 28, 2021
1 parent c14f954 commit beddf46
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@
<dependency>
<groupId>de.flapdoodle</groupId>
<artifactId>de.flapdoodle.os</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
package de.flapdoodle.embed.mongo.packageresolver.linux;

import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.packageresolver.*;
import de.flapdoodle.embed.process.config.store.DistributionPackage;
import de.flapdoodle.embed.process.config.store.FileSet;
import de.flapdoodle.embed.process.config.store.FileType;
import de.flapdoodle.embed.process.config.store.ImmutableFileSet;
import de.flapdoodle.embed.process.distribution.ArchiveType;
import de.flapdoodle.embed.process.distribution.Distribution;
import de.flapdoodle.os.BitSize;
import de.flapdoodle.os.CPUType;
import de.flapdoodle.os.OS;
import de.flapdoodle.os.linux.AmazonVersion;

import java.util.Optional;

public class AmazonPackageResolver implements PackageFinder {

private final ImmutablePlatformMatchRules rules;

public AmazonPackageResolver(final Command command) {
this.rules = rules(command);
}

@Override
public Optional<DistributionPackage> packageFor(final Distribution distribution) {
return rules.packageFor(distribution);
}

private static ImmutablePlatformMatchRules rules(final Command command) {
final ImmutableFileSet fileSet = FileSet.builder().addEntry(FileType.Executable, command.commandName()).build();

/*
* Amazon Linux 2 ARM 64
* --
* 4.4.3 - 4.4.0, 4.2.12 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0, 2.6.12 - 2.6.0
* https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-amazon2-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.4, 4.2.16 - 4.2.13
*/
final PlatformMatchRule amazon2Arm = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.4", "4.4.9"),
VersionRange.of("4.2.13", "4.2.16")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.ARM)
.withVersion(AmazonVersion.AmazonLinux2)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/linux/mongodb-linux-aarch64-amazon2-{version}.tgz")
.build())
.build();

final PlatformMatchRule amazon2ArmTools = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.4", "4.4.9"),
VersionRange.of("4.2.13", "4.2.16")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.ARM)
.withVersion(AmazonVersion.AmazonLinux2)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/tools/db/mongodb-database-tools-amazon2-arm64-{tools.version}.tgz")
.build())
.build();

/*
* Amazon Linux 2 x64
* --
* 4.2.4 - 4.2.4, 3.6.21 - 3.6.0, 3.4.23 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0, 2.6.12 - 2.6.0
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22
*/
final PlatformMatchRule amazon2 = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.0", "4.4.9"),
VersionRange.of("4.2.5", "4.2.16"),
VersionRange.of("4.2.0", "4.2.3"),
VersionRange.of("4.0.0", "4.0.26"),
VersionRange.of("3.6.22", "3.6.22")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.X86)
.withVersion(AmazonVersion.AmazonLinux2)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/linux/mongodb-linux-x86_64-amazon2-{version}.tgz")
.build())
.build();

final PlatformMatchRule amazon2tools = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.0", "4.4.9"),
VersionRange.of("4.2.5", "4.2.16"),
VersionRange.of("4.2.0", "4.2.3"),
VersionRange.of("4.0.0", "4.0.26"),
VersionRange.of("3.6.22", "3.6.22")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.X86)
.withVersion(AmazonVersion.AmazonLinux2)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/tools/db/mongodb-database-tools-amazon2-x86_64-{tools.version}.tgz")
.build())
.build();


/*
* Amazon Linux x64
* --
* 4.2.4 - 4.2.4, 3.4.8 - 3.4.8, 2.6.12 - 2.6.0
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.9, 3.4.7 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0
*/
final PlatformMatchRule amazon = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.0", "4.4.9"),
VersionRange.of("4.2.5", "4.2.16"),
VersionRange.of("4.2.0", "4.2.3"),
VersionRange.of("4.0.0", "4.0.26"),
VersionRange.of("3.6.0", "3.6.22"),
VersionRange.of("3.4.9", "3.4.23"),
VersionRange.of("3.4.0", "3.4.7"),
VersionRange.of("3.2.0", "3.2.21"),
VersionRange.of("3.0.0", "3.0.14")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.X86)
.withVersion(AmazonVersion.AmazonLinux)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/linux/mongodb-linux-x86_64-amazon-{version}.tgz")
.build())
.build();

final PlatformMatchRule amazontools = PlatformMatchRule.builder()
.match(DistributionMatch.any(
VersionRange.of("5.0.0", "5.0.2"),
VersionRange.of("4.4.0", "4.4.9"),
VersionRange.of("4.2.5", "4.2.16"),
VersionRange.of("4.2.0", "4.2.3"),
VersionRange.of("4.0.0", "4.0.26"),
VersionRange.of("3.6.0", "3.6.22"),
VersionRange.of("3.4.9", "3.4.23"),
VersionRange.of("3.4.0", "3.4.7"),
VersionRange.of("3.2.0", "3.2.21"),
VersionRange.of("3.0.0", "3.0.14")
)
.andThen(PlatformMatch
.withOs(OS.Linux)
.withBitSize(BitSize.B64)
.withCpuType(CPUType.X86)
.withVersion(AmazonVersion.AmazonLinux)
)
)
.finder(UrlTemplatePackageResolver.builder()
.fileSet(fileSet)
.archiveType(ArchiveType.TGZ)
.urlTemplate("/tools/db/mongodb-database-tools-amazon-x86_64-{tools.version}.tgz")
.build())
.build();

switch (command) {
case MongoDump:
case MongoImport:
case MongoRestore:
return PlatformMatchRules.empty()
.withRules(
amazon2ArmTools,
amazon2tools,
amazontools
);
default:
return PlatformMatchRules.empty()
.withRules(
amazon2Arm,
amazon2,
amazon
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@
import de.flapdoodle.os.BitSize;
import de.flapdoodle.os.ImmutablePlatform;
import de.flapdoodle.os.OS;
import de.flapdoodle.os.linux.CentosVersion;
import de.flapdoodle.os.linux.DebianVersion;
import de.flapdoodle.os.linux.LinuxMintVersion;
import de.flapdoodle.os.linux.UbuntuVersion;
import de.flapdoodle.os.linux.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -85,6 +82,12 @@ private static ImmutablePlatformMatchRules rules(Command command) {
.finder(new CentosPackageResolver(command))
.build();

ImmutablePlatformMatchRule amazonRule = PlatformMatchRule.builder()
.match(PlatformMatch.withOs(OS.Linux)
.withVersion(AmazonVersion.values()))
.finder(new AmazonPackageResolver(command))
.build();

/*
Linux (legacy) undefined
https://fastdl.mongodb.org/linux/mongodb-linux-i686-{}.tgz
Expand Down Expand Up @@ -176,6 +179,7 @@ private static ImmutablePlatformMatchRules rules(Command command) {
linuxMintRule,
debianRule,
centosRule,
amazonRule,
legacy32,
legacy64,
hiddenLegacy64,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package de.flapdoodle.embed.mongo.packageresolver.linux;

import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.packageresolver.HtmlParserResultTester;
import de.flapdoodle.embed.process.distribution.Distribution;
import de.flapdoodle.embed.process.distribution.Version;
import de.flapdoodle.os.CommonArchitecture;
import de.flapdoodle.os.ImmutablePlatform;
import de.flapdoodle.os.OS;
import de.flapdoodle.os.Platform;
import de.flapdoodle.os.linux.AmazonVersion;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class AmazonPackageResolverTest {
/*
* Amazon Linux 2 ARM 64
* https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-amazon2-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.4, 4.2.16 - 4.2.13
*/
@ParameterizedTest
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.4", "4.2.16 - 4.2.13"})
public void amazon2LinuxArm(String version) {
assertThat(linuxWith(CommonArchitecture.ARM_64, AmazonVersion.AmazonLinux2), version)
.resolvesTo("/linux/mongodb-linux-aarch64-amazon2-{}.tgz");
}

/*
* Amazon Linux 2 x64
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon2-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22
*/
@ParameterizedTest
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.0", "4.2.16 - 4.2.5", "4.2.3 - 4.2.0", "4.0.26 - 4.0.0", "3.6.22"})
public void amazon2Linux(String version) {
assertThat(linuxWith(CommonArchitecture.X86_64, AmazonVersion.AmazonLinux2), version)
.resolvesTo("/linux/mongodb-linux-x86_64-amazon2-{}.tgz");
}

/*
* Amazon Linux x64
* https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-{}.tgz
* 5.0.2 - 5.0.0, 4.4.9 - 4.4.0, 4.2.16 - 4.2.5, 4.2.3 - 4.2.0, 4.0.26 - 4.0.0, 3.6.22 - 3.6.0, 3.4.23 - 3.4.9, 3.4.7 - 3.4.0, 3.2.21 - 3.2.0, 3.0.14 - 3.0.0
*/
@ParameterizedTest
@ValueSource(strings = {"5.0.2 - 5.0.0", "4.4.9 - 4.4.0", "4.2.16 - 4.2.5", "4.2.3 - 4.2.0", "4.0.26 - 4.0.0", "3.6.22 - 3.6.0", "3.4.23 - 3.4.9", "3.4.7 - 3.4.0", "3.2.21 - 3.2.0", "3.0.14 - 3.0.0"})
public void amazonLinux(String version) {
assertThat(linuxWith(CommonArchitecture.X86_64, AmazonVersion.AmazonLinux), version)
.resolvesTo("/linux/mongodb-linux-x86_64-amazon-{}.tgz");
}

private static Platform linuxWith(CommonArchitecture architecture, de.flapdoodle.os.Version version) {
return ImmutablePlatform.builder()
.operatingSystem(OS.Linux)
.architecture(architecture)
.version(version)
.build();
}

private static HtmlParserResultTester assertThat(Platform platform, String versionList) {
return HtmlParserResultTester.with(
new AmazonPackageResolver(Command.Mongo),
version -> Distribution.of(Version.of(version), platform),
versionList);
}

}

0 comments on commit beddf46

Please sign in to comment.