-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
RHTAP bot
committed
Dec 13, 2024
1 parent
1166739
commit cb9b893
Showing
11 changed files
with
653 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
apiVersion: tekton.dev/v1beta1 | ||
kind: Task | ||
metadata: | ||
labels: | ||
app.kubernetes.io/version: "0.1" | ||
annotations: | ||
tekton.dev/pipelines.minVersion: "0.12.1" | ||
tekton.dev/tags: "konflux" | ||
name: apply-tags | ||
spec: | ||
description: >- | ||
Applies additional tags to the built image. | ||
params: | ||
- name: IMAGE | ||
description: Reference of image that was pushed to registry in the buildah task. | ||
type: string | ||
- name: ADDITIONAL_TAGS | ||
description: Additional tags that will be applied to the image in the registry. | ||
type: array | ||
default: [] | ||
- name: CA_TRUST_CONFIG_MAP_NAME | ||
type: string | ||
description: The name of the ConfigMap to read CA bundle data from. | ||
default: trusted-ca | ||
- name: CA_TRUST_CONFIG_MAP_KEY | ||
type: string | ||
description: The name of the key in the ConfigMap that contains the CA bundle data. | ||
default: ca-bundle.crt | ||
stepTemplate: | ||
volumeMounts: | ||
- name: trusted-ca | ||
mountPath: /etc/pki/tls/certs/ca-custom-bundle.crt | ||
subPath: ca-bundle.crt | ||
readOnly: true | ||
steps: | ||
- name: apply-additional-tags-from-parameter | ||
image: registry.access.redhat.com/ubi9/skopeo:9.4-14.1728984400@sha256:891ee232a9319ed0f675c318f9605422bde7436328e7faec7dc896a206a78e54 | ||
args: | ||
- $(params.ADDITIONAL_TAGS[*]) | ||
env: | ||
- name: IMAGE | ||
value: $(params.IMAGE) | ||
script: | | ||
#!/bin/bash | ||
if [ "$#" -ne 0 ]; then | ||
IMAGE_WITHOUT_TAG=$(echo "$IMAGE" | sed 's/:[^:]*$//') | ||
for tag in "$@"; do | ||
echo "Applying tag $tag" | ||
skopeo copy --multi-arch index-only docker://"$IMAGE" docker://"$IMAGE_WITHOUT_TAG:$tag" | ||
done | ||
else | ||
echo "No additional tags parameter specified" | ||
fi | ||
- name: apply-additional-tags-from-image-label | ||
image: registry.access.redhat.com/ubi9/skopeo:9.4-14.1728984400@sha256:891ee232a9319ed0f675c318f9605422bde7436328e7faec7dc896a206a78e54 | ||
env: | ||
- name: IMAGE | ||
value: $(params.IMAGE) | ||
script: | | ||
#!/bin/bash | ||
ADDITIONAL_TAGS_FROM_IMAGE_LABEL=$(skopeo inspect --no-tags --format '{{ index .Labels "konflux.additional-tags" }}' "docker://$IMAGE") | ||
if [ -n "${ADDITIONAL_TAGS_FROM_IMAGE_LABEL}" ]; then | ||
IFS=', ' read -r -a tags_array <<< "$ADDITIONAL_TAGS_FROM_IMAGE_LABEL" | ||
IMAGE_WITHOUT_TAG=$(echo "$IMAGE" | sed 's/:[^:]*$//') | ||
for tag in "${tags_array[@]}" | ||
do | ||
echo "Applying tag $tag" | ||
skopeo copy --multi-arch index-only docker://"$IMAGE" docker://"$IMAGE_WITHOUT_TAG:$tag" | ||
done | ||
else | ||
echo "No additional tags specified in the image labels" | ||
fi | ||
volumes: | ||
- name: trusted-ca | ||
configMap: | ||
name: $(params.CA_TRUST_CONFIG_MAP_NAME) | ||
items: | ||
- key: $(params.CA_TRUST_CONFIG_MAP_KEY) | ||
path: ca-bundle.crt | ||
optional: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
apiVersion: tekton.dev/v1 | ||
kind: Task | ||
metadata: | ||
labels: | ||
app.kubernetes.io/version: "0.1" | ||
build.appstudio.redhat.com/build_type: "docker" | ||
annotations: | ||
tekton.dev/pipelines.minVersion: "0.12.1" | ||
tekton.dev/tags: "image-build, appstudio" | ||
name: push-dockerfile | ||
spec: | ||
description: |- | ||
Discover Dockerfile from source code and push it to registry as an OCI artifact. | ||
params: | ||
- name: IMAGE | ||
description: The built binary image. The Dockerfile is pushed to the same image repository alongside. | ||
type: string | ||
- name: IMAGE_DIGEST | ||
description: The built binary image digest, which is used to construct the tag of Dockerfile image. | ||
type: string | ||
- name: DOCKERFILE | ||
description: Path to the Dockerfile. | ||
type: string | ||
default: ./Dockerfile | ||
- name: CONTEXT | ||
description: Path to the directory to use as context. | ||
type: string | ||
default: . | ||
- name: TAG_SUFFIX | ||
description: Suffix of the Dockerfile image tag. | ||
type: string | ||
default: .dockerfile | ||
- name: ARTIFACT_TYPE | ||
description: Artifact type of the Dockerfile image. | ||
type: string | ||
default: application/vnd.konflux.dockerfile | ||
results: | ||
- name: IMAGE_REF | ||
description: Digest-pinned image reference to the Dockerfile image. | ||
steps: | ||
- name: push | ||
image: quay.io/konflux-ci/oras:latest@sha256:b7e810730d97fe862826a048773a7539e469453df3681fd22de9754722266c69 | ||
workingDir: $(workspaces.workspace.path) | ||
env: | ||
- name: IMAGE | ||
value: $(params.IMAGE) | ||
- name: IMAGE_DIGEST | ||
value: $(params.IMAGE_DIGEST) | ||
- name: TAG_SUFFIX | ||
value: $(params.TAG_SUFFIX) | ||
- name: DOCKERFILE | ||
value: $(params.DOCKERFILE) | ||
- name: CONTEXT | ||
value: $(params.CONTEXT) | ||
- name: ARTIFACT_TYPE | ||
value: $(params.ARTIFACT_TYPE) | ||
- name: IMAGE_REF_RESULT | ||
value: $(results.IMAGE_REF.path) | ||
script: | | ||
set -eu | ||
set -o pipefail | ||
# Same discovery logic used in buildah task | ||
SOURCE_CODE_DIR=source | ||
if [ -e "$SOURCE_CODE_DIR/$CONTEXT/$DOCKERFILE" ]; then | ||
dockerfile_path="$(pwd)/$SOURCE_CODE_DIR/$CONTEXT/$DOCKERFILE" | ||
elif [ -e "$SOURCE_CODE_DIR/$DOCKERFILE" ]; then | ||
dockerfile_path="$(pwd)/$SOURCE_CODE_DIR/$DOCKERFILE" | ||
elif echo "$DOCKERFILE" | grep -q "^https\?://"; then | ||
echo "Fetch Dockerfile from $DOCKERFILE" | ||
dockerfile_path=$(mktemp --suffix=-dockerfile) | ||
http_code=$(curl -s -L -w "%{http_code}" --output "$dockerfile_path" "$DOCKERFILE") | ||
if [ $http_code != 200 ]; then | ||
echo "No Dockerfile is fetched. Server responds $http_code" | ||
exit 1 | ||
fi | ||
else | ||
echo "Cannot find Dockerfile $DOCKERFILE" | ||
exit 1 | ||
fi | ||
echo "Selecting auth for $IMAGE" | ||
auth_json=$(mktemp) | ||
select-oci-auth $IMAGE >"$auth_json" | ||
dockerfile_image=${IMAGE%:*}:${IMAGE_DIGEST/:/-}${TAG_SUFFIX} | ||
dockerfile_for_upload_path=/tmp/Dockerfile | ||
cp "$dockerfile_path" "$dockerfile_for_upload_path" | ||
cd "$(dirname $dockerfile_for_upload_path)" | ||
retry oras push --no-tty \ | ||
--format json \ | ||
--registry-config "$auth_json" \ | ||
--artifact-type "$ARTIFACT_TYPE" \ | ||
"$dockerfile_image" "$(basename $dockerfile_for_upload_path)" \ | ||
| yq '.reference' | tr -d '\r\n' >"$IMAGE_REF_RESULT" | ||
workspaces: | ||
- name: workspace | ||
description: Workspace containing the source code from where the Dockerfile is discovered. |
Oops, something went wrong.