Skip to content

Commit 7a8c96b

Browse files
fix(build, imageSpec): resolve env issues, labels warning, and add --skip-image-spec-stage flag (#6651)
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 0049ae8 commit 7a8c96b

35 files changed

+557
-99
lines changed

Diff for: cmd/werf/build/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
113113

114114
commonCmdData.SetupPlatform(cmd)
115115

116+
commonCmdData.SetupSkipImageSpecStage(cmd)
117+
116118
return cmd
117119
}
118120

Diff for: cmd/werf/bundle/publish/publish.go

+2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
150150
commonCmdData.SetupHelmCompatibleChart(cmd, false)
151151
commonCmdData.SetupRenameChart(cmd)
152152

153+
commonCmdData.SetupSkipImageSpecStage(cmd)
154+
153155
defaultTag := os.Getenv("WERF_TAG")
154156
if defaultTag == "" {
155157
defaultTag = "latest"

Diff for: cmd/werf/common/cmd_data.go

+7
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ type CmdData struct {
132132
AllowedLocalCacheVolumeUsageMargin *uint
133133

134134
Platform *[]string
135+
136+
SkipImageSpecStage *bool
135137
}
136138

137139
func (cmdData *CmdData) SetupWithoutImages(cmd *cobra.Command) {
@@ -192,3 +194,8 @@ func (cmdData *CmdData) SetupRenameChart(cmd *cobra.Command) {
192194
cmdData.RenameChart = new(string)
193195
cmd.Flags().StringVarP(cmdData.RenameChart, "rename-chart", "", os.Getenv("WERF_RENAME_CHART"), `Force setting of chart name in the Chart.yaml of the published chart to the specified value (can be set by the $WERF_RENAME_CHART, no rename by default, could not be used together with the '--helm-compatible-chart' option).`)
194196
}
197+
198+
func (cmdData *CmdData) SetupSkipImageSpecStage(cmd *cobra.Command) {
199+
cmdData.SkipImageSpecStage = new(bool)
200+
cmd.Flags().BoolVarP(cmdData.SkipImageSpecStage, "skip-image-spec-stage", "", util.GetBoolEnvironmentDefaultFalse("WERF_SKIP_IMAGE_SPEC_STAGE"), `Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)`)
201+
}

Diff for: cmd/werf/common/conveyor_options.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func GetConveyorOptions(ctx context.Context, commonCmdData *CmdData, imagesToPro
3737
}
3838

3939
conveyorOptions.DeferBuildLog = GetDeferredBuildLog(ctx, commonCmdData)
40-
40+
if commonCmdData.SkipImageSpecStage != nil {
41+
conveyorOptions.SkipImageSpecStage = *commonCmdData.SkipImageSpecStage
42+
}
4143
return conveyorOptions, nil
4244
}
4345

Diff for: cmd/werf/compose/main.go

+2
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ func newCmd(ctx context.Context, composeCmdName string, options *newCmdOptions)
336336
// TODO: delete this flag in v3
337337
cmd.Flags().StringVarP(&cmdData.ComposeBinPath, "docker-compose-bin-path", "", os.Getenv("WERF_DOCKER_COMPOSE_BIN_PATH"), "DEPRECATED: \"docker compose\" command always used now, this option is ignored. Define docker-compose bin path (default $WERF_DOCKER_COMPOSE_BIN_PATH)")
338338

339+
commonCmdData.SetupSkipImageSpecStage(cmd)
340+
339341
return cmd
340342
}
341343

Diff for: cmd/werf/converge/converge.go

+2
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ werf converge --repo registry.mydomain.com/web --env production`,
193193
cmd.Flags().BoolVarP(&cmdData.AutoRollback, "auto-rollback", "R", util.GetBoolEnvironmentDefaultFalse("WERF_AUTO_ROLLBACK"), "Enable auto rollback of the failed release to the previous deployed release version when current deploy process have failed ($WERF_AUTO_ROLLBACK by default)")
194194
cmd.Flags().BoolVarP(&cmdData.AutoRollback, "atomic", "", util.GetBoolEnvironmentDefaultFalse("WERF_ATOMIC"), "Enable auto rollback of the failed release to the previous deployed release version when current deploy process have failed ($WERF_ATOMIC by default)")
195195

196+
commonCmdData.SetupSkipImageSpecStage(cmd)
197+
196198
return cmd
197199
}
198200

Diff for: cmd/werf/export/export.go

+2
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Also, can be specified with $WERF_EXPORT_ADD_LABEL_* (e.g. $WERF_EXPORT_ADD_LABE
141141

142142
cmd.Flags().StringVarP(&addLabelSeparator, "add-label-separator", "", defaultValue, `Separator for --add-label values (default $WERF_EXPORT_ADD_LABEL_SEPARATOR or "\n")`)
143143

144+
commonCmdData.SetupSkipImageSpecStage(cmd)
145+
144146
return cmd
145147
}
146148

Diff for: cmd/werf/helm/get_autogenerated_values.go

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func NewGetAutogeneratedValuesCmd(ctx context.Context) *cobra.Command {
109109
common.SetupRequireBuiltImages(&commonCmdData, cmd)
110110
commonCmdData.SetupPlatform(cmd)
111111

112+
commonCmdData.SetupSkipImageSpecStage(cmd)
113+
112114
return cmd
113115
}
114116

Diff for: cmd/werf/kube_run/kube_run.go

+2
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
201201
cmd.Flags().StringArrayVarP(&cmdData.CopyFrom, "copy-from", "", []string{}, "Copy file/dir from container to local machine after user command execution. Example: \"/from/file:to\". Can be specified multiple times. Can also be defined with \"$WERF_COPY_FROM_*\", e.g. \"WERF_COPY_FROM_1=from:to\".")
202202
cmd.Flags().StringArrayVarP(&cmdData.CopyTo, "copy-to", "", []string{}, "Copy file/dir from local machine to container before user command execution. Example: \"from:/to/file\". Can be specified multiple times. Can also be defined with \"$WERF_COPY_TO_*\", e.g. \"WERF_COPY_TO_1=from:to\".")
203203

204+
commonCmdData.SetupSkipImageSpecStage(cmd)
205+
204206
return cmd
205207
}
206208

Diff for: cmd/werf/plan/plan.go

+2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ werf plan --repo registry.mydomain.com/web --env production`,
188188
cmd.Flags().IntVarP(&cmdData.Timeout, "timeout", "t", int(*defaultTimeout), "Resources tracking timeout in seconds ($WERF_TIMEOUT by default)")
189189
cmd.Flags().BoolVarP(&cmdData.DetailedExitCode, "exit-code", "", util.GetBoolEnvironmentDefaultFalse("WERF_EXIT_CODE"), "If true, returns exit code 0 if no changes, exit code 2 if any changes planned or exit code 1 in case of an error (default $WERF_EXIT_CODE or false)")
190190

191+
commonCmdData.SetupSkipImageSpecStage(cmd)
192+
191193
return cmd
192194
}
193195

Diff for: cmd/werf/render/render.go

+2
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
165165
cmd.Flags().StringVarP(&cmdData.RenderOutput, "output", "", os.Getenv("WERF_RENDER_OUTPUT"), "Write render output to the specified file instead of stdout ($WERF_RENDER_OUTPUT by default)")
166166
cmd.Flags().StringArrayVarP(&cmdData.ShowOnly, "show-only", "s", []string{}, "only show manifests rendered from the given templates")
167167

168+
commonCmdData.SetupSkipImageSpecStage(cmd)
169+
168170
return cmd
169171
}
170172

Diff for: cmd/werf/run/run.go

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ func NewCmd(ctx context.Context) *cobra.Command {
160160
cmd.Flags().BoolVarP(&cmdData.Bash, "bash", "", false, "Use predefined docker options and command for debug")
161161
cmd.Flags().StringVarP(&cmdData.RawDockerOptions, "docker-options", "", os.Getenv("WERF_DOCKER_OPTIONS"), "Define docker run options (default $WERF_DOCKER_OPTIONS)")
162162

163+
commonCmdData.SetupSkipImageSpecStage(cmd)
164+
163165
return cmd
164166
}
165167

Diff for: docs/_data/werf_yaml.yml

+6-14
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ sections:
4545
ru: Глобальная конфигурация образов согласно OCI спецификации, которая применяется ко всем образам
4646
collapsible: true
4747
isCollapsedByDefault: false
48-
detailsCustomLinks:
49-
en:
50-
- text: Changing image configuration spec
51-
article: "/usage/build/images.md#changing-image-configuration-spec"
52-
ru:
53-
- text: Изменение конфигурации образов
54-
article: "/usage/build/images.md#изменение-конфигурации-образов"
48+
detailsArticle:
49+
en: "/usage/build/images.html#changing-image-configuration-spec"
50+
ru: "/usage/build/images.html#изменение-конфигурации-образов"
5551
directives:
5652
- name: author
5753
value: "string"
@@ -381,13 +377,9 @@ sections:
381377
description:
382378
en: Image configuration according to the OCI specification
383379
ru: Конфигурация образа согласно OCI спецификации
384-
detailsCustomLinks:
385-
en:
386-
- text: Changing image configuration spec
387-
article: "/usage/build/images.md#changing-image-configuration-spec"
388-
ru:
389-
- text: Изменение конфигурации образов
390-
article: "/usage/build/images.md#изменение-конфигурации-образов"
380+
detailsArticle:
381+
en: "/usage/build/images.html#changing-image-configuration-spec"
382+
ru: "/usage/build/images.html#изменение-конфигурации-образов"
391383
directives:
392384
- name: author
393385
value: "string"

