Skip to content

Commit 19481e8

Browse files
committed
containertool: Allow destination repository to be set by an environment variable
1 parent 49f92be commit 19481e8

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Examples/HelloWorldHummingbird/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let package = Package(
2121
platforms: [.macOS(.v14)],
2222
dependencies: [
2323
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.1.0"),
24-
.package(url: "https://github.com/apple/swift-container-plugin", from: "1.0.0"),
24+
.package(path: "../.."),
2525
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
2626
],
2727
targets: [

Sources/containertool/containertool.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
3232
private var defaultRegistry: String?
3333

3434
@Option(help: "Repository path")
35-
private var repository: String
35+
private var repository: String?
3636

3737
@Argument(help: "Executable to package")
3838
private var executable: String
@@ -114,7 +114,14 @@ enum AllowHTTP: String, ExpressibleByArgument, CaseIterable { case source, desti
114114
// MARK: Apply defaults for unspecified configuration flags
115115

116116
let env = ProcessInfo.processInfo.environment
117+
117118
let defaultRegistry = defaultRegistry ?? env["CONTAINERTOOL_DEFAULT_REGISTRY"] ?? "docker.io"
119+
guard let repository = repository ?? env["CONTAINERTOOL_REPOSITORY"] else {
120+
throw ValidationError(
121+
"Please specify the destination repository using --repository or CONTAINERTOOL_REPOSITORY"
122+
)
123+
}
124+
118125
let username = defaultUsername ?? env["CONTAINERTOOL_DEFAULT_USERNAME"]
119126
let password = defaultPassword ?? env["CONTAINERTOOL_DEFAULT_PASSWORD"]
120127
let from = from ?? env["CONTAINERTOOL_BASE_IMAGE"] ?? "swift:slim"

Sources/swift-container-plugin/Documentation.docc/build-container-image.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Wrap a binary in a container image and publish it.
2020
- term `--default-registry <default-registry>`:
2121
The default registry hostname. (default: `docker.io`)
2222

23-
If the value of the `--repository` argument does not contain a registry hostname, the default registry will be prepended to the repository path.
23+
If the repository path does not contain a registry hostname, the default registry will be prepended to it.
2424

2525
- term `--repository <repository>`:
2626
The repository path.
@@ -79,9 +79,14 @@ Wrap a binary in a container image and publish it.
7979
### Environment
8080

8181
- term `CONTAINERTOOL_DEFAULT_REGISTRY`:
82-
Default image registry hostname, used when the `--repository` argument does not contain a registry hostname.
82+
Default image registry hostname, used when the repository path does not contain a registry hostname.
8383
(default: `docker.io`)
8484

85+
- term `CONTAINERTOOL_REPOSITORY`:
86+
The repository path.
87+
88+
If the path does not begin with a registry hostname, the default registry will be prepended to the path.
89+
8590
- term `CONTAINERTOOL_BASE_IMAGE`:
8691
Base image on which to layer the application.
8792
(default: `swift:slim`)

scripts/test-plugin-output-streaming.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ swift package --package-path "$PKGPATH" --allow-network-connections all build-co
4646
set -o pipefail
4747

4848
# This checks that the output lines are not broken, but not that they appear in the correct order
49-
grep -F -x -e "error: Missing expected argument '--repository <repository>'" \
50-
-e "error: Help: --repository <repository> Repository path" \
51-
-e "error: Usage: containertool [<options>] --repository <repository> <executable>" \
49+
grep -F -x -e "error: Please specify the destination repository using --repository or CONTAINERTOOL_REPOSITORY" \
50+
-e "error: Usage: containertool [<options>] <executable>" \
5251
-e "error: See 'containertool --help' for more information." "$PKGPATH/output"
5352

5453
log Plugin error output: PASSED

0 commit comments

Comments
 (0)