Skip to content

Commit 799193e

Browse files
feat(build): add mutate image spec config feature (#6578)
Signed-off-by: Yaroslav Pershin <62902094+iapershin@users.noreply.github.com> Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com> Co-authored-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
1 parent 30b50c4 commit 799193e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1529
-32
lines changed

docs/_data/werf_yaml.yml

Lines changed: 164 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,47 @@ sections:
3333
description:
3434
en: "Enable layer-by-layer caching of Dockerfile instructions in container registry globally for all images"
3535
ru: "Включить послойное кеширование инструкций Dockerfile в container registry глобально для всех образов"
36+
- name: imageSpec
37+
description:
38+
en: Global image configuration options according to the OCI specification, which will be applied to all images
39+
ru: Глобальная конфигурация образов согласно OCI спецификации, которая применяется ко всем образам
40+
collapsible: true
41+
isCollapsedByDefault: false
42+
detailsCustomLinks:
43+
en:
44+
- text: Changing image configuration spec
45+
article: "/usage/build/images.md#changing-image-configuration-spec"
46+
ru:
47+
- text: Изменение конфигурации образов
48+
article: "/usage/build/images.md#изменение-конфигурации-образов"
49+
directives:
50+
- name: author
51+
value: "string"
52+
description:
53+
en: Author of the image
54+
ru: Автор образа
55+
- name: clearHistory
56+
value: "bool"
57+
description:
58+
en: Remove all image build history
59+
ru: Удалить всю историю сборки образа
60+
- name: config
61+
description:
62+
en: Common image configuration
63+
ru: Общая конфигурация образа
64+
collapsible: true
65+
isCollapsedByDefault: false
66+
directives:
67+
- name: clearWerfLabels
68+
value: "bool"
69+
description:
70+
en: Clear werf labels
71+
ru: Сбросить метки werf
72+
- name: removeLabels
73+
value: "[ string || /REGEXP/, ... ]"
74+
description:
75+
en: List of labels to remove
76+
ru: Список меток для удаления
3677
- name: deploy
3778
description:
3879
en: Settings for deployment
@@ -328,6 +369,126 @@ sections:
328369
description:
329370
en: "Name of build argument which will contain specified type of information about image"
330371
ru: "Имя аргумента (Dockerfile build-args), который будет содержать указанный тип информации об образе"
372+
- &common_image_spec_config
373+
name: imageSpec
374+
description:
375+
en: Image configuration according to the OCI specification
376+
ru: Конфигурация образа согласно OCI спецификации
377+
detailsCustomLinks:
378+
en:
379+
- text: Changing image configuration spec
380+
article: "/usage/build/images.md#changing-image-configuration-spec"
381+
ru:
382+
- text: Изменение конфигурации образов
383+
article: "/usage/build/images.md#изменение-конфигурации-образов"
384+
directives:
385+
- name: author
386+
value: "string"
387+
description:
388+
en: Author of the image
389+
ru: Автор образа
390+
- name: clearHistory
391+
value: "bool"
392+
description:
393+
en: Remove all image build history
394+
ru: Удалить всю историю сборки образа
395+
- name: config
396+
description:
397+
en: Common image configuration
398+
ru: Общая конфигурация образа
399+
collapsible: true
400+
isCollapsedByDefault: false
401+
directives:
402+
- name: clearWerfLabels
403+
value: "bool"
404+
description:
405+
en: Clear werf labels
406+
ru: Сбросить метки werf
407+
- name: removeLabels
408+
value: "[ string || /REGEXP/, ... ]"
409+
description:
410+
en: List of labels to remove
411+
ru: Список меток для удаления
412+
- name: removeVolumes
413+
value: "[string, ...]"
414+
description:
415+
en: List of volumes to remove
416+
ru: Список томов для удаления
417+
- name: removeEnv
418+
value: "[string, ...]"
419+
description:
420+
en: List of environment variables to remove
421+
ru: Список переменных окружения для удаления
422+
- name: clearEntrypoint
423+
value: "bool"
424+
description:
425+
en: Remove ENTRYPOINT
426+
ru: Очистить ENTRYPOINT
427+
- name: clearCmd
428+
value: "bool"
429+
description:
430+
en: Remove CMD
431+
ru: Очистить CMD
432+
- name: volumes
433+
value: "[string, ...]"
434+
description:
435+
en: List of volumes to add
436+
ru: Список томов для добавления
437+
detailsLink: "https://docs.docker.com/engine/reference/builder/#volume"
438+
- name: labels
439+
value: "{ name string: value string, ... }"
440+
description:
441+
en: List of labels to add
442+
ru: Список меток для добавления
443+
detailsLink: "https://docs.docker.com/engine/reference/builder/#label"
444+
- name: env
445+
value: "{ name string: value string, ... }"
446+
description:
447+
en: List of environment variables to add
448+
ru: Список переменных окружения для добавления
449+
detailsLink: "https://docs.docker.com/engine/reference/builder/#env"
450+
- name: expose
451+
value: "[string, ...]"
452+
description:
453+
en: Set exposed ports
454+
ru: Установить порты открытые порты
455+
detailsLink: "https://docs.docker.com/engine/reference/builder/#expose"
456+
- name: user
457+
value: "string"
458+
description:
459+
en: Set user
460+
ru: Установить пользователя
461+
detailsLink: "https://docs.docker.com/engine/reference/builder/#user"
462+
- name: cmd
463+
value: "[string, ...]"
464+
description:
465+
en: Set CMD
466+
ru: Установить CMD
467+
detailsLink: "https://docs.docker.com/engine/reference/builder/#cmd"
468+
- name: entrypoint
469+
value: "[string, ...]"
470+
description:
471+
en: Set ENTRYPOINT
472+
ru: Установить ENTRYPOINT
473+
detailsLink: "https://docs.docker.com/engine/reference/builder/#entrypoint"
474+
- name: workingDir
475+
value: "string"
476+
description:
477+
en: Set WORKDIR
478+
ru: Установить WORKDIR
479+
detailsLink: "https://docs.docker.com/engine/reference/builder/#workdir"
480+
- name: stopSignal
481+
value: "string"
482+
description:
483+
en: Set STOPSIGNAL
484+
ru: Установить STOPSIGNAL
485+
detailsLink: "https://docs.docker.com/engine/reference/builder/#stopsignal"
486+
- name: healthcheck
487+
value: "{ test: [string, ...], interval: string, retries: int }"
488+
description:
489+
en: Healthcheck configuration. Intervals are in seconds.
490+
ru: Конфигурация проверки состояния. Интервалы в секундах.
491+
detailsLink: "https://docs.docker.com/engine/reference/builder/#healthcheck"
331492

332493
- id: stapel-section
333494
description:
@@ -655,10 +816,11 @@ sections:
655816
detailsArticle:
656817
en: "/usage/build/stapel/instructions.html#dependency-on-the-cacheversion"
657818
ru: "/usage/build/stapel/instructions.html#зависимость-от-значения-cacheversion"
819+
- <<: *common_image_spec_config
658820
- name: docker
659821
description:
660-
en: "Set of directives to effect on an image manifest"
661-
ru: "Набор директив для изменения манифеста образа"
822+
en: "Set of directives to change the image manifest (DEPRECATED). Incompatible with the imageSpec directive"
823+
ru: "Набор директив для изменения манифеста образа (DEPRECATED). Несовместимо с директивой imageSpec"
662824
detailsArticle:
663825
all: "/usage/build/stapel/dockerfile.html"
664826
collapsible: true

docs/_includes/reference/cli/werf_build.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ werf build [IMAGE_NAME...] [options]
174174
STAGE_NAME should be one of the following: from, beforeInstall,
175175
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
176176
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
177-
dockerInstructions, dockerfile
177+
dockerInstructions, dockerfile, imageSpec
178178
--kube-config=''
179179
Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or
180180
$KUBECONFIG)

docs/_includes/reference/cli/werf_bundle_publish.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ werf bundle publish [IMAGE_NAME...] [options]
170170
STAGE_NAME should be one of the following: from, beforeInstall,
171171
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
172172
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
173-
dockerInstructions, dockerfile
173+
dockerInstructions, dockerfile, imageSpec
174174
--kube-config=''
175175
Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or
176176
$KUBECONFIG)

docs/_includes/reference/cli/werf_converge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ werf converge --repo registry.mydomain.com/web --env production
208208
STAGE_NAME should be one of the following: from, beforeInstall,
209209
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
210210
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
211-
dockerInstructions, dockerfile
211+
dockerInstructions, dockerfile, imageSpec
212212
--kube-api-server=''
213213
Kubernetes API server address (default $WERF_KUBE_API_SERVER)
214214
--kube-burst-limit=100

docs/_includes/reference/cli/werf_export.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ werf export [IMAGE_NAME...] [options]
133133
STAGE_NAME should be one of the following: from, beforeInstall,
134134
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
135135
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
136-
dockerInstructions, dockerfile
136+
dockerInstructions, dockerfile, imageSpec
137137
--kube-config=''
138138
Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or
139139
$KUBECONFIG)

docs/_includes/reference/cli/werf_helm_get_autogenerated_values.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ werf helm get-autogenerated-values [IMAGE_NAME...] [options]
119119
STAGE_NAME should be one of the following: from, beforeInstall,
120120
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
121121
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
122-
dockerInstructions, dockerfile
122+
dockerInstructions, dockerfile, imageSpec
123123
--kube-config=''
124124
Kubernetes config file path (default $WERF_KUBE_CONFIG, or $WERF_KUBECONFIG, or
125125
$KUBECONFIG)

docs/_includes/reference/cli/werf_plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ werf plan --repo registry.mydomain.com/web --env production
196196
STAGE_NAME should be one of the following: from, beforeInstall,
197197
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
198198
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
199-
dockerInstructions, dockerfile
199+
dockerInstructions, dockerfile, imageSpec
200200
--kube-api-server=''
201201
Kubernetes API server address (default $WERF_KUBE_API_SERVER)
202202
--kube-burst-limit=100

