Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HumairAK/60ea91599c7739d07c8f077620f4c3a8 to your computer and use it in GitHub Desktop.
Save HumairAK/60ea91599c7739d07c8f077620f4c3a8 to your computer and use it in GitHub Desktop.
After apiserver adds copy steps (final).
apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/big_data_passing_format: $(workspaces.$TASK_NAME.path)/artifacts/simple-pipeline-fe138/$TASKRUN_NAME/$TASK_PARAM_NAME
pipelines.kubeflow.org/pipeline_spec: '{"name": "simple_pipeline"}'
pipelines.kubeflow.org/run_name: Run of pre_version_at_2023-07-16T19:34:54.400Z
(954d1)
sidecar.istio.io/inject: "false"
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: http://minio-sample.my-dsp.svc.cluster.local:9000
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"produce-output": [["mydestfile", "$(workspaces.produce-output.path)/artifacts/simple-pipeline-fe138/$(context.taskRun.name)/mydestfile"]]}'
tekton.dev/input_artifacts: '{}'
tekton.dev/output_artifacts: '{"produce-output": [{"key": "artifacts/$PIPELINERUN/produce-output/mydestfile.tgz",
"name": "produce-output-mydestfile", "path": "/tmp/outputs/mydestfile/data"}]}'
tekton.dev/template: ""
creationTimestamp: "2023-07-16T19:35:00Z"
finalizers:
- chains.tekton.dev/pipelinerun
generation: 1
labels:
custom.tekton.dev/originalPipelineRun: simple-pipeline-fe138
pipeline/runid: fe13820b-2e93-41f5-8e23-004d7d30c990
pipelines.kubeflow.org/generation: ""
pipelines.kubeflow.org/pipelinename: ""
tekton.dev/pipeline: simple-pipeline-fe138
name: simple-pipeline-fe138
namespace: my-dsp
resourceVersion: "202603"
uid: bf358051-8ce2-4bb8-8c2f-5ee3a3eba41b
spec:
pipelineSpec:
tasks:
- name: produce-output
taskSpec:
metadata:
annotations:
artifact_outputs: '["mydestfile"]'
pipelines.kubeflow.org/component_spec_digest: '{"name": "Produce output",
"outputs": [{"name": "mydestfile"}], "version": "Produce output@sha256=ac34ebebe299a8eda0d9441960e6c889698e565204afdb9fad195417b7b9d2d3"}'
labels:
pipelines.kubeflow.org/cache_enabled: "true"
results:
- description: /tmp/outputs/mydestfile/data
name: mydestfile
type: string
- name: taskrun-name
type: string
spec: null
steps:
- args:
- --mydestfile
- $(workspaces.produce-output.path)/artifacts/simple-pipeline-fe138/$(context.taskRun.name)/mydestfile
command:
- sh
- -ec
- |
program_path=$(mktemp)
printf "%s" "$0" > "$program_path"
python3 -u "$program_path" "$@"
- |
def _make_parent_dirs_and_return_path(file_path: str):
import os
os.makedirs(os.path.dirname(file_path), exist_ok=True)
return file_path
def produce_output(
mydestfile, # Note: _file is stripped
):
import urllib.request
print("starting download...")
urllib.request.urlretrieve("http://212.183.159.230/20MB.zip", mydestfile)
print("done")
import argparse
_parser = argparse.ArgumentParser(prog='Produce output', description='')
_parser.add_argument("--mydestfile", dest="mydestfile", type=_make_parent_dirs_and_return_path, required=True, default=argparse.SUPPRESS)
_parsed_args = vars(_parser.parse_args())
_outputs = produce_output(**_parsed_args)
env:
- name: ORIG_PR_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['custom.tekton.dev/originalPipelineRun']
image: quay.io/operate-first/opf-toolbox:v0.12.0
name: main
resources: {}
- command:
- sh
- -ec
- echo -n "$(context.taskRun.name)" > "$(results.taskrun-name.path)"
image: busybox
name: output-taskrun-name
resources: {}
- command:
- sh
- -ec
- |
set -exo pipefail
TOTAL_SIZE=0
copy_artifact() {
if [ -d "$1" ]; then
tar -czvf "$1".tar.gz "$1"
SUFFIX=".tar.gz"
fi
ARTIFACT_SIZE=`wc -c "$1"${SUFFIX} | awk '{print $1}'`
TOTAL_SIZE=$( expr $TOTAL_SIZE + $ARTIFACT_SIZE)
touch "$2"
if [[ $TOTAL_SIZE -lt 3072 ]]; then
if [ -d "$1" ]; then
tar -tzf "$1".tar.gz > "$2"
elif ! awk "/[^[:print:]]/{f=1} END{exit !f}" "$1"; then
cp "$1" "$2"
fi
fi
}
copy_artifact $(workspaces.produce-output.path)/artifacts/simple-pipeline-fe138/$(context.taskRun.name)/mydestfile $(results.mydestfile.path)
env:
- name: ORIG_PR_NAME
valueFrom:
fieldRef:
fieldPath: metadata.labels['custom.tekton.dev/originalPipelineRun']
image: busybox
name: copy-results-artifacts
onError: continue
resources: {}
- args:
- |
if [ -d /tekton/results ]; then mkdir -p /tekton/home/tep-results; mv /tekton/results/* /tekton/home/tep-results/ || true; fi
command:
- sh
- -c
image: registry.access.redhat.com/ubi8/ubi-micro@sha256:443db9a646aaf9374f95d266ba0c8656a52d70d0ffcc386a782cea28fa32e55d
name: move-all-results-to-tekton-home
resources: {}
- args:
- |
#!/usr/bin/env sh
push_artifact() {
if [ -f "$2" ]; then
tar -cvzf $1.tgz $2
aws s3 --endpoint http://minio-sample.my-dsp.svc.cluster.local:9000 cp $1.tgz s3://mlpipeline/artifacts/$PIPELINERUN/$PIPELINETASK/$1.tgz
else
echo "$2 file does not exist. Skip artifact tracking for $1"
fi
}
push_log() {
cat /var/log/containers/$PODNAME*$NAMESPACE*step-main*.log > step-main.log
push_artifact main-log step-main.log
}
strip_eof() {
if [ -f "$2" ]; then
awk 'NF' $2 | head -c -1 > $1_temp_save && cp $1_temp_save $2
fi
}
push_artifact "mydestfile" "/tekton/home/tep-results/"$(basename "$(workspaces.produce-output.path)/artifacts/simple-pipeline-fe138/$(context.taskRun.name)/mydestfile")
command:
- sh
- -c
env:
- name: ARTIFACT_BUCKET
valueFrom:
fieldRef:
fieldPath: metadata.annotations['tekton.dev/artifact_bucket']
- name: ARTIFACT_ENDPOINT
valueFrom:
fieldRef:
fieldPath: metadata.annotations['tekton.dev/artifact_endpoint']
- name: ARTIFACT_ENDPOINT_SCHEME
valueFrom:
fieldRef:
fieldPath: metadata.annotations['tekton.dev/artifact_endpoint_scheme']
- name: ARTIFACT_ITEMS
valueFrom:
fieldRef:
fieldPath: metadata.annotations['tekton.dev/artifact_items']
- name: PIPELINETASK
valueFrom:
fieldRef:
fieldPath: metadata.labels['tekton.dev/pipelineTask']
- name: PIPELINERUN
valueFrom:
fieldRef:
fieldPath: metadata.labels['tekton.dev/pipelineRun']
- name: PODNAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
key: accesskey
name: mlpipeline-minio-artifact
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
key: secretkey
name: mlpipeline-minio-artifact
- name: ARCHIVE_LOGS
value: "false"
- name: TRACK_ARTIFACTS
value: "true"
- name: STRIP_EOF
value: "true"
image: quay.io/opendatahub/ds-pipelines-artifact-manager@sha256:58a13845901f8aae5421f640eeebee0abf3b12b27c1f96fbc8ff199b7e4f8d8d
name: copy-artifacts
resources: {}
workspaces:
- name: produce-output
workspaces:
- name: produce-output
workspace: simple-pipeline
workspaces:
- name: simple-pipeline
serviceAccountName: pipeline-runner-sample
timeout: 1h0m0s
workspaces:
- name: simple-pipeline
volumeClaimTemplate:
metadata:
creationTimestamp: null
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
storageClassName: gp3
status: {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment