-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflows.lib.yml
204 lines (189 loc) · 5.51 KB
/
workflows.lib.yml
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#@ load("@ytt:data", "data")
#@ load("@ytt:overlay", "overlay")
#@ def pull_request_defaults(data_values=None):
push:
branches:
#@ if hasattr(data_values,"git"):
#@ for branch in data_values.git.branches:
- #@ branch
#@ end
#@ else:
- master
- main
- F/*
- f/*
- R/*
- r/*
- B/*
- b/*
#@ end
#@ end
#@ def image_full_tag(registry, image_name, version):
#@ return "{}/{}:{}".format(registry, image_name, version)
#@ end
#@ def image_versioned_tag(registry, image_name):
#@ return image_full_tag(registry, image_name, "${{ needs.version.outputs.issue_id_slug }}")
#@ end
#@ def tag(registry, image, suffix="${{ needs.version.outputs.issue_id_slug }}"):
#@ return image_full_tag(registry.url, image.image_name, suffix)
#@ end
#@ def tag_cache(registry, image):
#@ return tag(registry, image, "${{ needs.version.outputs.issue_id_slug }}")
#@ end
#@ def tag_version(registry, image):
#@ return tag(registry, image, "${{ needs.version.outputs.app_version }}")
#@ end
---
#@ def job_name(name,prefix="job-"):
#@ return "{}{}".format(prefix,name)
#@ end
#@ def job_name_from_slug(component, prefix="job-"):
#@ return job_name(component.slug, prefix)
#@ end
#@ def docker_build_job_name(component):
#@ return job_name_from_slug(component,"docker-build-")
#@ end
---
#@ def login_docker(registry):
name: #@ "Login to {}".format(registry.name)
uses: docker/login-action@v1
with:
registry: #@ registry.url
username: #@ registry.user
password: #@ registry.password
#@ end
---
#@ def checkout():
name: Checkout repository
uses: actions/checkout@v2
#@ end
---
#@ def setup_qemu():
name: Set up QEMU
uses: docker/setup-qemu-action@v1
#@ end
---
#@ def setup_buildx():
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
#@ end
---
#@ def checkout_private_actions():
name: Checkout GitHub Action Repos
uses: daspn/private-actions-checkout@v2
with:
actions_list: '[
"covergo/[email protected]",
"covergo/[email protected]",
"covergo/docker-extract@v1",
"covergo/[email protected]",
"covergo/set-compose-tags@v1",
"covergo/run-in-compose@v1"
]'
checkout_base_path: ./.github/actions
app_id: ${{ secrets.PRIVATE_ACTION_APP_ID }}
app_private_key: ${{ secrets.PRIVATE_ACTION_APP_PRIVATE_KEY }}
#@ end
---
#@ def default_switch(flag, value_default, value_not_default):
#@ if flag == "default":
#@ return value_default
#@ else:
#@ return value_not_default
#@ end
#@ end
---
#@ def docker_build_step_title(component_name):
#@ return "Build and publish {} docker image".format(component_name)
#@ end
---
#@ def build_and_push_docker(component, cache_registry, step_name="default", step_id="default", push_image=True, load_image=False, tag_build="default", provide_version_args=False):
name: #@ default_switch(step_name, docker_build_step_title(component.name), step_name)
uses: docker/build-push-action@v2
#@ if step_id != "default" :
id: #@ step_id
#@ end
#@ if tag_build == "default" :
#@ tag_build=tag_cache(cache_registry, component)
#@ end
with:
file: #@ component.dockerfile
#@ if push_image:
push: #@ push_image
#@ end
#@ if load_image:
load: #@ load_image
#@ end
tags: #@ tag_build
cache-from: #@ "type=registry,ref="+tag_cache(cache_registry, component)
cache-to: type=inline
#@ if provide_version_args:
build-args: |
APP_VERSION=${{ needs.version.outputs.app_version }}
FILE_VERSION=${{ needs.version.outputs.file_version }}
INFORMATIONAL_VERSION=${{ needs.version.outputs.information_version }}
#@ end
#@ end
---
#@ def image_build_job(component, cache_registry, needs=[], main_registry="skip", tag_build="default", job_name="default", load_image=False, push_image=True, provide_version_args=False, add_if=True, add_name=False):
#@ if tag_build=="default":
#@ tag_build = tag_cache(cache_registry,component)
#@ end
#@ if add_name or job_name!="default":
#@overlay/match missing_ok=True
name: #@ default_switch(job_name, docker_build_step_title(component.name), job_name)
#@overlay/match missing_ok=True
#@ end
#@ runner="ubuntu-latest"
#@ if hasattr(component,"runner"):
#@ runner = component.runner
#@ end
runs-on: #@ runner
#@overlay/match missing_ok=True
needs:
#@ for needed in needs:
#@overlay/append
- #@ needed
#@ end
#@ if add_if:
#@overlay/match missing_ok=True
if: github.event_name == 'push' && contains(toJson(github.event.commits), '[ci
skip]') == false
#@ end
#@ step_id_value="docker-build-"+component.slug
#@overlay/match missing_ok=True
steps:
#@overlay/match by=overlay.index(0)
#@overlay/insert before=True
- #@ checkout()
#@overlay/match by=overlay.index(1)
#@overlay/insert before=True
- #@ login_docker(cache_registry)
#@ if main_registry!="skip":
#@overlay/match by=overlay.index(2)
#@overlay/insert before=True
- #@ login_docker(main_registry)
#@ end
#@overlay/match by=overlay.index(3)
#@overlay/insert before=True
- #@ build_and_push_docker(component, cache_registry, step_id=step_id_value, tag_build=tag_build, provide_version_args=provide_version_args, load_image=load_image, push_image=push_image)
#@overlay/match by=overlay.index(4)
#@overlay/insert before=True
- name: Image digest
run: #@ "echo ${{ steps."+step_id_value+".outputs.digest }}"
#@ end
#@ def get_runner(component):
#@ if hasattr(component,"runner") :
#@ return component.runner
#@ else:
#@ return "ubuntu-latest"
#@ end
#@ end
---
#@ def generate_diagnostic_password(passwordSource) :
#@ if hasattr(passwordSource,"diagnostic_password") :
#@ return getattr(passwordSource,"diagnostic_password")
#@ else:
#@ return "${{ secrets.DIAGNOSTIC_PASSWORD }}$GITHUB_RUN_NUMBER"
#@ end
#@ end