Skip to content

Add --disable-docker-image-update plugin flag #311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions Plugins/AWSLambdaPackager/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ struct AWSLambdaPackager: CommandPlugin {
toolsProvider: { name in try context.tool(named: name).path },
outputDirectory: configuration.outputDirectory,
baseImage: configuration.baseDockerImage,
disableDockerImageUpdate: configuration.disableDockerImageUpdate,
buildConfiguration: configuration.buildConfiguration,
verboseLogging: configuration.verboseLogging
)
Expand All @@ -77,6 +78,7 @@ struct AWSLambdaPackager: CommandPlugin {
toolsProvider: (String) throws -> Path,
outputDirectory: Path,
baseImage: String,
disableDockerImageUpdate: Bool,
buildConfiguration: PackageManager.BuildConfiguration,
verboseLogging: Bool
) throws -> [LambdaProduct: Path] {
Expand All @@ -86,13 +88,15 @@ struct AWSLambdaPackager: CommandPlugin {
print("building \"\(packageIdentity)\" in docker")
print("-------------------------------------------------------------------------")

// update the underlying docker image, if necessary
print("updating \"\(baseImage)\" docker image")
try self.execute(
executable: dockerToolPath,
arguments: ["pull", baseImage],
logLevel: .output
)
if !disableDockerImageUpdate {
// update the underlying docker image, if necessary
print("updating \"\(baseImage)\" docker image")
try self.execute(
executable: dockerToolPath,
arguments: ["pull", baseImage],
logLevel: .output
)
}

// get the build output path
let buildOutputPathCommand = "swift build -c \(buildConfiguration.rawValue) --show-bin-path"
Expand Down Expand Up @@ -290,6 +294,7 @@ private struct Configuration: CustomStringConvertible {
public let buildConfiguration: PackageManager.BuildConfiguration
public let verboseLogging: Bool
public let baseDockerImage: String
public let disableDockerImageUpdate: Bool

public init(
context: PluginContext,
Expand All @@ -302,6 +307,7 @@ private struct Configuration: CustomStringConvertible {
let configurationArgument = argumentExtractor.extractOption(named: "configuration")
let swiftVersionArgument = argumentExtractor.extractOption(named: "swift-version")
let baseDockerImageArgument = argumentExtractor.extractOption(named: "base-docker-image")
let disableDockerImageUpdateArgument = argumentExtractor.extractFlag(named: "disable-docker-image-update") > 0

self.verboseLogging = verboseArgument

Expand Down Expand Up @@ -345,6 +351,8 @@ private struct Configuration: CustomStringConvertible {
let swiftVersion = swiftVersionArgument.first ?? .none // undefined version will yield the latest docker image
self.baseDockerImage = baseDockerImageArgument.first ?? "swift:\(swiftVersion.map { $0 + "-" } ?? "")amazonlinux2"

self.disableDockerImageUpdate = disableDockerImageUpdateArgument

if self.verboseLogging {
print("-------------------------------------------------------------------------")
print("configuration")
Expand All @@ -360,6 +368,7 @@ private struct Configuration: CustomStringConvertible {
products: \(self.products.map(\.name))
buildConfiguration: \(self.buildConfiguration)
baseDockerImage: \(self.baseDockerImage)
disableDockerImageUpdate: \(self.disableDockerImageUpdate)
}
"""
}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ The `archive` command can be customized using the following parameters
* `2` (Debug)
* `--swift-version` Swift language version used to define the Amazon Linux 2 Docker image. For example "5.7.3"
* `--base-docker-image` An Amazon Linux 2 docker image name available in your system.
* `--disable-docker-image-update` If flag is set, docker image will not be updated and local image will be used.

Both `--swift-version` and `--base-docker-image` are mutually exclusive

Expand Down