@@ -3,7 +3,7 @@ kind: Task
3
3
metadata :
4
4
name : go-crane-image
5
5
labels :
6
- app.kubernetes.io/version : " 0.2.1 "
6
+ app.kubernetes.io/version : " 0.3.0 "
7
7
annotations :
8
8
tekton.dev/pipelines.minVersion : " 0.40.0"
9
9
tekton.dev/categories : language
@@ -12,140 +12,137 @@ metadata:
12
12
tekton.dev/platforms : " linux/amd64,linux/s390x,linux/ppc64le,linux/arm64"
13
13
spec :
14
14
description : >-
15
- The go-crane-image Task will build a container image based of off a go
16
- project to be compiled, using crane.
15
+ The go-crane-image Task will build a container image based of off a go project to be compiled, using crane.
17
16
workspaces :
18
- - name : source
19
- description : The go source to build
20
- - name : dockerconfig
21
- description : Includes a docker `config.json` or `.dockerconfigjson`
22
- optional : true
17
+ - name : source
18
+ description : The go source to build
19
+ - name : dockerconfig
20
+ description : Includes a docker `config.json` or `.dockerconfigjson`
21
+ optional : true
23
22
params :
24
- - name : app
25
- description : >-
26
- The name of the "application" to build. This will have an impact on the binary
27
- and possibly the image reference
28
- - name : package
29
- description : >-
30
- The package to build. It needs to be a package `main` that compiles into a binary.
31
- The default value is `.`, usual value can be `./cmd/{name}`
32
- default : .
33
- - name : image
34
- description : >-
35
- The image specific options such as prefix, labels, env, …
36
- type : object
37
- properties :
38
- base : {type: string}
39
- labels : {type: string}
40
- envs : {type: string}
41
- push : {type: string}
42
- prefix : {type: string}
43
- tag : {type: string}
44
- default :
45
- base : " "
46
- labels : " "
47
- envs : " "
48
- push : " true"
49
- tag : " latest"
50
- - name : go
51
- description : >-
52
- Golang options, such as flags, version, …
53
- type : object
54
- properties :
55
- version : {type: string}
56
- GOFLAGS : {type: string}
57
- GOOS : {type: string}
58
- GOARCH : {type: string}
59
- CGO_ENABLED : {type: string}
60
- default :
61
- version : " 1.18"
62
- GOFLAGS : " -v"
63
- GOOS : " "
64
- GOARCH : " "
65
- CGO_ENABLED : " 0"
23
+ - name : app
24
+ description : >-
25
+ The name of the "application" to build. This will have an impact on the binary and possibly the image reference
26
+ - name : package
27
+ description : >-
28
+ The package to build. It needs to be a package `main` that compiles into a binary. The default value is `.`, usual value can be `./cmd/{name}`
29
+ default : .
30
+ - name : image
31
+ description : >-
32
+ The image specific options such as prefix, labels, env, …
33
+ type : object
34
+ properties :
35
+ base : {type: string}
36
+ labels : {type: string}
37
+ envs : {type: string}
38
+ push : {type: string}
39
+ prefix : {type: string}
40
+ tag : {type: string}
41
+ default :
42
+ base : " "
43
+ labels : " "
44
+ envs : " "
45
+ push : " true"
46
+ tag : " latest"
47
+ - name : go
48
+ description : >-
49
+ Golang options, such as flags, version, …
50
+ type : object
51
+ properties :
52
+ version : {type: string}
53
+ GOFLAGS : {type: string}
54
+ GOOS : {type: string}
55
+ GOARCH : {type: string}
56
+ CGO_ENABLED : {type: string}
57
+ default :
58
+ version : " 1.18"
59
+ GOFLAGS : " -v"
60
+ GOOS : " "
61
+ GOARCH : " "
62
+ CGO_ENABLED : " 0"
66
63
results :
67
64
- name : IMAGE_DIGEST
68
65
description : Digest of the image just built.
69
66
- name : IMAGE_URL
70
67
description : URL of the image just built.
71
68
steps :
72
- - name : build-go
73
- image : docker.io/library/golang:$(params.go.version)
74
- workingDir : $(workspaces.source.path)
75
- script : |
76
- #!/usr/bin/env bash
77
- set -e
78
- go env
79
- go build -o $(params.app) $(params.package)
80
- env :
81
- - name : GOFLAGS
82
- value : " $(params.go.GOFLAGS)"
83
- - name : GOOS
84
- value : " $(params.go.GOOS)"
85
- - name : GOARCH
86
- value : " $(params.go.GOARCH)"
87
- - name : CGO_ENABLED
88
- value : " $(params.go.CGO_ENABLED)"
89
- - name : publish-image
90
- image : ghcr.io/shortbrain/golang-tasks/crane:main
91
- workingDir : $(workspaces.source.path)
92
- script : |
93
- #!/usr/bin/env bash
94
- set -e
69
+ - name : build-go
70
+ image : docker.io/library/golang:$(params.go.version)
71
+ workingDir : $(workspaces.source.path)
72
+ script : |
73
+ #!/usr/bin/env bash
74
+ set -e
75
+ go env
76
+ go build -o $(params.app) $(params.package)
77
+ env :
78
+ - name : GOFLAGS
79
+ value : " $(params.go.GOFLAGS)"
80
+ - name : GOOS
81
+ value : " $(params.go.GOOS)"
82
+ - name : GOARCH
83
+ value : " $(params.go.GOARCH)"
84
+ - name : CGO_ENABLED
85
+ value : " $(params.go.CGO_ENABLED)"
86
+ - name : publish-image
87
+ image : ghcr.io/shortbrain/golang-tasks/crane:main
88
+ workingDir : $(workspaces.source.path)
89
+ script : |
90
+ #!/usr/bin/env bash
91
+ set -e
95
92
96
- if [[ "$(params.image.push)" == "false" ]]; then
97
- echo "Not doing anything as push is disabled"
98
- echo -n "" > $(resutls.IMAGE_DIGEST.path)
99
- echo -n "" > $(resutls.IMAGE_URL.path)
100
- exit 0
101
- fi
93
+ if [[ "$(params.image.push)" == "false" ]]; then
94
+ echo "Not doing anything as push is disabled"
95
+ echo -n "" > $(resutls.IMAGE_DIGEST.path)
96
+ echo -n "" > $(resutls.IMAGE_URL.path)
97
+ exit 0
98
+ fi
99
+
100
+ # Prepare the layer to add
101
+ mkdir output
102
+ cp $(params.app) ./output
103
+ # FIXME: extra things to copy ?
102
104
103
- # Prepare the layer to add
104
- mkdir output
105
- cp $(params.app) ./output
106
- # FIXME: extra things to copy ?
107
-
108
- if [[ "$(workspaces.dockerconfig.bound)" == "true" ]]; then
109
- # if config.json exists at workspace root, we use that
110
- if test -f "$(workspaces.dockerconfig.path)/config.json"; then
111
- export DOCKER_CONFIG="$(workspaces.dockerconfig.path)"
112
- # else we look for .dockerconfigjson at the root
113
- elif test -f "$(workspaces.dockerconfig.path)/.dockerconfigjson"; then
114
- cp "$(workspaces.dockerconfig.path)/.dockerconfigjson" "$HOME/.docker/config.json"
115
- export DOCKER_CONFIG="$HOME/.docker"
116
- # need to error out if neither files are present
117
- else
118
- echo "neither 'config.json' nor '.dockerconfigjson' found at workspace root"
119
- exit 1
105
+ if [[ "$(workspaces.dockerconfig.bound)" == "true" ]]; then
106
+ # if config.json exists at workspace root, we use that
107
+ if test -f "$(workspaces.dockerconfig.path)/config.json"; then
108
+ export DOCKER_CONFIG="$(workspaces.dockerconfig.path)"
109
+ # else we look for .dockerconfigjson at the root
110
+ elif test -f "$(workspaces.dockerconfig.path)/.dockerconfigjson"; then
111
+ cp "$(workspaces.dockerconfig.path)/.dockerconfigjson" "$HOME/.docker/config.json"
112
+ export DOCKER_CONFIG="$HOME/.docker"
113
+ # need to error out if neither files are present
114
+ else
115
+ echo "neither 'config.json' nor '.dockerconfigjson' found at workspace root"
116
+ exit 1
117
+ fi
120
118
fi
121
- fi
122
119
123
- APPEND_FLAGS="--new_tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
124
- if [[ -n "$(params.image.base)" ]]; then
125
- APPEND_FLAGS="--base $(params.image.base) ${APPEND_FLAGS}"
126
- fi
120
+ APPEND_FLAGS="--new_tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
121
+ if [[ -n "$(params.image.base)" ]]; then
122
+ APPEND_FLAGS="--base $(params.image.base) ${APPEND_FLAGS}"
123
+ fi
127
124
128
- MUTATE_FLAGS="--entrypoint=/$(params.app) --tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
129
- # envs
130
- while IFS=';' read -ra ENVS; do
131
- for ENV in "${ENVS[@]}"; do
132
- MUTATE_FLAGS="${MUTATE_FLAGS} --env ${ENV}"
133
- done
134
- done <<< "$(params.image.envs)"
125
+ MUTATE_FLAGS="--entrypoint=/$(params.app) --tag $(params.image.prefix)/$(params.app):$(params.image.tag)"
126
+ # envs
127
+ while IFS=';' read -ra ENVS; do
128
+ for ENV in "${ENVS[@]}"; do
129
+ MUTATE_FLAGS="${MUTATE_FLAGS} --env ${ENV}"
130
+ done
131
+ done <<< "$(params.image.envs)"
135
132
136
- # labels
137
- while IFS=';' read -ra LABELS; do
138
- for LABEL in "${LABELS[@]}"; do
139
- MUTATE_FLAGS="${MUTATE_FLAGS} --label ${LABEL}"
140
- done
141
- done <<< "$(params.image.labels)"
133
+ # labels
134
+ while IFS=';' read -ra LABELS; do
135
+ for LABEL in "${LABELS[@]}"; do
136
+ MUTATE_FLAGS="${MUTATE_FLAGS} --label ${LABEL}"
137
+ done
138
+ done <<< "$(params.image.labels)"
142
139
143
- crane mutate $( \
144
- crane append ${APPEND_FLAGS} \
145
- --new_layer <(cd ./output && tar -f - -c .) \
146
- ) \
147
- ${MUTATE_FLAGS} > crane_output
148
- CRANE_OUTPUT=$(cat crane_output)
149
- echo -n ${CRANE_OUTPUT#*@} > $(results.IMAGE_DIGEST.path)
150
- echo -n ${CRANE_OUTPUT} > $(results.IMAGE_URL.path)
151
- # echo -n ${CRANE_OUTPUT%@*} > $(results.IMAGE_URL.path)
140
+ crane mutate $( \
141
+ crane append ${APPEND_FLAGS} \
142
+ --new_layer <(cd ./output && tar -f - -c .) \
143
+ ) \
144
+ ${MUTATE_FLAGS} > crane_output
145
+ CRANE_OUTPUT=$(cat crane_output)
146
+ echo -n ${CRANE_OUTPUT#*@} > $(results.IMAGE_DIGEST.path)
147
+ echo -n ${CRANE_OUTPUT} > $(results.IMAGE_URL.path)
148
+ # echo -n ${CRANE_OUTPUT%@*} > $(results.IMAGE_URL.path)
0 commit comments