forked from open-component-model/open-component-model
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
187 lines (170 loc) · 5.85 KB
/
Taskfile.yml
File metadata and controls
187 lines (170 loc) · 5.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
version: '3'
includes:
reuse: ../reuse.Taskfile.yml
vars:
IMAGE_TOOL: docker
INTEGRATION_TEST_IDENTIFIER: 'Integration'
CLI_DOCUMENTATION_MODE: "markdown"
CLI_DOCUMENTATION_DIRECTORY: tmp/docs
PROVIDER: ocm.software
NAME: cli
DEFAULT_VERSION:
sh: |
echo "0.0.0-$(date -u +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)"
VERSION: '{{ .VERSION | default .DEFAULT_VERSION }}'
COMPONENT_CONSTRUCTOR_FILE: "{{ .TASKFILE_DIR }}/tmp/component-constructor.yaml"
CTF_LOCATION: '{{ .TASKFILE_DIR }}/tmp/transport-archive'
GOOS:
sh: |
go env GOOS
GOARCH:
sh: |
go env GOARCH
tasks:
test:
cmds:
- task: reuse:run-go-test
vars:
SKIP_PATTERN: '{{ .INTEGRATION_TEST_IDENTIFIER }}'
install:
desc: "Install the CLI"
prompt: "This will install the CLI to {{ .TARGET }}, do you want to continue?"
interactive: true
vars:
TARGET: /usr/local/bin
deps:
- task: build
cmds:
- cmd: sudo install -m 755 {{ .TASKFILE_DIR }}/tmp/bin/ocm {{ .TARGET }}
build:
desc: "Build the CLI in the Host Architecture"
deps:
- task: build:target
vars:
GOOS: '{{ .GOOS }}'
GOARCH: '{{ .GOARCH }}'
cmds:
- cmd: ln -sf {{ .TASKFILE_DIR }}/tmp/bin/ocm-{{ .GOOS }}-{{ .GOARCH }} {{ .TASKFILE_DIR }}/tmp/bin/ocm
download/deps:
internal: true
cmd: go mod download
build/multiarch:
desc: "Build CLI for all supported targets"
deps:
- for:
matrix:
GOOS: [ "windows", "linux", "darwin" ]
GOARCH: [ "amd64", "arm64" ]
task: build:target
vars:
GOOS: '{{.ITEM.GOOS }}'
GOARCH: '{{.ITEM.GOARCH }}'
build/multiarch/image:
deps: [ "build/multiarch" ]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- |
mkdir -p {{ .TASKFILE_DIR }}/tmp/oci
{{ .IMAGE_TOOL }} buildx build \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/open-component-model/cli:{{ .VERSION }} \
--output type=oci,dest={{ .TASKFILE_DIR }}/tmp/oci/cli.tar,oci-mediatypes=true,name=ghcr.io/open-component-model/cli \
-f ./Containerfile .
- |
mkdir -p {{ .TASKFILE_DIR }}/tmp/resources
cat > {{ .TASKFILE_DIR }}/tmp/resources/ocm-multi-arch-container-image.yaml <<EOF
- name: image
type: ociImage
version: {{ .VERSION }}
relation: local
input:
type: file
mediaType: application/vnd.ocm.software.oci.layout.v1+tar
path: {{ .TASKFILE_DIR }}/tmp/oci/cli.tar
EOF
build:target:
desc: "Build CLI for a specific GOOS/GOARCH target"
internal: true
silent: false
prefix: '{{.GOOS}}-{{.GOARCH}}'
generates:
- tmp/bin/ocm-{{ .GOOS }}-{{ .GOARCH }}
- tmp/resources/ocm-{{ .GOOS }}-{{ .GOARCH }}.yaml
cmds:
- cmd: |
CGO_ENABLED=0 GOOS={{ .GOOS }} GOARCH={{ .GOARCH }} go build \
-ldflags "-s -w -X ocm.software/open-component-model/cli/cmd/version.BuildVersion={{ .VERSION }}" \
-o {{ .TASKFILE_DIR }}/tmp/bin/ocm-{{ .GOOS }}-{{ .GOARCH }}
- |
mkdir -p {{ .TASKFILE_DIR }}/tmp/resources
cat > {{ .TASKFILE_DIR }}/tmp/resources/ocm-{{ .GOOS }}-{{ .GOARCH }}.yaml <<EOF
- name: cli
type: executable
version: {{ .VERSION }}
labels:
- name: downloadName
value: ocm
extraIdentity:
os: {{ .GOOS }}
architecture: {{ .GOARCH }}
relation: local
input:
type: file
path: {{ .TASKFILE_DIR }}/tmp/bin/ocm-{{ .GOOS }}-{{ .GOARCH }}
EOF
generate/ctf:
deps:
- task: generate/component-constructor
- task: build
desc: "Generate the component-constructor.yaml and build the CLI for all targets, then generate the CTF containing the Component Version"
cmd: |
rm -rf {{ .CTF_LOCATION }}
{{ .TASKFILE_DIR }}/tmp/bin/ocm add component-versions \
--constructor {{ .COMPONENT_CONSTRUCTOR_FILE }} \
--repository {{ .CTF_LOCATION }}
verify/ctf:
desc: "Verify the CTF by checking the component version and being able to fetch and run the CLI for the Host Architecture"
silent: true
vars:
REFERENCE: '{{ .CTF_LOCATION }}//{{ .PROVIDER }}/{{ .NAME }}'
dir: '{{ .TASKFILE_DIR }}/tmp/verify-ctf'
cmd: |
VERSION=$({{ .TASKFILE_DIR }}/tmp/bin/ocm get component-version {{ .REFERENCE }} -oyaml --loglevel=error | yq .[0].component.version)
if [ -z "$VERSION" ]; then
echo "Component version not found in CTF at {{ .REFERENCE }}"
exit 1
fi
echo "Component version found: $VERSION"
{{ .TASKFILE_DIR }}/tmp/bin/ocm download resource {{ .REFERENCE }}:$VERSION \
--identity name=cli,os={{ .GOOS }},architecture={{ .GOARCH }}
chmod +x ./ocm
./ocm version
generate/component-constructor:
desc: "Generate the component-constructor.yaml by building the CLI for all targets"
generates:
- '{{ .COMPONENT_CONSTRUCTOR_FILE }}'
silent: true
cmds:
- task: download/deps
- task: build/multiarch/image
silent: true
- |
cat <<EOF > {{ .COMPONENT_CONSTRUCTOR_FILE }}
name: {{ .PROVIDER }}/{{ .NAME }}
version: {{ .VERSION }}
provider:
name: {{ .PROVIDER }}
resources:
EOF
- |
for file in {{ .TASKFILE_DIR }}/tmp/resources/*.yaml; do
# Indent each line by 2 spaces and append
cat "$file" >> {{ .COMPONENT_CONSTRUCTOR_FILE }}
done
- cat "{{ .COMPONENT_CONSTRUCTOR_FILE }}"
generate/docs:
desc: "Generate CLI Markdown documentation"
cmd: |
go run {{ .TASKFILE_DIR }}/main.go generate docs \
--directory {{ .CLI_DOCUMENTATION_DIRECTORY }} \
--mode {{ .CLI_DOCUMENTATION_MODE }}