From 2bf45b3c567de24881c38b74df5c6cbbfba739ed Mon Sep 17 00:00:00 2001 From: Nikolay Gorbatov Date: Wed, 13 Aug 2025 14:15:12 +0400 Subject: [PATCH] add example with mountpoints define --- .werf/defines/image-mountpoints.tmpl | 23 +++++++++++ .werf/stages/images.yaml | 1 + .../mount-points.yaml | 2 + .../werf.inc.yaml | 8 ++++ templates/deployment-mountpoints-example.yaml | 38 +++++++++++++++++++ tools/mounts/README.md | 3 ++ tools/mounts/mountdir/.placeholder | 0 tools/mounts/mountfile | 0 8 files changed, 75 insertions(+) create mode 100644 .werf/defines/image-mountpoints.tmpl create mode 100644 images/image-with-mountpoints-example/mount-points.yaml create mode 100644 images/image-with-mountpoints-example/werf.inc.yaml create mode 100644 templates/deployment-mountpoints-example.yaml create mode 100644 tools/mounts/README.md create mode 100644 tools/mounts/mountdir/.placeholder create mode 100644 tools/mounts/mountfile diff --git a/.werf/defines/image-mountpoints.tmpl b/.werf/defines/image-mountpoints.tmpl new file mode 100644 index 0000000..8cb2f93 --- /dev/null +++ b/.werf/defines/image-mountpoints.tmpl @@ -0,0 +1,23 @@ +# add mount points from file mount_points.yaml in the build dir + +{{- define "image mount points" }} + {{- $mountPoints := ($.Files.Get (printf "images/%s/mount-points.yaml" $.ImageName) | fromYaml) }} + {{- range $v := $mountPoints.dirs }} +- add: /tools/mounts/mountdir + to: {{ $v }} + owner: 64535 + group: 64535 + stageDependencies: + install: + - "**/*" + {{- end }} + {{- range $v := $mountPoints.files }} +- add: /tools/mounts/mountfile + to: {{ $v }} + owner: 64535 + group: 64535 + stageDependencies: + install: + - "**/*" + {{- end }} +{{- end }} diff --git a/.werf/stages/images.yaml b/.werf/stages/images.yaml index 6b9ecc9..8483651 100644 --- a/.werf/stages/images.yaml +++ b/.werf/stages/images.yaml @@ -2,6 +2,7 @@ {{- range $path, $content := $ImagesBuildFiles }} {{ $ctx := (dict "ImageName" ($path | split "/")._1) }} + {{- $_ := set $ctx "Files" $.Files }} --- {{- /* For Dockerfile just render it from the folder. */ -}} {{- if not (regexMatch "/werf.inc.yaml$" $path) }} diff --git a/images/image-with-mountpoints-example/mount-points.yaml b/images/image-with-mountpoints-example/mount-points.yaml new file mode 100644 index 0000000..f00b2f4 --- /dev/null +++ b/images/image-with-mountpoints-example/mount-points.yaml @@ -0,0 +1,2 @@ +dirs: + - /mount-dir-example diff --git a/images/image-with-mountpoints-example/werf.inc.yaml b/images/image-with-mountpoints-example/werf.inc.yaml new file mode 100644 index 0000000..bfd38b6 --- /dev/null +++ b/images/image-with-mountpoints-example/werf.inc.yaml @@ -0,0 +1,8 @@ +{{ /* +--- +image: mpexample +from: ealen/echo-server:0.7.0 +git: +{{- include "image mount points" . }} + +/* }} diff --git a/templates/deployment-mountpoints-example.yaml b/templates/deployment-mountpoints-example.yaml new file mode 100644 index 0000000..b8801f5 --- /dev/null +++ b/templates/deployment-mountpoints-example.yaml @@ -0,0 +1,38 @@ +{{- /* +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mpexample + namespace: {{ .Chart.Name }} + {{- include "helm_lib_module_labels" (list . (dict "app" "echoserver")) | nindent 2 }} +spec: + revisionHistoryLimit: 2 + replicas: {{ .Values.echoserver.replicas }} + selector: + matchLabels: + app: mpexample + template: + metadata: + labels: + app: mpexample + spec: + priorityClassName: develop + containers: + - image: {{ include "helm_lib_module_image" (list . "mpexample") }} + imagePullPolicy: IfNotPresent + name: echoserver + ports: + - containerPort: 8080 + name: http + env: + - name: PORT + value: "8080" + volumeMounts: + - name: example + mountPath: /mount-dir-example + volumes: + - name: example + emptyDir: + sizeLimit: 50Mi +*/ -}} diff --git a/tools/mounts/README.md b/tools/mounts/README.md new file mode 100644 index 0000000..728514d --- /dev/null +++ b/tools/mounts/README.md @@ -0,0 +1,3 @@ +# Mount primitives + +This dir contains empty dir and empty file to use as mountpoints in the images. diff --git a/tools/mounts/mountdir/.placeholder b/tools/mounts/mountdir/.placeholder new file mode 100644 index 0000000..e69de29 diff --git a/tools/mounts/mountfile b/tools/mounts/mountfile new file mode 100644 index 0000000..e69de29