Skip to content

Commit c746fd8

Browse files
committed
add manual container build instructions
1 parent 23ece5f commit c746fd8

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

docs/services/cicd.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,59 @@ RUN apt-get -yqq update && apt-get -yqq upgrade \
597597
&& rm -rf /var/lib/apt/lists/*
598598
```
599599

600+
### Manual container build
601+
It is possible to use CI's mechanisms to build a container image manually providing a `Dockerfile`, or even a full build context with a `Dockerfile`.
602+
For reproducibility one should aim to use a code versioning system like `git`, but for debugging a manual API call might not pollute the code history so much.
603+
604+
To use the API endpoint you need to create API credentials (one time setup) using the developer portal. Please follow [this guide][ref-devportal].
605+
To be able to use manual API container builds you must subscribe your application to the `ciext-container-builder` API.
606+
607+
After your application is created the tab `APIs` will appear at the top of the developer portal, which allows you to inspect the API for `ciext-container-builder`.
608+
The section `Documents` is very helpful as it contains the endpoint documentation for `/container/build POST`.
609+
Refer to the documentation there for all parameters.
610+
611+
The endpoint can work in two different modes:
612+
613+
1. Send just a Dockerfile
614+
1. Send a full build context as a tar.gz-archive and tell the API where the Dockerfile inside the tarball is.
615+
616+
!!! info "Create access token"
617+
To send any request to the API endpoint, we first need to create an access token, which can be done with the Consumer Key and Consumer secret.
618+
```console
619+
$ ACCESS_TOKEN="$(curl -u <your-consumer-key>:<your-consumer-secret> --silent -X POST https://auth.cscs.ch/auth/realms/firecrest-clients/protocol/openid-connect/token -d "grant_type=client_credentials" | jq -r '.access_token')"
620+
```
621+
The token is stored in the variable ACCESS_TOKEN.
622+
This token has only a short validity, so you need to create a fresh access token, whenever the current one becomes invalid (about 5 minutes validity).
623+
624+
!!! info "Build from Dockerfile"
625+
```console
626+
$ curl -H "Authorization: Bearer $ACCESS_TOKEN" --data-binary @path/to/Dockerfile "https://api.cscs.ch/ciext/v1/container/build?arch=x86_64"
627+
```
628+
It is mandatory to specify for which architecture you want to build the container. Valid choices are:
629+
630+
* `x86_64` - Correct for all nodes that are not Grace-Hopper
631+
* `aarch64` - ARM architecture - Correct for Grace-Hopper
632+
633+
The API call above sends the Dockerfile to the server, and the server will reply with a link, where you can see the build log.
634+
The final container image will be pushed to JFrog, a CSCS internal container registry.
635+
Once the container image is built, it can be pulled from any CSCS machine.
636+
637+
If you want to push the image to your Docker Hub account, you need to create a Docker Hub access token with write permissions, and then use the API call (similarly for other OCI registry providers)
638+
```
639+
$ curl -H "Authorization: Bearer $ACCESS_TOKEN" -H "X-Registry-Username <your-dockerhub-username>" -H "X-Registry-Password: <your-dockerhub-token>" --data-binary @path/to/Dockerfile "https://api.cscs.ch/ciext/v1/container/build?arch=x86_64&image=docker.io/<your-dockerhub-username>/my_image_name:latest"
640+
```
641+
642+
!!! info "Build with code"
643+
If you are using `COPY` or `ADD` statements in your Dockerfile, you will need to send the build context too.
644+
To send a full archive the easiest is via the API call
645+
```console
646+
$ tar -C path/to/build-context -czf - . | curl -H "Authorization: Bearer $ACCESS_TOKEN" --data-binary @- "https://api.cscs.ch/ciext/v1/container/build?arch=x86_64&dockerfile=relative/path/to/Dockerfile"
647+
```
648+
This is similar to
649+
```console
650+
$ docker build -f relative/path/to/Dockerfile .
651+
```
652+
600653
## CSCS CI specifics
601654

602655
### Restart CI jobs

0 commit comments

Comments
 (0)