diff --git a/.tekton/ansible-ai-connect-operator-pull-request.yaml b/.tekton/ansible-ai-connect-operator-pull-request.yaml index f1d833e0..96e7007f 100644 --- a/.tekton/ansible-ai-connect-operator-pull-request.yaml +++ b/.tekton/ansible-ai-connect-operator-pull-request.yaml @@ -162,6 +162,8 @@ spec: value: $(params.git-url) - name: revision value: $(params.revision) + - name: fetchTags + value: true runAfter: - init taskRef: @@ -183,6 +185,297 @@ spec: workspace: workspace - name: basic-auth workspace: git-auth + - name: git-metadata + runAfter: + - clone-repository + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: get-commit-timestamp + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + echo -n $(date -d @$(git log -1 --format=%at) "+%Y%m%d%H%M") > $(results.commit-timestamp.path) + results: + - name: commit-timestamp + - name: common-get-operator-versions + runAfter: + - clone-repository + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: get-latest-tag + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + LATEST_TAG=$(git tag -l --sort=v:refname | tail -n1) + echo -n $LATEST_TAG > $(results.operator_version_latest.path) + + echo -n $LATEST_TAG + + MAJOR=$(echo $LATEST_TAG | cut -d. -f1) + MINOR=$(echo $LATEST_TAG | cut -d. -f2) + PATCH=$(echo $LATEST_TAG | cut -d. -f3) + PATCH=$((PATCH + 1)) + NEW_TAG="$MAJOR.$MINOR.$PATCH" + echo -n $NEW_TAG > $(results.operator_version_next.path) + echo -n $NEW_TAG + + results: + - name: operator_version_latest + description: the _latest_ Operator version + - name: operator_version_next + description: The _next_ Operator version + - name: bundle + runAfter: + - clone-repository + - common-get-operator-versions + workspaces: + - name: source + workspace: workspace + taskSpec: + params: + - name: IMAGE + default: quay.io/ansible/ansible-ai-connect-konflux + - name: ADDITIONAL_TAGS + default: "" + - name: STORAGE_DRIVER + default: overlay + workspaces: + - name: source + steps: + - name: bundle + image: quay.io/operator-framework/operator-sdk:v1.10.0 + script: | + cd "$(workspaces.source.path)/source" + operator-sdk generate kustomize manifests -q + + # install kustomize + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + mv kustomize /usr/local/bin/ + + cd config/manager + + kustomize edit set image controller=$(params.IMAGE):0.1.0 + + cd ../.. + kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version 0.1.0 + operator-sdk bundle validate ./bundle + + echo "=====================" + ls + echo "=====================" + cd bundle + echo "cd bundle" + echo "=====================" + ls + echo "=====================" + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + volumes: + - name: varlibcontainers + emptyDir: {} + - name: update-cluster-service-version + runAfter: + - bundle + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: update-cluster-service-version + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + if [[ "$(tasks.common-get-operator-versions.results.operator_version_latest)" == "0.0.0" ]]; then + >&2 echo "No previous version found." + exit 0 + fi + + VERSION="$(tasks.common-get-operator-versions.results.operator_version_next)" + PREV_VERSION="$(tasks.common-get-operator-versions.results.operator_version_latest)" + if ! grep -qF "replaces: ansible-ai-connect-operator.v${PREV_VERSION}" bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml; then + sed -i "/version: ${VERSION}/a\\ + replaces: ansible-ai-connect-operator.v${PREV_VERSION}" ./bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml + fi + - name: bundle-build-push + runAfter: + - update-cluster-service-version + workspaces: + - name: source + workspace: workspace + taskSpec: + params: + - name: IMAGE + default: quay.io/ansible/ansible-ai-connect-konflux + - name: ADDITIONAL_TAGS + default: "" + - name: STORAGE_DRIVER + default: overlay + workspaces: + - name: source + steps: + - name: bundle-build + image: quay.io/buildah/stable:v1.17.0 + script: | + cd "$(workspaces.source.path)/source" + + OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next) + ADDITIONAL_TAGS="$(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp) $(params.IMAGE):$OPERATOR_VERSION_NEXT" + + buildah --storage-driver=$(params.STORAGE_DRIVER) bud \ + --no-cache -f bundle.Dockerfile -t $(params.IMAGE) . + + for tag in $ADDITIONAL_TAGS; do + buildah tag $(params.IMAGE) $tag + done + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + - name: bundle-push + image: quay.io/buildah/stable:v1.17.0 + script: | + OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next) + ADDITIONAL_TAGS="$(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp) $(params.IMAGE):$OPERATOR_VERSION_NEXT" + + for tag in $ADDITIONAL_TAGS; do + buildah --storage-driver=$(params.STORAGE_DRIVER) push \ + $tag + done + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + volumes: + - name: varlibcontainers + emptyDir: {} + + - name: build-catalog-index-bundle-image-list + runAfter: + - clone-repository + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: build-catalog-index-bundle-image-list + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + + # Install bash + apk add --no-cache bash skopeo + + # Create the actual script to run + cat << 'EOF' > /tmp/script.sh + #!/bin/bash + set -euo pipefail + cd "$(workspaces.source.path)/source" + LATEST_TAGS=($(git tag -l --sort=v:refname)) + echo "${LATEST_TAGS[@]}" + + # Filter array by tags that end with a semver + filtered_tags=() + regex="^([0-9]+\.[0-9]+\.[0-9]+)$" + for i in "${LATEST_TAGS[@]}" ; do + if [[ $i =~ $regex ]]; then + filtered_tags+=("quay.io/ansible/ansible-ai-connect-bundle:${BASH_REMATCH[1]}") ; + fi + done + + echo "${filtered_tags[@]}" + + # Include the version being built + filtered_tags+=("quay.io/ansible/ansible-ai-connect-bundle:$(tasks.common-get-operator-versions.results.operator_version_next)") + + # Convert array back to comma separated list + output_tags=${filtered_tags[@]} + output=${output_tags// /,} + + echo "================" + echo "${output}" + echo "================" + + + mkdir temp + skopeo copy --src-creds srajaram:LBtYCLwC9JgPwf3lFNMZMjim6NBA42siAIo2JlprKwEr1k2kXACxxDiiaSrPrChg6WDzmviEX6A7YATtiT+DhA== docker://quay.io/ansible/ansible-ai-connect-bundle:0.1.0 dir:/temp + + echo "================" + ls + echo "================" + echo "cd temp" + + # echo "${output}" > $(results.build-imgs.path) + + exit 0 + EOF + + # Make the script executable + chmod +x /tmp/script.sh + + # Execute the script using bash + /bin/bash /tmp/script.sh + results: + - name: build-imgs + + - name: prepare-catalog + runAfter: + - build-catalog-index-bundle-image-list + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: prepare-catalog + image: quay.io/buildah/stable:v1.17.0 + script: | + echo "hi" + #!/bin/bash + set -euo pipefail + echo $(tasks.build-catalog-index-bundle-image-list.results.build-imgs) + + + + + + + + + + + + + - name: prefetch-dependencies params: - name: input @@ -225,8 +518,7 @@ spec: - name: COMMIT_SHA value: $(tasks.clone-repository.results.commit) - name: BUILD_ARGS - value: - - $(params.build-args[*]) + value: ["IMAGE_TAGS=$(tasks.common-get-operator-versions.results.operator_version_next)-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp)"] - name: BUILD_ARGS_FILE value: $(params.build-args-file) runAfter: @@ -411,8 +703,11 @@ spec: params: - name: IMAGE value: $(tasks.build-container.results.IMAGE_URL) + - name: ADDITIONAL_TAGS + value: ["$(tasks.common-get-operator-versions.results.operator_version_next)-pr-{{pull_request_number}}-$(tasks.git-metadata.results.commit-timestamp)"] runAfter: - build-container + - common-get-operator-versions taskRef: params: - name: name diff --git a/.tekton/ansible-ai-connect-operator-push.yaml b/.tekton/ansible-ai-connect-operator-push.yaml index 37bb0dc7..7a59f0de 100644 --- a/.tekton/ansible-ai-connect-operator-push.yaml +++ b/.tekton/ansible-ai-connect-operator-push.yaml @@ -159,6 +159,8 @@ spec: value: $(params.git-url) - name: revision value: $(params.revision) + - name: fetchTags + value: true runAfter: - init taskRef: @@ -180,6 +182,182 @@ spec: workspace: workspace - name: basic-auth workspace: git-auth + - name: git-metadata + runAfter: + - clone-repository + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: get-commit-timestamp + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + echo -n $(date -d @$(git log -1 --format=%at) "+%Y%m%d%H%M") > $(results.commit-timestamp.path) + results: + - name: commit-timestamp + - name: common-get-operator-versions + runAfter: + - clone-repository + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: get-latest-tag + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + LATEST_TAG=$(git tag -l --sort=v:refname | tail -n1) + echo -n $LATEST_TAG > $(results.operator_version_latest.path) + + MAJOR=$(echo $LATEST_TAG | cut -d. -f1) + MINOR=$(echo $LATEST_TAG | cut -d. -f2) + PATCH=$(echo $LATEST_TAG | cut -d. -f3) + PATCH=$((PATCH + 1)) + NEW_TAG="$MAJOR.$MINOR.$PATCH" + echo $NEW_TAG > $(results.operator_version_next.path) + results: + - name: operator_version_latest + description: the _latest_ Operator version + - name: operator_version_next + description: The _next_ Operator version + - name: bundle + runAfter: + - clone-repository + - common-get-operator-versions + workspaces: + - name: source + workspace: workspace + taskSpec: + params: + - name: IMAGE + default: quay.io/ansible/ansible-ai-connect-konflux + - name: ADDITIONAL_TAGS + default: "latest $(tasks.common-get-operator-versions.results.operator_version_next)" + - name: STORAGE_DRIVER + default: overlay + workspaces: + - name: source + steps: + - name: bundle + image: quay.io/operator-framework/operator-sdk:v1.10.0 + script: | + cd "$(workspaces.source.path)/source" + operator-sdk generate kustomize manifests -q + + #install kustomize + curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash + mv kustomize /usr/local/bin/ + + cd config/manager + + kustomize edit set image controller=$(params.IMAGE):0.1.0 + + cd ../.. + kustomize build config/manifests | operator-sdk generate bundle -q --overwrite --version 0.1.0 + operator-sdk bundle validate ./bundle + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + volumes: + - name: varlibcontainers + emptyDir: {} + - name: update-cluster-service-version + runAfter: + - bundle + workspaces: + - name: source + workspace: workspace + taskSpec: + workspaces: + - name: source + steps: + - name: update-cluster-service-version + image: alpine/git + script: | + #!/bin/sh + set -euo pipefail + cd "$(workspaces.source.path)/source" + if [[ "$(tasks.common-get-operator-versions.results.operator_version_latest)" == "0.0.0" ]]; then + >&2 echo "No previous version found." + exit 0 + fi + + VERSION="$(tasks.common-get-operator-versions.results.operator_version_next)" + PREV_VERSION="$(tasks.common-get-operator-versions.results.operator_version_latest)" + if ! grep -qF "replaces: ansible-ai-connect-operator.v${PREV_VERSION}" bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml; then + sed -i "/version: ${VERSION}/a\\ + replaces: ansible-ai-connect-operator.v${PREV_VERSION}" ./bundle/manifests/ansible-ai-connect-operator.clusterserviceversion.yaml + fi + - name: bundle-build-push + runAfter: + - update-cluster-service-version + workspaces: + - name: source + workspace: workspace + taskSpec: + params: + - name: IMAGE + default: quay.io/ansible/ansible-ai-connect-konflux + - name: ADDITIONAL_TAGS + default: "latest" + - name: STORAGE_DRIVER + default: overlay + workspaces: + - name: source + steps: + - name: bundle-build + image: quay.io/buildah/stable:v1.17.0 + script: | + cd "$(workspaces.source.path)/source" + + OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next) + ADDITIONAL_TAGS="$(params.IMAGE):bundle-latest $(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT" + + buildah --storage-driver=$(params.STORAGE_DRIVER) bud \ + --no-cache -f bundle.Dockerfile -t $(params.IMAGE) . + + for tag in $ADDITIONAL_TAGS; do + buildah tag $(params.IMAGE) $tag + done + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + - name: bundle-push + image: quay.io/buildah/stable:v1.17.0 + script: | + OPERATOR_VERSION_NEXT=$(tasks.common-get-operator-versions.results.operator_version_next) + ADDITIONAL_TAGS="$(params.IMAGE):bundle-latest $(params.IMAGE):bundle-$OPERATOR_VERSION_NEXT" + + for tag in $ADDITIONAL_TAGS; do + buildah --storage-driver=$(params.STORAGE_DRIVER) push \ + $tag + done + volumeMounts: + - name: varlibcontainers + mountPath: /var/lib/containers + securityContext: + capabilities: + add: ["SETFCAP"] + volumes: + - name: varlibcontainers + emptyDir: {} - name: prefetch-dependencies params: - name: input @@ -222,8 +400,7 @@ spec: - name: COMMIT_SHA value: $(tasks.clone-repository.results.commit) - name: BUILD_ARGS - value: - - $(params.build-args[*]) + value: ["IMAGE_TAGS=latest"] - name: BUILD_ARGS_FILE value: $(params.build-args-file) runAfter: @@ -408,8 +585,11 @@ spec: params: - name: IMAGE value: $(tasks.build-container.results.IMAGE_URL) + - name: ADDITIONAL_TAGS + value: ["latest", "$(tasks.common-get-operator-versions.results.operator_version_next)"] runAfter: - build-container + - common-get-operator-versions taskRef: params: - name: name