-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtemplates.py
More file actions
223 lines (207 loc) · 9.83 KB
/
templates.py
File metadata and controls
223 lines (207 loc) · 9.83 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
"""This module contains the Jinja2 templates used to generate the build
descriptions.
"""
import datetime
import jinja2
INFOHEADER_TEMPLATE = f""" Copyright (c) {datetime.datetime.now().year} SUSE LLC
All modifications and additions to the file contributed by third parties
remain the property of their copyright owners, unless otherwise agreed
upon.
The content of THIS FILE IS AUTOGENERATED and should not be manually modified.
It is maintained by the BCI team and generated by
https://github.com/SUSE/BCI-dockerfile-generator
Please submit bugfixes or comments via https://bugs.opensuse.org/
You can contact the BCI team via https://github.com/SUSE/bci/discussions"""
#: Jinja2 template used to generate :file:`Dockerfile`
DOCKERFILE_TEMPLATE = jinja2.Template(
"""# SPDX-License-Identifier: {{ image.license }}
{{ INFOHEADER }}
#!UseOBSRepositories
{% if image.exclusive_arch %}#!ExclusiveArch: {% for arch in image.exclusive_arch %}{{ arch }}{{ " " if not loop.last }}{% endfor %}{%- endif %}
{% for tag in image.build_tags -%}
#!BuildTag: {{ tag }}
{% endfor -%}
{%- if image.publish_registry.force_multiversion -%}#!ForceMultiVersion
{% endif -%}
{% if image.build_version %}#!BuildName: {{ image.build_name }}
#!BuildVersion: {{ image.build_version }}
{%- endif %}
{%- if image.build_release %}
#!BuildRelease: {{ image.build_release }}
{%- endif %}
{{ image.dockerfile_from_line }}
{%- if image.from_target_image %}
COPY --from=target / /target
{%- endif %}
{% if image.packages %}{{ DOCKERFILE_RUN }} \\
zypper -n {%- if image.from_target_image %} --installroot /target --gpg-auto-import-keys {%- endif %} install {% if image.no_recommends %}--no-recommends {% endif %}{{ image.packages }}; \\
{%- if image.packages_to_delete %}
zypper -n {%- if image.from_target_image %} --installroot /target {%- endif %} remove {{ image.packages_to_delete }}; \\
{%- endif %}
zypper -n clean; \\
{{ LOG_CLEAN }}
{%- endif %}
{% if image.from_target_image %}FROM {{ image.dockerfile_from_target_ref }}
COPY --from=builder /target /{% endif %}
# Define labels according to https://en.opensuse.org/Building_derived_containers
# labelprefix={{ image.labelprefix }}
{%- if image.maintainer %}
LABEL org.opencontainers.image.authors="{{ image.maintainer }}"
{%- endif %}
LABEL org.opencontainers.image.title="{{ image.title }}"
LABEL org.opencontainers.image.description="{{ image.description }}"
LABEL org.opencontainers.image.version="{{ image.oci_version }}"
LABEL org.opencontainers.image.url="{{ image.url }}"
LABEL org.opencontainers.image.created="%BUILDTIME%"
LABEL org.opencontainers.image.vendor="{{ image.publish_registry.vendor }}"
LABEL org.opencontainers.image.source="%SOURCEURL%"
LABEL org.opencontainers.image.ref.name="{{ image.image_ref_name }}"
LABEL org.opensuse.reference="{{ image.reference }}"
LABEL org.openbuildservice.disturl="%DISTURL%"
{%- if image.os_version.is_tumbleweed %}
LABEL org.opensuse.lifecycle-url="{{ image.lifecycle_url }}"
LABEL org.opensuse.release-stage="{{ image.release_stage }}"
{%- else %}
LABEL com.suse.supportlevel="{{ image.support_level }}"
{%- if image.supported_until %}
LABEL com.suse.supportlevel.until="{{ image.supported_until }}"
{%- endif %}
LABEL com.suse.eula="{{ image.eula }}"
LABEL com.suse.lifecycle-url="{{ image.lifecycle_url }}"
LABEL com.suse.release-stage="{{ image.release_stage }}"
{%- endif %}
# endlabelprefix
{%- if image.is_base_container_annotation_available %}
LABEL org.opencontainers.image.base.name="%BASE_REFNAME%"
LABEL org.opencontainers.image.base.digest="%BASE_DIGEST%"
{%- endif %}
LABEL io.artifacthub.package.readme-url="{{ image.readme_url }}"
{%- if image.logo_url %}
LABEL io.artifacthub.package.logo-url="{{ image.logo_url }}"
{%- endif %}
{%- if image.extra_label_lines %}{{ image.extra_label_lines }}
{%- endif %}
{%- if image.env_lines %}{{- image.env_lines }}{% endif %}
{%- if image.entrypoint_docker %}{{ image.entrypoint_docker }}{% endif %}
{%- if image.cmd_docker %}{{ image.cmd_docker }}{% endif %}
{%- if image.expose_dockerfile %}{{ image.expose_dockerfile }}{% endif %}
{% if image.dockerfile_custom_end %}{{ image.dockerfile_custom_end }}{% endif %}
{%- if image.entrypoint_user %}USER {{ image.entrypoint_user }}{% endif %}
{%- if image.workdir %}WORKDIR {{ image.workdir }}{% endif %}
{%- if image.volume_dockerfile %}{{ image.volume_dockerfile }}{% endif %}
"""
)
#: Jinja2 template used to generate :file:`$pkg_name.kiwi`
KIWI_TEMPLATE = jinja2.Template(
"""<?xml version="1.0" encoding="utf-8"?>
<!-- SPDX-License-Identifier: {{ image.license }} -->
<!--
{{ INFOHEADER }}
-->
<!-- OBS-AddTag: {% for tag in image.build_tags -%} {{ tag }} {% endfor -%}-->
{%- if image.exclusive_arch %}
<!-- OBS-ExclusiveArch:{% for arch in image.exclusive_arch %} {{ arch }}{%- endfor %} -->
{%- endif %}
{%- if image.kiwi_ignore_packages %}
<!-- OBS-IgnorePackage:{% for pkg in image.kiwi_ignore_packages %} {{ pkg }}{%- endfor %} -->
{%- endif %}
<!-- OBS-Imagerepo: obsrepositories:/ -->
<image schemaversion="7.4" name="{{ image.uid }}-image" xmlns:suse_label_helper="com.suse.label_helper">
<description type="system">
<author>{{ image.publish_registry.vendor }}</author>
<contact>https://www.suse.com/</contact>
<specification>{{ image.title }} Container Image</specification>
</description>
<preferences>
<type image="docker"{{ image.kiwi_derived_from_entry }}>
<containerconfig
name="{{ image.build_tags[0].split(':')[0] }}"
tag="{{ image.build_tags[0].split(':')[1] }}"
{%- if image.kiwi_additional_tags %}
additionaltags="{{ image.kiwi_additional_tags }}"
{%- endif %}
{%- if image.entrypoint_user %}
user="{{ image.entrypoint_user }}"
{%- endif %}
{%- if image.workdir %}
workingdir="{{ image.workdir }}"
{%- endif %}
{#- NOTE: eye sight chart: this has a closing element character '>' here: ----> -#} >
<labels>
<suse_label_helper:add_prefix prefix="{{ image.labelprefix }}">
{%- if image.maintainer %}
<label name="org.opencontainers.image.authors" value="{{ image.maintainer }}"/>
{%- endif %}
<label name="org.opencontainers.image.title" value="{{ image.title }}"/>
<label name="org.opencontainers.image.description" value="{{ image.description }}"/>
<label name="org.opencontainers.image.version" value="{{ image.oci_version }}"/>
<label name="org.opencontainers.image.created" value="%BUILDTIME%"/>
<label name="org.opencontainers.image.vendor" value="{{ image.publish_registry.vendor }}"/>
<label name="org.opencontainers.image.source" value="%SOURCEURL%"/>
<label name="org.opencontainers.image.url" value="{{ image.url }}"/>
<label name="org.opencontainers.image.ref.name" value="{{ image.image_ref_name }}"/>
<label name="org.opensuse.reference" value="{{ image.reference }}"/>
<label name="org.openbuildservice.disturl" value="%DISTURL%"/>
{%- if not image.os_version.is_tumbleweed %}
<label name="com.suse.supportlevel" value="{{ image.support_level }}"/>
{%- if image.supported_until %}
<label name="com.suse.supportlevel.until" value="{{ image.supported_until }}"/>
{%- endif %}
<label name="com.suse.eula" value="{{ image.eula }}"/>
{%- endif %}
<label name="{% if image.os_version.is_tumbleweed %}org.opensuse{% else %}com.suse{% endif %}.release-stage" value="{{ image.release_stage }}"/>
<label name="{% if image.os_version.is_tumbleweed %}org.opensuse{% else %}com.suse{% endif %}.lifecycle-url" value="{{ image.lifecycle_url }}"/>
{{- image.extra_label_xml_lines }}
</suse_label_helper:add_prefix>
{%- if image.is_base_container_annotation_available %}
<label name="org.opencontainers.image.base.name" value="%BASE_REFNAME%"/>
<label name="org.opencontainers.image.base.digest" value="%BASE_DIGEST%"/>
{%- endif %}
<label name="io.artifacthub.package.readme-url" value="{{ image.readme_url }}"/>{% if image.logo_url %}
<label name="io.artifacthub.package.logo-url" value="{{ image.logo_url }}"/>{% endif %}
</labels>
{%- if image.cmd_kiwi %}{{ image.cmd_kiwi }}{% endif %}
{%- if image.entrypoint_kiwi %}{{ image.entrypoint_kiwi }}{% endif %}
{%- if image.volumes_kiwi %}{{ image.volumes_kiwi }}{% endif %}
{%- if image.exposes_kiwi %}{{ image.exposes_kiwi }}{% endif %}
{{- image.kiwi_env_entry }}
</containerconfig>
</type>
<version>{{ image.kiwi_version }}</version>
<packagemanager>zypper</packagemanager>
<rpm-check-signatures>false</rpm-check-signatures>
<rpm-excludedocs>true</rpm-excludedocs>
</preferences>
<repository type="rpm-md">
<source path="obsrepositories:/"/>
</repository>
{{ image.kiwi_packages }}
</image>
"""
)
#: Jinja2 template used to generate :file:`_service`.
SERVICE_TEMPLATE = jinja2.Template(
"""<services>
<service mode="buildtime" name="{{ image.build_recipe_type }}_label_helper"/>
<service mode="buildtime" name="kiwi_metainfo_helper"/>
{%- set all_build_flavors = [""] %}
{%- if image.crate and image.build_flavor %}
{%- set all_build_flavors = image.crate.all_build_flavors(image) %}
{%- endif %}
{%- for flavor in all_build_flavors %}
{%- for replacement in image.replacements_via_service %}
<service name="replace_using_package_version" mode="buildtime">
<param name="file">
{%- if replacement.file_name != None %}{{replacement.file_name}}
{%- elif (image.build_recipe_type|string) == "docker" %}{% if flavor %}Dockerfile.{{ flavor }}{% else %}Dockerfile{% endif %}
{%- else %}{{ image.package_name }}.kiwi
{%- endif %}</param>
<param name="regex">{{ replacement.regex_in_build_description }}</param>
<param name="package">{{ replacement.package_name }}</param>{% if replacement.parse_version %}
<param name="parse-version">{{ replacement.parse_version }}</param>{% endif %}
</service>
{%- endfor -%}
{% endfor %}
</services>
"""
)