CentOS Stream Images from Image Builder
CentOS Stream Images from Image Builder¶
Although you cannot select CentOS Stream from the web interface of Image Builder, you can use the API to select CentOS Stream. Very good instructions can be found here - https://www.redhat.com/en/blog/using-hosted-image-builder-its-api Various API Calls can be found here - https://console.redhat.com/docs/api/image-builder Image builder blog post: https://www.redhat.com/en/blog/announcing-full-support-new-red-hat-enterprise-linux-image-builder-service Image builder web console: https://console.redhat.com/insights/image-builder/
Setup¶
- Log into your Red Hat account
- It can be a Red Hat Developer account.
- Get an offline token from https://access.redhat.com/management/api
- Save that token. You will set it as a variable.
OFFLINE_TOKEN="PutYourTokenHereItWillBeLongDoNotUseThisBecauseItIsJustAnExample"
Verify you can login to Image Builder¶
curl --silent \
--request POST \
--data grant_type=refresh_token \
--data client_id=rhsm-api \
--data refresh_token=$OFFLINE_TOKEN \
https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token \
| jq .
Set access_token¶
Your access token expires fairly quickly run this each time it expires
access_token=$( \
curl --silent \
--request POST \
--data grant_type=refresh_token \
--data client_id=rhsm-api \
--data refresh_token=$OFFLINE_TOKEN \
https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/token \
| jq -r .access_token \
)
Common Commands¶
Get documentation¶
curl --silent \
--header "Authorization: Bearer $access_token" \
https://console.redhat.com/api/image-builder/v1/openapi.json \
| jq . >> api.documentation
List available distributions¶
curl --silent \
--header "Authorization: Bearer $access_token" \
https://console.redhat.com/api/image-builder/v1/distributions \
| jq .
Output¶
...
{
"description": "CentOS Stream 9",
"name": "centos-9"
},
...
{
"description": "Fedora Linux 37",
"name": "fedora-37"
},
...
Get arch and image types¶
curl --silent \
--header "Authorization: Bearer $access_token" \
https://console.redhat.com/api/image-builder/v1/architectures/fedora-37\
| jq .
Output¶
...
"arch": "x86_64",
"image_types": [
"ami",
"vhd",
"aws",
"gcp",
"azure",
"edge-commit",
"edge-installer",
"rhel-edge-commit",
"rhel-edge-installer",
"guest-image",
"image-installer",
"vsphere"
],
...
Request image be built¶
Note: request.json is your template. If you have a different name, replace @request.json with @your-name
curl --silent \
--request POST \
--header "Authorization: Bearer $access_token" \
--header "Content-Type: application/json" \
--data @request.json \
https://console.redhat.com/api/image-builder/v1/compose
Get build id¶
compose_id=$( \
curl --silent \
--request POST \
--header "Authorization: Bearer $access_token" \
--header "Content-Type: application/json" \
--data @request.json \
https://console.redhat.com/api/image-builder/v1/compose \
| jq -r .id \
)
Check Status¶
curl \
--silent \
--header "Authorization: Bearer $access_token" \
"https://console.redhat.com/api/image-builder/v1/composes/$compose_id" \
| jq .