1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-11-25 06:17:50 +00:00
catalog/gcs/gcs-download.yaml
Christie Wilson bd99284d02 Use "path" instead of "name" 👣
"path" is a more descriptive name for this param since it is the path to
the data - also this is what upload was already using :D
2020-04-07 17:24:01 +01:00

51 lines
1.7 KiB
YAML

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: gcs-download
spec:
workspaces:
- name: credentials
description: A secret with a service account key to use as GOOGLE_APPLICATION_CREDENTIALS.
- name: output
description: The workspace where files will be copied to from GCS.
params:
- name: path
description: The path to the file or directory that will be written to the output workspace.
type: string
- name: location
description: The address (including "gs://") of the bucket you'd like to copy from.
type: string
- name: typeDir
description: Set this to "true" if the location you are copying from is a directory.
type: string
default: "false"
- name: serviceAccountPath
description: The path inside the credentials workspace to the GOOGLE_APPLICATION_CREDENTIALS key file.
type: string
default: service_account.json
steps:
- name: copy
image: google/cloud-sdk
script: |
#!/usr/bin/env bash
set -xe
CRED_PATH="$(workspaces.credentials.path)/$(params.serviceAccountPath)"
DESTINATION="$(workspaces.output.path)/$(params.path)"
if [[ -f "$CRED_PATH" ]]; then
GOOGLE_APPLICATION_CREDENTIALS="$CRED_PATH"
fi
if [[ "${GOOGLE_APPLICATION_CREDENTIALS}" != "" ]]; then
echo GOOGLE_APPLICATION_CREDENTIALS is set, activating Service Account...
gcloud auth activate-service-account --key-file=${GOOGLE_APPLICATION_CREDENTIALS}
fi
if [[ "$(params.typeDir)" == "true" ]]; then
mkdir -p "$DESTINATION"
gsutil rsync -d -r "$(params.location)" "$DESTINATION"
else
gsutil cp $(params.location) "$DESTINATION"
fi