Skip to content

Commit

Permalink
use more params across to be able to redefine
Browse files Browse the repository at this point in the history
add cachePatterns and image for params to configure
and make du command to be more explicits across
make only **go.mod and **go.sum to be cached not every go files.

Signed-off-by: Chmouel Boudjnah <[email protected]>
  • Loading branch information
chmouel committed Apr 30, 2024
1 parent 436c7fc commit 9157678
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
25 changes: 15 additions & 10 deletions examples/pipeline-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ spec:
- name: buildCommand
type: string
default: go build -v .
- name: cachePatterns
type: array
default: ["**go.mod", "**go.sum"]
- name: image
type: string
default: cgr.dev/chainguard/go
workspaces:
- name: source
tasks:
Expand All @@ -28,9 +34,13 @@ spec:
params:
- name: buildCommand
default: $(params.buildCommand)
- name: cachePatterns
default: $(params.cachePatterns)
- name: image
default: $(params.image)
steps:
- name: create-repo
image: cgr.dev/chainguard/go
image: $(params.image)
script: |
mkdir -p $(workspaces.source.path)/repo
chmod 777 $(workspaces.source.path)/repo
Expand All @@ -55,16 +65,14 @@ spec:
value: https://raw.githubusercontent.com/openshift-pipelines/tekton-caches/main/tekton/cache-fetch.yaml
params:
- name: patterns
value:
- "**.go"
- "**go.sum"
value: $(params.cachePatterns)
- name: source
value: oci://$(params.registry)/cache-go:{{hash}}
- name: cachePath
value: $(workspaces.source.path)/cache
- name: workingdir
value: $(workspaces.source.path)/repo
- image: cgr.dev/chainguard/go
- image: $(params.image)
workingDir: $(workspaces.source.path)/repo
name: run-go-build
env:
Expand All @@ -76,8 +84,7 @@ spec:
set -x
git config --global --add safe.directory $(workspaces.source.path)/repo
$(params.buildCommand)
du -shk $GOPATH
du -shk $GOMODCACHE
echo "Cache size is $(du -sh $(workspaces.source.path)/cache)"
- name: cache-upload
ref:
resolver: http
Expand All @@ -86,9 +93,7 @@ spec:
value: https://raw.githubusercontent.com/openshift-pipelines/tekton-caches/main/tekton/cache-upload.yaml
params:
- name: patterns
value:
- "**.go"
- "**go.sum"
value: $(params.cachePatterns)
- name: target
value: oci://$(params.registry)/cache-go:{{hash}}
- name: cachePath
Expand Down
2 changes: 2 additions & 0 deletions examples/pipelinerun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ spec:
value: main
- name: registry
value: registry.civuole.local/cache
- name: image
value: cgr.dev/chainguard/go
workspaces:
- name: source
emptyDir: {}

0 comments on commit 9157678

Please sign in to comment.