|
| 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/speakers/euan-harris/). |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +Swift Container Plugin can package any executable product defined in `Package.swift` in a container image and publish it to a container registry. |
| 23 | + |
| 24 | +### Build and publish a container image |
| 25 | + |
| 26 | +After adding the plugin to your project, you can build and publish a container image in one step: |
| 27 | + |
| 28 | +``` |
| 29 | +% swift package --swift-sdk x86_64-swift-linux-musl \ |
| 30 | + build-container-image --repository registry.example.com/myservice |
| 31 | +... |
| 32 | +Plugin ‘ContainerImageBuilder’ wants permission to allow all network connections on all ports. |
| 33 | +Stated reason: “This command publishes images to container registries over the network”. |
| 34 | +Allow this plugin to allow all network connections on all ports? (yes/no) yes |
| 35 | +... |
| 36 | +Building for debugging... |
| 37 | +Build of product 'containertool' complete! (4.95s) |
| 38 | +... |
| 39 | +Build of product 'hello-world' complete! (5.51s) |
| 40 | +... |
| 41 | +[ContainerImageBuilder] Found base image manifest: sha256:7bd643386c6e65cbf52f6e2c480b7a76bce8102b562d33ad2aff7c81b7169a42 |
| 42 | +[ContainerImageBuilder] Found base image configuration: sha256:b904a448fde1f8088913d7ad5121c59645b422e6f94c13d922107f027fb7a5b4 |
| 43 | +[ContainerImageBuilder] Built application layer |
| 44 | +[ContainerImageBuilder] Uploading application layer |
| 45 | +[ContainerImageBuilder] Layer sha256:dafa2b0c44d2cfb0be6721f079092ddf15dc8bc537fb07fe7c3264c15cb2e8e6: already exists |
| 46 | +[ContainerImageBuilder] Layer sha256:2565d8e736345fc7ba44f9b3900c5c20eda761eee01e01841ac7b494f9db5cf6: already exists |
| 47 | +[ContainerImageBuilder] Layer sha256:2c179bb2e4fe6a3b8445fbeb0ce5351cf24817cb0b068c75a219b12434c54a58: already exists |
| 48 | +registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df |
| 49 | +``` |
| 50 | + |
| 51 | +### Run the image |
| 52 | + |
| 53 | +You can deploy your service in the cloud, or use a standards-compliant container runtime such as `podman` to run it locally: |
| 54 | + |
| 55 | +``` |
| 56 | +% podman run -p 8080:8080 registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df |
| 57 | +Trying to pull registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed9190317147dee95a218faf1df... |
| 58 | +... |
| 59 | +2024-05-26T22:57:50+0000 info HummingBird : [HummingbirdCore] Server started and listening on 0.0.0.0:8080 |
| 60 | +``` |
| 61 | + |
| 62 | +Take a look at the [Examples](Examples). |
| 63 | + |
| 64 | +## Topics |
| 65 | + |
| 66 | +### Essentials |
| 67 | +- <doc:requirements> |
| 68 | +- <doc:Adding-the-plugin-to-your-project> |
| 69 | +- <doc:authentication> |
| 70 | + |
| 71 | +### Building and running |
| 72 | +- <doc:build> |
| 73 | +- <doc:run> |
0 commit comments