Diff for: docs/_includes/reference/cli/werf_build.md

+2
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ werf build [IMAGE_NAME...] [options]
249249
cache.
250250
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
251251
$WERF_SECONDARY_REPO_2=...)
252+
--skip-image-spec-stage=false
253+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
252254
--skip-tls-verify-registry=false
253255
Skip TLS certificate validation when accessing a registry (default
254256
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_bundle_publish.md

+2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ werf bundle publish [IMAGE_NAME...] [options]
281281
$WERF_SET_STRING_2=key2=val2)
282282
-L, --skip-dependencies-repo-refresh=false
283283
Do not refresh helm chart repositories locally cached index
284+
--skip-image-spec-stage=false
285+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
284286
--skip-tls-verify-registry=false
285287
Skip TLS certificate validation when accessing a registry (default
286288
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_compose_config.md

+2
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ werf compose config [IMAGE_NAME...] [options] [--docker-compose-options="OPTIONS
242242
cache.
243243
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
244244
$WERF_SECONDARY_REPO_2=...)
245+
--skip-image-spec-stage=false
246+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
245247
--skip-tls-verify-registry=false
246248
Skip TLS certificate validation when accessing a registry (default
247249
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_compose_down.md

+2
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ werf compose down [IMAGE_NAME...] [options] [--docker-compose-options="OPTIONS"]
235235
cache.
236236
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
237237
$WERF_SECONDARY_REPO_2=...)
238+
--skip-image-spec-stage=false
239+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
238240
--skip-tls-verify-registry=false
239241
Skip TLS certificate validation when accessing a registry (default
240242
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_compose_run.md

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ werf compose run [IMAGE_NAME...] [options] [--docker-compose-options="OPTIONS"]
232232
cache.
233233
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
234234
$WERF_SECONDARY_REPO_2=...)
235+
--skip-image-spec-stage=false
236+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
235237
--skip-tls-verify-registry=false
236238
Skip TLS certificate validation when accessing a registry (default
237239
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_compose_up.md

+2
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ werf compose up [IMAGE_NAME...] [options] [--docker-compose-options="OPTIONS"] [
243243
cache.
244244
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
245245
$WERF_SECONDARY_REPO_2=...)
246+
--skip-image-spec-stage=false
247+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
246248
--skip-tls-verify-registry=false
247249
Skip TLS certificate validation when accessing a registry (default
248250
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_converge.md

+2
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ werf converge --repo registry.mydomain.com/web --env production
350350
$WERF_SET_STRING_2=key2=val2)
351351
-L, --skip-dependencies-repo-refresh=false
352352
Do not refresh helm chart repositories locally cached index
353+
--skip-image-spec-stage=false
354+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
353355
--skip-tls-verify-helm-dependencies=false
354356
Skip TLS certificate validation when accessing a Helm charts repository (default
355357
$WERF_SKIP_TLS_VERIFY_HELM_DEPENDENCIES)

Diff for: docs/_includes/reference/cli/werf_export.md

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ werf export [IMAGE_NAME...] [options]
213213
cache.
214214
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
215215
$WERF_SECONDARY_REPO_2=...)
216+
--skip-image-spec-stage=false
217+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
216218
--skip-tls-verify-registry=false
217219
Skip TLS certificate validation when accessing a registry (default
218220
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_helm_get_autogenerated_values.md

+2
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ werf helm get-autogenerated-values [IMAGE_NAME...] [options]
203203
$WERF_SECONDARY_REPO_2=...)
204204
--set-docker-config-json-value=false
205205
Shortcut to set current docker config into the .Values.dockerconfigjson
206+
--skip-image-spec-stage=false
207+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
206208
--skip-tls-verify-registry=false
207209
Skip TLS certificate validation when accessing a registry (default
208210
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_kube_run.md

+2
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ werf kube-run [options] [IMAGE_NAME] [-- COMMAND ARG...]
223223
cache.
224224
Also, can be specified with $WERF_SECONDARY_REPO_* (e.g. $WERF_SECONDARY_REPO_1=...,
225225
$WERF_SECONDARY_REPO_2=...)
226+
--skip-image-spec-stage=false
227+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
226228
--skip-tls-verify-registry=false
227229
Skip TLS certificate validation when accessing a registry (default
228230
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/_includes/reference/cli/werf_plan.md

+2
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@ werf plan --repo registry.mydomain.com/web --env production
329329
$WERF_SET_STRING_2=key2=val2)
330330
-L, --skip-dependencies-repo-refresh=false
331331
Do not refresh helm chart repositories locally cached index
332+
--skip-image-spec-stage=false
333+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
332334
--skip-tls-verify-helm-dependencies=false
333335
Skip TLS certificate validation when accessing a Helm charts repository (default
334336
$WERF_SKIP_TLS_VERIFY_HELM_DEPENDENCIES)

Diff for: docs/_includes/reference/cli/werf_render.md

+2
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ werf render [IMAGE_NAME...] [options]
285285
only show manifests rendered from the given templates
286286
-L, --skip-dependencies-repo-refresh=false
287287
Do not refresh helm chart repositories locally cached index
288+
--skip-image-spec-stage=false
289+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
288290
--skip-tls-verify-helm-dependencies=false
289291
Skip TLS certificate validation when accessing a Helm charts repository (default
290292
$WERF_SKIP_TLS_VERIFY_HELM_DEPENDENCIES)

Diff for: docs/_includes/reference/cli/werf_run.md

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ werf run [options] [IMAGE_NAME] [-- COMMAND ARG...]
184184
$WERF_SECONDARY_REPO_2=...)
185185
--shell=false
186186
Use predefined docker options and command for debug
187+
--skip-image-spec-stage=false
188+
Force skipping "imageSpec" build stage (default $WERF_SKIP_IMAGE_SPEC_STAGE or false)
187189
--skip-tls-verify-registry=false
188190
Skip TLS certificate validation when accessing a registry (default
189191
$WERF_SKIP_TLS_VERIFY_REGISTRY)

Diff for: docs/pages_en/usage/build/images.md

+48-1
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,8 @@ build:
412412

413413
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.
414414

415+
> **Note:** Global configuration applies only for `final` images. See more [here](#using-intermediate-and-final-images)
416+
415417
### Configuration for a specific image
416418

417419
Example configuration for an individual image:
@@ -427,7 +429,7 @@ imageSpec:
427429
clearHistory: true
428430
config:
429431
user: "1001:1001"
430-
exposedPorts:
432+
expose:
431433
- "8080/tcp"
432434
env:
433435
NODE_ENV: "production"
@@ -472,6 +474,51 @@ git:
472474

473475
In this example, the base image `postgres:12.22-bookworm` has unnecessary volumes removed, which can then be used in the `app` image.
474476

477+
### Working with CMD and ENTRYPOINT
478+
479+
If `CMD` is set in the image and `ENTRYPOINT` is specified in `imageSpec`, the `CMD` will be reset. Therefore, when modifying `ENTRYPOINT`, `CMD` must be explicitly defined if required.
480+
481+
For example, if the image has the following configuration:
482+
483+
```json
484+
"Entrypoint": null
485+
"Cmd": ["node", "server.js"],
486+
```
487+
488+
Then, to modify `ENTRYPOINT`, `CMD` must also be explicitly specified. The configuration should look like this:
489+
490+
```yaml
491+
project: test
492+
configVersion: 1
493+
---
494+
image: frontend_image
495+
from: alpine
496+
imageSpec:
497+
config:
498+
entrypoint:
499+
- "/app/entrypoint.sh"
500+
cmd:
501+
- "node"
502+
- "server.js"
503+
```
504+
505+
This behavior is consistent with Docker’s handling of `CMD` and `ENTRYPOINT`, as described in [the official documentation](https://docs.docker.com/reference/dockerfile/#understand-how-cmd-and-entrypoint-interact).
506+
507+
### Working with environment variables
508+
509+
When working with environment variables, you can reference existing ones from the image using `${ENV_NAME}`:
510+
511+
```yaml
512+
project: test
513+
configVersion: 1
514+
---
515+
image: backend
516+
from: alpine:3.21
517+
imageSpec:
518+
config:
519+
env:
520+
PATH: "${PATH}:/app/bin"
521+
```
475522

476523
## Linking images
477524

0 commit comments

Comments
 (0)