|
| 1 | +apiVersion: tekton.dev/v1beta1 |
| 2 | +kind: StepAction |
| 3 | +metadata: |
| 4 | + name: cache-upload |
| 5 | + annotations: |
| 6 | + tekton.dev/pipelines.minVersion: "0.56.0" |
| 7 | + tekton.dev/tags: "cache" |
| 8 | +spec: |
| 9 | + params: |
| 10 | + - name: patterns |
| 11 | + description: | |
| 12 | + Regular expression to select files to include to compute the hash. |
| 13 | + For example, in the case of a Go project, you can use `go.mod` for this, so the value would be "**/go.sum" (to work with possible sub go modules as well). |
| 14 | + type: array |
| 15 | + - name: target |
| 16 | + description: | |
| 17 | + The target from where the cache should be uploaded. It's a URI with the scheme defining the "provider". In addition, one can add a {{hash}} variable to use the computed hash in the reference (oci image tags, path in s3, …) |
| 18 | + Currently supported: |
| 19 | + - oci:// (e.g. oci://quay.io/vdemeester/go-cache:{{hash}} |
| 20 | + - s3:// (e.g. s3:// |
| 21 | + type: string |
| 22 | + - name: cachePath |
| 23 | + description: | |
| 24 | + Path where to extract the cache content. |
| 25 | + It can refer any folder, backed by a workspace or a volume, or nothing. |
| 26 | + type: string |
| 27 | + - name: workingdir |
| 28 | + description: | |
| 29 | + The working dir from where the files patterns needs to be taken |
| 30 | + type: string |
| 31 | + - name: insecure |
| 32 | + description: | |
| 33 | + Whether to use insecure mode for fetching the cache |
| 34 | + type: string |
| 35 | + default: "false" |
| 36 | + - name: fetched |
| 37 | + description: | |
| 38 | + Wether cache was fetched or not previously |
| 39 | + type: string |
| 40 | + default: "false" |
| 41 | + - name: force-cache-upload |
| 42 | + description: | |
| 43 | + Whether to force the cache upload even if it was fetched previously |
| 44 | + type: string |
| 45 | + default: "false" |
| 46 | + - name: googleCredentialsPath |
| 47 | + description: | |
| 48 | + The path where to find the google credentials. If left empty, it is ignored. |
| 49 | + type: string |
| 50 | + default: "" |
| 51 | + - name: awsConfigFile |
| 52 | + description: | |
| 53 | + The path to the aws config file. If left empty, it is ignored. |
| 54 | + type: string |
| 55 | + default: "" |
| 56 | + - name: awsCredentialFile |
| 57 | + description: | |
| 58 | + The path to find the aws credentials file. If left empty, it is ignored. |
| 59 | + type: string |
| 60 | + default: "" |
| 61 | + - name: blobQueryParams |
| 62 | + description: | |
| 63 | + Blob Query Params to support configure s3, gcs and azure. This is optional unless some additional features of storage providers are required like s3 acceleration, fips, pathstyle,etc |
| 64 | + type: string |
| 65 | + default: "" |
| 66 | + env: |
| 67 | + - name: PARAM_TARGET |
| 68 | + value: $(params.target) |
| 69 | + - name: PARAM_CACHE_PATH |
| 70 | + value: $(params.cachePath) |
| 71 | + - name: PARAM_WORKINGDIR |
| 72 | + value: $(params.workingdir) |
| 73 | + - name: PARAM_INSECURE |
| 74 | + value: $(params.insecure) |
| 75 | + - name: RESULT_CACHE_FETCHED |
| 76 | + value: $(params.fetched) |
| 77 | + - name: PARAM_FORCE_CACHE_UPLOAD |
| 78 | + value: $(params.force-cache-upload) |
| 79 | + - name: GOOGLE_APPLICATION_CREDENTIALS |
| 80 | + value: $(params.googleCredentialsPath) |
| 81 | + - name: AWS_CONFIG_FILE |
| 82 | + value: $(params.awsConfigFile) |
| 83 | + - name: AWS_SHARED_CREDENTIALS_FILE |
| 84 | + value: $(params.awsCredentialFile) |
| 85 | + - name: BLOB_QUERY_PARAMS |
| 86 | + value: $(params.blobQueryParams) |
| 87 | + image: ghcr.io/chmouel/tekton-caches/cache@sha256:7b543966be2c4ef9bc439c0a6d262dd0f284216c7c292ba35c15b9ef5bca84c6 |
| 88 | + args: ["$(params.patterns[*])"] |
| 89 | + script: | |
| 90 | + #!/usr/bin/env sh |
| 91 | + set -x |
| 92 | + if [[ ${PARAM_FORCE_CACHE_UPLOAD} == "false" && ${RESULT_CACHE_FETCHED} == "true" ]]; then |
| 93 | + echo "no need to upload cache" |
| 94 | + exit 0 |
| 95 | + fi |
| 96 | +
|
| 97 | + PATTERN_FLAGS="" |
| 98 | + echo "Patterns: $*" |
| 99 | + for p in $*; do |
| 100 | + PATTERN_FLAGS="${PATTERN_FLAGS} --pattern ${p}" |
| 101 | + done |
| 102 | +
|
| 103 | + # Try three times |
| 104 | + for i in {1..3};do |
| 105 | + /ko-app/cache upload ${PATTERN_FLAGS} \ |
| 106 | + --target ${PARAM_TARGET} \ |
| 107 | + --folder ${PARAM_CACHE_PATH} \ |
| 108 | + --insecure ${PARAM_INSECURE} \ |
| 109 | + --workingdir ${PARAM_WORKINGDIR} |
| 110 | + ret=$? |
| 111 | + if [[ ${ret} == 0 ]];then |
| 112 | + exit 0 |
| 113 | + fi |
| 114 | + done |
| 115 | + exit 1 |
0 commit comments