Skip to content

Commit 2c3b245

Browse files
authored
Add --disable-docker-image-update plugin flag (#311)
motivation: sometimes, you need to use a customized local docker image and `docker pull` don’t have to be called changes: * add `--disable-docker-image-update` plugin flag to disable `docker pull` call
1 parent f3eac31 commit 2c3b245

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

Plugins/AWSLambdaPackager/Plugin.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ struct AWSLambdaPackager: CommandPlugin {
5151
toolsProvider: { name in try context.tool(named: name).path },
5252
outputDirectory: configuration.outputDirectory,
5353
baseImage: configuration.baseDockerImage,
54+
disableDockerImageUpdate: configuration.disableDockerImageUpdate,
5455
buildConfiguration: configuration.buildConfiguration,
5556
verboseLogging: configuration.verboseLogging
5657
)
@@ -77,6 +78,7 @@ struct AWSLambdaPackager: CommandPlugin {
7778
toolsProvider: (String) throws -> Path,
7879
outputDirectory: Path,
7980
baseImage: String,
81+
disableDockerImageUpdate: Bool,
8082
buildConfiguration: PackageManager.BuildConfiguration,
8183
verboseLogging: Bool
8284
) throws -> [LambdaProduct: Path] {
@@ -86,13 +88,15 @@ struct AWSLambdaPackager: CommandPlugin {
8688
print("building \"\(packageIdentity)\" in docker")
8789
print("-------------------------------------------------------------------------")
8890

89-
// update the underlying docker image, if necessary
90-
print("updating \"\(baseImage)\" docker image")
91-
try self.execute(
92-
executable: dockerToolPath,
93-
arguments: ["pull", baseImage],
94-
logLevel: .output
95-
)
91+
if !disableDockerImageUpdate {
92+
// update the underlying docker image, if necessary
93+
print("updating \"\(baseImage)\" docker image")
94+
try self.execute(
95+
executable: dockerToolPath,
96+
arguments: ["pull", baseImage],
97+
logLevel: .output
98+
)
99+
}
96100

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

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

306312
self.verboseLogging = verboseArgument
307313

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

354+
self.disableDockerImageUpdate = disableDockerImageUpdateArgument
355+
348356
if self.verboseLogging {
349357
print("-------------------------------------------------------------------------")
350358
print("configuration")
@@ -360,6 +368,7 @@ private struct Configuration: CustomStringConvertible {
360368
products: \(self.products.map(\.name))
361369
buildConfiguration: \(self.buildConfiguration)
362370
baseDockerImage: \(self.baseDockerImage)
371+
disableDockerImageUpdate: \(self.disableDockerImageUpdate)
363372
}
364373
"""
365374
}

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ The `archive` command can be customized using the following parameters
197197
* `2` (Debug)
198198
* `--swift-version` Swift language version used to define the Amazon Linux 2 Docker image. For example "5.7.3"
199199
* `--base-docker-image` An Amazon Linux 2 docker image name available in your system.
200+
* `--disable-docker-image-update` If flag is set, docker image will not be updated and local image will be used.
200201

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

0 commit comments

Comments
 (0)