Browse Source

minor change

main
Nicolas Massé 2 months ago
parent
commit
617648bc8d
  1. 8
      tekton/README.md
  2. 28
      tekton/common/task-flightctl-update-digest.yaml
  3. 2
      tekton/pipeline.yaml

8
tekton/README.md

@ -76,5 +76,11 @@ oc create secret generic flightctl-config --from-file=client.yaml=$HOME/.config/
## Build the base image
```sh
oc create -f pipelinerun-base.yaml
oc create -f pipelinerun1.yaml
```
## Build the other images
```sh
oc create -f pipelinerun2.yaml
```

28
tekton/common/task-flightctl-update-digest.yaml

@ -4,6 +4,8 @@ metadata:
name: flightctl-update-digest
spec:
params:
- name: image-name
type: string
- name: new-image-digest
type: string
- description: The label selector to identify the fleet(s) to update.
@ -22,6 +24,10 @@ spec:
value: "false"
- name: FLEET_LABEL_SELECTOR
value: "$(params.fleet-label-selector)"
- name: IMAGE_NAME
value: "$(params.image-name)"
- name: NEW_IMAGE_DIGEST
value: "$(params.new-image-digest)"
script: |
#!/bin/bash
set -Eeuo pipefail
@ -39,9 +45,6 @@ spec:
# Print versions of the program we use
echo "=== Environment ==="
echo "---> flightctl"
flightctl version
echo
echo "---> bash"
bash --version
echo
@ -55,28 +58,21 @@ spec:
id
echo
echo "---> flightctl"
flightctl version
flightctl --config-dir $(workspaces.flightctl-config.path) version
echo
echo "---> config file"
ls -lZ $(workspaces.flightctl-config.path)
echo
# List fleets matching the label selector and update their image to the new digest
flightctl --config-dir $(workspaces.flightctl-config.path) get fleets --limit 0 -l "${FLEET_LABEL_SELECTOR}" -o name | while read -r fleet; do
echo "Updating fleet $fleet to image digest $(params.new-image-digest)"
echo "Updating fleet $fleet to image ${IMAGE_NAME}@${NEW_IMAGE_DIGEST}"
# Get the current fleet definition
flightctl --config-dir $(workspaces.flightctl-config.path) get fleet/$fleet -o yaml > /tmp/fleet.yaml
# Extract the current image from the fleet definition
CURRENT_IMAGE="$(yq eval '.spec.template.spec.os.image' /tmp/fleet.yaml)"
# Splits the CURRENT_IMAGE on the "@" or ":" character and takes the first part (the image name without tag or digest)
# Using only bash built-in features to avoid dependencies on other tools
IMAGE_NAME="${CURRENT_IMAGE%%[@:]*}"
# Construct the new image with the new digest
NEW_IMAGE="${IMAGE_NAME}@$(params.new-image-digest)"
# Update the fleet definition with the new image
yq eval -i ".spec.template.spec.os.image = \"$NEW_IMAGE\"" /tmp/fleet.yaml
yq eval -i ".spec.template.spec.os.image = \"${IMAGE_NAME}@${NEW_IMAGE_DIGEST}\"" /tmp/fleet.yaml
# Apply the updated fleet definition
flightctl --config-dir $(workspaces.flightctl-config.path) apply -f /tmp/fleet.yaml

2
tekton/pipeline.yaml

@ -129,6 +129,8 @@ spec:
taskRef:
name: flightctl-update-digest
params:
- name: image-name
value: $(params.image-name)
- name: new-image-digest
value: $(tasks.push-image.results.image-digest)
- name: fleet-label-selector

Loading…
Cancel
Save