Skip to content

Commit c148c56

Browse files
euanhheckj
andauthored
docs: Split ContainerBuildPlugin documentation into multiple pages (#99)
Motivation ---------- Most of the documentation explaining how a user should run the plugin is in a single DoCC file under the `ContainerImageBuilderPlugin` target (this otherwise empty target is needed because DoCC does not generate documentation for plugins). This documentation would be easier to read, and easier to expand with more information, if it was split into several sections. This would provide an outline view in the left-hand pane (the "curation") which would allow users to jump directly to sections of interest, and make internal links between documentation sections easier. Modifications ------------- * Rename `ContainerImageBuilderPlugin` to `swift-container-plugin`. `swift-container-plugin` will hold all the high level documentation, examples and tutorials for the project. A future PR will add a manual page which specifically covers only the plugin. * Result ------ The existing documentation is better structured. A number of small edits have been made for clarity. Test Plan --------- * No functional change. * DoCC checks are already run by the `soundness` GitHub CI job and continue to pass; all notes and usage warnings fixed. --------- Co-authored-by: Joseph Heck <[email protected]>
1 parent 55be678 commit c148c56

File tree

14 files changed

+274
-137
lines changed

14 files changed

+274
-137
lines changed

.spi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ builder:
33
configs:
44
- documentation_targets:
55
- containertool
6-
- ContainerImageBuilderPlugin
6+
- swift-container-plugin

Package.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let package = Package(
2727
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0"..<"4.0.0"),
2828
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
2929
.package(url: "https://github.com/apple/swift-http-types.git", from: "1.2.0"),
30-
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
30+
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
3131
],
3232
targets: [
3333
.target(
@@ -78,12 +78,11 @@ let package = Package(
7878
),
7979
dependencies: [.target(name: "containertool")]
8080
),
81-
// Empty target that builds the DocC catalog at /ContainerImageBuilderPluginDocumentation/ContainerImageBuilder.docc.
81+
// Empty target that builds the DocC catalog at /SwiftContainerPluginDocumentation/Documentation.docc.
8282
// The ContainerImageBuilder catalog includes high-level, user-facing documentation about using
8383
// the ContainerImageBuilder plugin from the command-line.
8484
.target(
85-
name: "ContainerImageBuilderPlugin",
86-
path: "Sources/ContainerImageBuilderPluginDocumentation",
85+
name: "swift-container-plugin",
8786
exclude: ["README.md"]
8887
),
8988
.testTarget(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Swift Container Plugin makes it easy to build container images for servers writt
1717
Find out more and see it in action:
1818

1919
* [How to put Swift in a box](https://fosdem.org/2025/schedule/event/fosdem-2025-5116-how-to-put-swift-in-a-box-building-container-images-with-swift-container-plugin/) at [FOSDEM 2025](https://fosdem.org/2025/schedule/track/swift/).
20-
* [Swift to the cloud in a single step](https://www.youtube.com/watch?v=9AaINsCfZzw) at [ServerSide.Swift 2024](https://www.serversideswift.info/speakers/euan-harris/).
20+
* [Swift to the cloud in a single step](https://www.youtube.com/watch?v=9AaINsCfZzw) at [ServerSide.Swift 2024](https://www.serversideswift.info/2024/speakers/euan-harris/).
2121

2222
## Usage
2323

Sources/ContainerImageBuilderPluginDocumentation/Documentation.docc/ContainerImageBuilderPlugin.md

Lines changed: 0 additions & 122 deletions
This file was deleted.

Sources/containertool/Documentation.docc/containertool.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Wrap a binary in a container image and publish it.
88

99
> Note: A container image is the standard way to package cloud software. Once you have wrapped your server in a container image, you can deploy it on any public or private cloud service based on [Kubernetes](https://kubernetes.io), or run it locally using a desktop container runtime.
1010
11-
## Usage
11+
### Usage
1212

1313
`containertool` can be run directly but its main role is to be a helper tool used by the `ContainerImageBuilder` command plugin. See the plugin documentation for examples of how to use it in this way.
1414

@@ -23,6 +23,7 @@ ARGUMENTS:
2323
OPTIONS:
2424
--repository <repository>
2525
Repository path
26+
--resources <resources> Resource bundle directory
2627
--username <username> Username
2728
--password <password> Password
2829
-v, --verbose Verbose output
@@ -33,5 +34,10 @@ OPTIONS:
3334
--from <from> Base image reference
3435
--os <os> Operating system (default: linux)
3536
--tag <tag> Tag for this manifest
37+
--enable-netrc/--disable-netrc
38+
Load credentials from a netrc file (default:
39+
--enable-netrc)
40+
--netrc-file <netrc-file>
41+
Specify the netrc file path
3642
-h, --help Show help information.
3743
```
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Add the plugin to your project
2+
3+
Make Swift Container Plugin available in your project.
4+
5+
## Overview
6+
7+
Swift Container Plugin is distributed as a Swift Package Manager package. To make it available, you must add it as a dependency of your project.
8+
9+
### Install the plugin using the `swift package` CLI
10+
11+
> Adding the same dependency to your project more than once will prevent it from building.
12+
> If this happens, delete the duplicate dependency lines from `Package.swift` and rebuild.
13+
14+
Recent versions of `swift package` suupport the `add-dependency` command:
15+
16+
```shell
17+
swift package add-dependency https://github.com/apple/swift-container-plugin --from 0.5.0
18+
```
19+
20+
### Install the plugin by manually editing `Package.swift`
21+
22+
If you cannot use the `swift package add-dependency` comand, append the following lines to your project's `Package.swift` file:
23+
24+
```swift
25+
package.dependencies += [
26+
.package(url: "https://github.com/apple/swift-container-plugin", from: "0.5.0"),
27+
]
28+
```
29+
30+
### Check that the plugin is available
31+
32+
After installation, Swift Package Manager should show that the `ContainerImageBuilder` is now available:
33+
34+
```shell
35+
% swift package plugin --list
36+
‘build-container-image’ (plugin ‘ContainerImageBuilder’ in package ‘swift-container-plugin)
37+
```
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@
1111
-->
1212
<plist version="1.0">
1313
<dict>
14-
<key>CDDefaultCodeListingLanguage</key>
15-
<string>shell</string>
16-
<key>CDDefaultModuleKind</key>
17-
<string>Command Plugin</string>
14+
<key>CDDefaultCodeListingLanguage</key>
15+
<string>shell</string>
16+
<key>CFBundleName</key>
17+
<string>swift-container-plugin</string>
18+
<key>CFBundleDisplayName</key>
19+
<string>swift-container-plugin</string>
20+
<key>CFBundleIdentifier</key>
21+
<string>com.apple.ContainerPlugin</string>
22+
<key>CFBundlePackageType</key>
23+
<string>DOCS</string>
24+
<key>CDDefaultModuleKind</key>
25+
<string>Tool</string>
1826
</dict>
1927
</plist>
2028

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Swift Container Plugin
2+
3+
@Metadata {
4+
@TechnologyRoot()
5+
}
6+
7+
Build and publish container images using Swift Package Manager.
8+
9+
## Overview
10+
11+
Container images are the standard way to package cloud software today. Once you have packaged your server in a container image, you can deploy it on any container-based public or private cloud service, or run it locally using a desktop container runtime.
12+
13+
Swift Container Plugin makes it easy to build container images for servers written in Swift, using Swift Package Manager.
14+
15+
Find out more and see it in action:
16+
17+
* [How to put Swift in a box](https://fosdem.org/2025/schedule/event/fosdem-2025-5116-how-to-put-swift-in-a-box-building-container-images-with-swift-container-plugin/) at [FOSDEM 2025](https://fosdem.org/2025/schedule/track/swift/).
18+
* [Swift to the cloud in a single step](https://www.youtube.com/watch?v=9AaINsCfZzw) at [ServerSide.Swift 2024](https://www.serversideswift.info/2024/speakers/euan-harris/).
19+
20+
### Usage
21+
22+
Use the Swift Container Plugin to package an executable product from your Swift package into a container image and publish it to a container registry.
23+
24+
To use the plugin:
25+
- <doc:Adding-the-plugin-to-your-project>
26+
- <doc:requirements>
27+
- <doc:authentication>
28+
29+
### Build and publish a container image
30+
31+
After adding the plugin to your project, you can build and publish a container image in one step.
32+
Here is how to build the [HelloWorld example](https://github.com/apple/swift-container-plugin/tree/main/Examples/HelloWorldHummingbird) as a static binary for Linux running the `x86_64` architecture:
33+
34+
```
35+
% swift package --swift-sdk x86_64-swift-linux-musl \
36+
build-container-image --repository registry.example.com/myservice
37+
...
38+
Plugin ‘ContainerImageBuilder’ wants permission to allow all network connections on all ports.
39+
Stated reason: “This command publishes images to container registries over the network”.
40+
Allow this plugin to allow all network connections on all ports? (yes/no) yes
41+
...
42+
Building for debugging...
43+
Build of product 'containertool' complete! (4.95s)
44+
...
45+
Build of product 'hello-world' complete! (5.51s)
46+
...
47+
[ContainerImageBuilder] Found base image manifest: sha256:7bd643386c6e65cbf52f6e2c480b7a76bce8102b562d33ad2aff7c81b7169a42
48+
[ContainerImageBuilder] Found base image configuration: sha256:b904a448fde1f8088913d7ad5121c59645b422e6f94c13d922107f027fb7a5b4
49+
[ContainerImageBuilder] Built application layer
50+
[ContainerImageBuilder] Uploading application layer
51+
[ContainerImageBuilder] Layer sha256:dafa2b0c44d2cfb0be6721f079092ddf15dc8bc537fb07fe7c3264c15cb2e8e6: already exists
52+
[ContainerImageBuilder] Layer sha256:2565d8e736345fc7ba44f9b3900c5c20eda761eee01e01841ac7b494f9db5cf6: already exists
53+
[ContainerImageBuilder] Layer sha256:2c179bb2e4fe6a3b8445fbeb0ce5351cf24817cb0b068c75a219b12434c54a58: already exists
54+
registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df
55+
```
56+
57+
### Run the image
58+
59+
You can deploy your service in the cloud, or use a standards-compliant container runtime such as `podman` to run it locally:
60+
61+
```
62+
% podman run -p 8080:8080 registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df
63+
Trying to pull registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df...
64+
...
65+
2024-05-26T22:57:50+0000 info HummingBird : [HummingbirdCore] Server started and listening on 0.0.0.0:8080
66+
```
67+
68+
Take a look at the [Examples](Examples).
69+
70+
## Topics
71+
72+
### Essentials
73+
- <doc:requirements>
74+
- <doc:Adding-the-plugin-to-your-project>
75+
- <doc:authentication>
76+
77+
### Building and running
78+
- <doc:build>
79+
- <doc:run>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Set up your registry credentials
2+
3+
Configure the plugin to authenticate to your container registry.
4+
5+
## Overview
6+
7+
Many container registries require authentication in order to push images, or even pull them.
8+
The plugin reads your registry credentials from a `.netrc` file in your home directory.
9+
Add a record into the `.netrc` file for each registry you use, the plugin uses the authentication by the registry you choose.
10+
11+
The following example shows placeholder values for the registry `registry.example.com`:
12+
13+
```
14+
machine registry.example.com
15+
login myuser
16+
password mypassword
17+
```
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Build and package your service
2+
3+
Build a container image and upload it to a registry.
4+
5+
## Overview
6+
7+
The plugin exposes the command `build-container-image` which you invoke to build your service, package it in a container image and upload it to a container registry, in a single command:
8+
9+
```shell
10+
% swift package --swift-sdk x86_64-swift-linux-musl \
11+
build-container-image --from swift:slim --repository registry.example.com/myservice
12+
```
13+
14+
* The `--swift-sdk` argument specifies the Swift SDK with which to build the executable. In this case we are using the Static Linux SDK, installed earlier, to build an statically-linked x86_64 Linux binary.
15+
* The `--from` argument specifies the base image on which our service will run. `swift:slim` is the default, but you can choose your own base image or use `scratch` if your service does not require a base image at all.
16+
* The `--repository` argument specifies the repository to which the plugin will upload the finished image.
17+
18+
> Note: on macOS, the plugin needs permission to connect to the network to publish the image to the registry.
19+
>
20+
> ```
21+
> Plugin ‘ContainerImageBuilder’ wants permission to allow all network connections on all ports.
22+
> Stated reason: “This command publishes images to container registries over the network”.
23+
> Allow this plugin to allow all network connections on all ports? (yes/no)
24+
> ```
25+
>
26+
> Type `yes` to continue.
27+
28+
```
29+
Building for debugging...
30+
Build of product 'containertool' complete! (4.95s)
31+
...
32+
Build of product 'hello-world' complete! (5.51s)
33+
...
34+
[ContainerImageBuilder] Found base image manifest: sha256:7bd643386c6e65cbf52f6e2c480b7a76bce8102b562d33ad2aff7c81b7169a42
35+
[ContainerImageBuilder] Found base image configuration: sha256:b904a448fde1f8088913d7ad5121c59645b422e6f94c13d922107f027fb7a5b4
36+
[ContainerImageBuilder] Built application layer
37+
[ContainerImageBuilder] Uploading application layer
38+
[ContainerImageBuilder] Layer sha256:dafa2b0c44d2cfb0be6721f079092ddf15dc8bc537fb07fe7c3264c15cb2e8e6: already exists
39+
[ContainerImageBuilder] Layer sha256:2565d8e736345fc7ba44f9b3900c5c20eda761eee01e01841ac7b494f9db5cf6: already exists
40+
[ContainerImageBuilder] Layer sha256:2c179bb2e4fe6a3b8445fbeb0ce5351cf24817cb0b068c75a219b12434c54a58: already exists
41+
registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df
42+
```
43+
44+
When the plugin finishes, it prints a reference identifying the new image.
45+
Any standard container runtime can use the reference to pull and run your service.

0 commit comments

Comments
 (0)