Skip to content

Commit b77604a

Browse files
committed
fix detection of container cli tool
1 parent e4bb09a commit b77604a

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

Plugins/AWSLambdaBuilder/Plugin.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ struct AWSLambdaBuilder: CommandPlugin {
2828
let packageID: String = context.package.id
2929
let packageDisplayName = context.package.displayName
3030
let packageDirectory = context.package.directoryURL
31-
let dockerToolPath = try context.tool(named: "docker").url
3231
let zipToolPath = try context.tool(named: "zip").url
3332

3433
// extract arguments that require PluginContext to fully resolve
@@ -39,6 +38,18 @@ struct AWSLambdaBuilder: CommandPlugin {
3938
let productsArgument = argumentExtractor.extractOption(named: "products")
4039
let configurationArgument = argumentExtractor.extractOption(named: "configuration")
4140

41+
// Resolve the container CLI that matches the requested cross-compilation method.
42+
// The plugin sandbox can only run tools it resolves up front, so we must pick the right
43+
// binary here — `container` for `--cross-compile container`, `docker` otherwise. Extracting
44+
// these options only peeks them for the plugin; the original `arguments` (which the helper
45+
// re-parses) is still forwarded unchanged below.
46+
// `--container-cli` is a deprecated alias for `--cross-compile`.
47+
let crossCompileArgument = argumentExtractor.extractOption(named: "cross-compile")
48+
let containerCliArgument = argumentExtractor.extractOption(named: "container-cli")
49+
let crossCompileMethod = (crossCompileArgument.first ?? containerCliArgument.first)?.lowercased()
50+
let containerCLIToolName = crossCompileMethod == "container" ? "container" : "docker"
51+
let containerToolPath = try context.tool(named: containerCLIToolName).url
52+
4253
if let outputPath = outputPathArgument.first {
4354
#if os(Linux)
4455
var isDirectory: Bool = false
@@ -87,7 +98,7 @@ struct AWSLambdaBuilder: CommandPlugin {
8798
"--package-id", packageID,
8899
"--package-display-name", packageDisplayName,
89100
"--package-directory", packageDirectory.path(),
90-
"--docker-tool-path", dockerToolPath.path,
101+
"--docker-tool-path", containerToolPath.path,
91102
"--zip-tool-path", zipToolPath.path,
92103
] + arguments
93104

Sources/AWSLambdaPluginHelper/lambda-build/Builder.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,19 +450,35 @@ enum CrossCompileMethod: String, CustomStringConvertible {
450450
env: [String: String]?,
451451
command: String
452452
) -> [String] {
453-
switch self {
454-
case .docker, .container:
453+
func genericArgs() -> [String] {
455454
var args: [String] = ["run", "--rm"]
456455
for mount in mounts {
457456
args += ["-v", mount]
458457
}
459458
if let env {
460459
for (key, value) in env.sorted(by: { $0.key < $1.key }) {
461-
args += ["--env", "\(key)=\(value)"]
460+
args += ["-e", "\(key)=\(value)"]
462461
}
463462
}
464463
args += ["-w", workingDirectory, baseImage, "bash", "-cl", command]
465464
return args
465+
}
466+
switch self {
467+
468+
case .docker:
469+
return genericArgs()
470+
471+
case .container:
472+
var args = genericArgs()
473+
474+
// container's runtime needs a bit more memory
475+
if self == .container {
476+
args.insert("--memory", at: 1)
477+
args.insert("4G", at: 2)
478+
}
479+
480+
return args
481+
466482
case .swiftStaticSdk, .customSdk:
467483
fatalError("runArguments should not be called for unsupported cross-compile methods")
468484
}

0 commit comments

Comments
 (0)