docs/_includes/reference/cli/werf_render.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ werf render [IMAGE_NAME...] [options]
145145
STAGE_NAME should be one of the following: from, beforeInstall,
146146
dependenciesBeforeInstall, gitArchive, install, dependenciesAfterInstall, beforeSetup,
147147
dependenciesBeforeSetup, setup, dependenciesAfterSetup, gitCache, gitLatestPatch,
148-
dockerInstructions, dockerfile
148+
dockerInstructions, dockerfile, imageSpec
149149
--kube-api-server=''
150150
Kubernetes API server address (default $WERF_KUBE_API_SERVER)
151151
--kube-burst-limit=100

docs/pages_en/usage/build/images.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,97 @@ import:
382382

383383
For more info on how to write Stapel instructions refer to the [documentation]({{"usage/build/stapel/base.html" | true_relative_url }}).
384384

385+
## Changing image configuration spec
386+
387+
In OCI (Open Container Initiative), [image configuration spec](https://github.com/opencontainers/image-spec/blob/main/config.md) is the image specification that describes its structure and metadata. The `imageSpec` directive in `werf.yaml` provides flexible options for managing and configuring various aspects of images:
388+
389+
- Flexibility in managing specification fields.
390+
- Removal or resetting of unnecessary components: labels, environment variables, volumes, commands, and build history.
391+
- A unified configuration mechanism for all supported backends and syntaxes.
392+
- Rules that apply both to all images in a project and to individual images.
393+
394+
### Global configuration
395+
396+
Example configuration that will apply to all images in the project:
397+
398+
```yaml
399+
project: test
400+
configVersion: 1
401+
build:
402+
imageSpec:
403+
author: "Frontend Maintainer <frontend@example.com>"
404+
clearHistory: true
405+
config:
406+
removeLabels:
407+
- "unnecessary-label"
408+
- /org.opencontainers.image..*/
409+
labels:
410+
app: "my-app"
411+
```
412+
413+
This configuration will be applied to all images in the project: labels and author will be set for all images, and unnecessary labels will be removed.
414+
415+
### Configuration for a specific image
416+
417+
Example configuration for an individual image:
418+
419+
```yaml
420+
project: test
421+
configVersion: 1
422+
---
423+
image: frontend_image
424+
from: alpine
425+
imageSpec:
426+
author: "Frontend Maintainer <frontend@example.com>"
427+
clearHistory: true
428+
config:
429+
user: "1001:1001"
430+
exposedPorts:
431+
- "8080/tcp"
432+
env:
433+
NODE_ENV: "production"
434+
API_URL: "https://api.example.com"
435+
entrypoint:
436+
- "/usr/local/bin/start.sh"
437+
volumes:
438+
- "/app/data"
439+
workingDir: "/app"
440+
labels:
441+
frontend-version: "1.2.3"
442+
stopSignal: "SIGTERM"
443+
removeLabels:
444+
- "old-frontend-label"
445+
- /old-regex-label.*/
446+
removeVolumes:
447+
- "/var/cache"
448+
removeEnv:
449+
- "DEBUG"
450+
```
451+
452+
> **Note:** Configuration for a specific image takes precedence over global configuration. String values will be overwritten, and for multi-valued directives, the data will be merged based on priority.
453+
454+
### Build process changes
455+
456+
Changing the image configuration does not directly affect the build process but allows you to configure aspects such as removing unnecessary volumes or adding environment variables for the base image. Example:
457+
458+
```yaml
459+
image: base
460+
from: postgres:12.22-bookworm
461+
imageSpec:
462+
config:
463+
removeVolumes:
464+
- "/var/lib/postgresql/data"
465+
---
466+
image: app
467+
fromImage: base
468+
git:
469+
add: /postgresql/data
470+
to: /var/lib/postgresql/data
471+
```
472+
473+
In this example, the base image `postgres:12.22-bookworm` has unnecessary volumes removed, which can then be used in the `app` image.
474+
475+
385476
## Linking images
386477

387478
### Inheritance and importing files

docs/pages_en/usage/build/stapel/dockerfile.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ author: Alexey Igrychev <alexey.igrychev@flant.com>
55
directive_summary: docker
66
---
77

8+
> The `docker` directive is deprecated and will be removed in v3. Please use the `imageSpec` directive instead. Read more about the `imageSpec` directive [here]({{ "usage/build/images.html#changing-image-configuration-spec" | true_relative_url }}).
9+
810
[Dockerfile instructions](https://docs.docker.com/engine/reference/builder/) can be divided into two groups: build-time instructions and other instructions affecting an image manifest. Build-time instructions do not make sense in a werf build process. Thus, werf supports only following instructions:
911

1012
* `USER` to set the user name (or UID) and optionally the user group (or GID) (read more [here](https://docs.docker.com/engine/reference/builder/#user)).

0 commit comments

Comments
 (0)