|
1 | 1 | # Build and package your service |
2 | 2 |
|
3 | | -Build a container image and upload it to a registry. |
| 3 | +Build a container image and publish it to a registry. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 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: |
| 7 | +The plugin exposes the command `build-container-image` which you invoke to build your service, package it in a container image and publish it to a container registry, in a single command: |
8 | 8 |
|
9 | 9 | ```shell |
10 | 10 | % swift package --swift-sdk x86_64-swift-linux-musl \ |
11 | 11 | build-container-image --from swift:slim --repository registry.example.com/myservice |
12 | 12 | ``` |
13 | 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. |
| 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](<doc:requirements>), to build an statically-linked x86_64 Linux executable. |
15 | 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. |
| 16 | +* The `--repository` argument specifies the repository to which the plugin will publish the finished image. |
17 | 17 |
|
18 | 18 | > Note: on macOS, the plugin needs permission to connect to the network to publish the image to the registry. |
19 | 19 | > |
@@ -43,3 +43,45 @@ registry.example.com/myservice@sha256:a3f75d0932d052dd9d448a1c9040b16f9f2c2ed919 |
43 | 43 |
|
44 | 44 | When the plugin finishes, it prints a reference identifying the new image. |
45 | 45 | Any standard container runtime can use the reference to pull and run your service. |
| 46 | +
|
| 47 | +### Default registry |
| 48 | +
|
| 49 | +If you don't include a registry name in the `--repository` argument, the plugin will publish your image to Docker Hub by default. |
| 50 | +
|
| 51 | +You can override the default registry by using the `--default-registry` argument or setting the `CONTAINERTOOL_DEFAULT_REGISTRY` environment variable. |
| 52 | +
|
| 53 | +The following examples show how to publish images to some popular registry providers. |
| 54 | +
|
| 55 | +### Docker Hub |
| 56 | +
|
| 57 | +The following example publishes an image to a repository named `mydockerid/example` on Docker Hub. |
| 58 | +
|
| 59 | +The repository will be created if it does not already exist. |
| 60 | +
|
| 61 | +``` |
| 62 | +swift package --swift-sdk x86_64-swift-linux-musl build-container-image \ |
| 63 | + --repository mydockerid/example |
| 64 | +``` |
| 65 | +
|
| 66 | +### GitHub Container Registry |
| 67 | +
|
| 68 | +The following example publishes an image to a repository named `mydockerid/example` on GitHub Container Registry. |
| 69 | +
|
| 70 | +The repository will be created if it does not already exist. |
| 71 | +
|
| 72 | +``` |
| 73 | +swift package --swift-sdk x86_64-swift-linux-musl build-container-image \ |
| 74 | + --repository ghcr.io/mygithubusername/example |
| 75 | +``` |
| 76 | +
|
| 77 | +### Amazon Elastic Container Registry |
| 78 | +
|
| 79 | +The following example publishes an image to the repository named `example/test` on Amazon Elastic Container Registry. |
| 80 | +
|
| 81 | +**The repository must already exist before you push to it.** |
| 82 | +Create a repository using the [Amazon ECR Console](https://docs.aws.amazon.com/AmazonECR/latest/userguide/repository-create.html). |
| 83 | +
|
| 84 | +``` |
| 85 | +swift package --swift-sdk x86_64-swift-linux-musl build-container-image \ |
| 86 | + --repository 123456789012.dkr.ecr.us-west-2.amazonaws.com/example/test |
| 87 | +``` |
0 commit comments