Skip to content

Commit 31b1dcb

Browse files
refactor(ci): workflows and base image, add build swtpm (#922)
This PR modernizes our build system by: Updating GitHub workflow configurations Restructuring base image management via werf templates Implementing connect to 3p repos Updating critical dependencies Build swtpm package Rename directory cv to component_versions --------- Signed-off-by: Nikita Korolev <nikita.korolev@flant.com>
1 parent c30d15a commit 31b1dcb

33 files changed

Lines changed: 333 additions & 124 deletions

File tree

.github/workflows/dev_module_build.yml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ env:
2424
GO_VERSION: "1.22.7"
2525
GOLANGCI_LINT_VERSION: "1.64.8"
2626
SOURCE_REPO: "${{secrets.SOURCE_REPO}}"
27+
SOURCE_REPO_GIT: "${{secrets.SOURCE_REPO_GIT}}"
2728

2829
on:
2930
workflow_dispatch:
@@ -35,7 +36,7 @@ on:
3536
required: false
3637
type: number
3738
pull_request:
38-
types: [opened, reopened, synchronize, labeled]
39+
types: [opened, reopened, synchronize, labeled, unlabeled]
3940
push:
4041
branches:
4142
- main
@@ -325,6 +326,30 @@ jobs:
325326
if: ${{ !contains(needs.set_vars.outputs.runner_type, 'self-hosted') }}
326327
uses: ./.github/actions/remove-unwanted-software
327328

329+
- name: Start ssh-agent
330+
uses: webfactory/ssh-agent@v0.9.0
331+
with:
332+
ssh-private-key: |
333+
${{secrets.SOURCE_REPO_SSH_KEY}}
334+
335+
- name: Add ssh_known_hosts
336+
run: |
337+
HOST=$(grep -oP '(?<=@)[^/:]+' <<< ${{secrets.SOURCE_REPO_GIT}})
338+
echo "::add-mask::$HOST"
339+
IPS=$(nslookup "$HOST" | awk '/^Address: / { print $2 }')
340+
for IP in $IPS; do
341+
echo "::add-mask::$IP"
342+
done
343+
mkdir -p ~/.ssh
344+
touch ~/.ssh/known_hosts
345+
HOST_KEYS=$(ssh-keyscan -H "$HOST" 2>/dev/null)
346+
while IFS= read -r KEY_LINE; do
347+
CONSTANT_PART=$(awk '{print $2, $3}' <<< "$KEY_LINE")
348+
if ! grep -q "$CONSTANT_PART" ~/.ssh/known_hosts; then
349+
echo "$KEY_LINE" >> ~/.ssh/known_hosts
350+
fi
351+
done <<< "$HOST_KEYS"
352+
328353
- uses: deckhouse/modules-actions/setup@v2
329354
with:
330355
registry: ${{ vars.DEV_REGISTRY }}

.helmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ openapi
1010
release.yaml
1111
werf*.yaml
1212
NOTES.txt
13+
.git

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
**/.hg
44
**/werf*.yaml
55
**/werf*.yml
6+
.werf/**
67
**/templates
78
**/ISSUE_TEMPLATE
89
CHANGELOG/*.yml
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{{- define "parse_base_images_map" }}
2+
{{- $virtualizationImages := .Files.Get "base-images/virtualization_images.yml" | fromYaml }}
3+
{{- $deckhouseImages := .Files.Get "base-images/deckhouse_images.yml" | fromYaml }}
4+
5+
# virtualizationImages have image format:
6+
# BASE_IMAGE: "<image_name>@sha256abcde12345
7+
{{- range $k, $v := $virtualizationImages }}
8+
{{ $baseImagePath := (printf "%s%s" $virtualizationImages.REGISTRY_PATH (trimSuffix "/" $v)) }}
9+
{{- if ne $k "REGISTRY_PATH" }}
10+
{{- $_ := set $virtualizationImages $k $baseImagePath }}
11+
{{- end }}
12+
{{- end }}
13+
{{- $_ := unset $virtualizationImages "REGISTRY_PATH" }}
14+
15+
# deckhouse_images has a format
16+
# <prefix>/<name>: "sha256:abcde12345
17+
{{- range $k, $v := $deckhouseImages }}
18+
{{ $baseImagePath := (printf "%s@%s" $deckhouseImages.REGISTRY_PATH (trimSuffix "/" $v)) }}
19+
{{- if ne $k "REGISTRY_PATH" }}
20+
{{- $_ := set $deckhouseImages $k $baseImagePath }}
21+
{{- end }}
22+
{{- end }}
23+
{{- $_ := unset $deckhouseImages "REGISTRY_PATH" }}
24+
25+
{{- $_ := set . "Images" (mustMerge $virtualizationImages $deckhouseImages) }}
26+
# base images artifacts
27+
{{- range $k, $v := .Images }}
28+
---
29+
image: {{ $k }}
30+
from: {{ $v }}
31+
final: false
32+
{{- end }}
33+
{{- end }}

.werf/images.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Common dirs
2+
{{- define "module_image_template" }}
3+
4+
{{- if eq .ImageInstructionType "Dockerfile" }}
5+
---
6+
image: images/{{ .ImageName }}
7+
context: images/{{ .ImageName }}
8+
dockerfile: Dockerfile
9+
{{- else }}
10+
{{- tpl .ImageBuildData . | nindent 0 }}
11+
{{- end }}
12+
13+
{{- end }}
14+
15+
# Context inside folder images
16+
{{- $Root := . }}
17+
18+
{{ $ImagesBuildFiles := .Files.Glob "images/*/{Dockerfile,werf.inc.yaml}" }}
19+
20+
{{- range $path, $content := $ImagesBuildFiles }}
21+
{{- $ctx := dict }}
22+
23+
{{- if regexMatch "/werf.inc.yaml$" $path }}
24+
{{- $_ := set $ctx "ImageInstructionType" "Stapel" }}
25+
{{- else }}
26+
{{- $_ := set $ctx "ImageInstructionType" "Dockerfile" }}
27+
{{- end }}
28+
29+
{{- $ImageData := $path | split "/" }}
30+
31+
{{- $_ := set $ctx "ImageName" $ImageData._1 }}
32+
{{- $_ := set $ctx "ImageBuildData" $content }}
33+
{{- $_ := set $ctx "SOURCE_REPO" $Root.SOURCE_REPO }}
34+
{{- $_ := set $ctx "SOURCE_REPO_GIT" $Root.SOURCE_REPO_GIT }}
35+
{{- $_ := set $ctx "MODULE_EDITION" $Root.MODULE_EDITION }}
36+
{{- $_ := set $ctx "Version" $Root.Version }}
37+
38+
{{- include "module_image_template" $ctx }}
39+
40+
{{- range $ImageYamlMainfest := regexSplit "\n?---[ \t]*\n" (include "module_image_template" $ctx) -1 }}
41+
{{- $ImageManifest := $ImageYamlMainfest | fromYaml }}
42+
43+
{{- if $ImageManifest | dig "final" true }}
44+
45+
{{- if $ImageManifest.image }}
46+
{{- $_ := set $ "ImagesIDList" (append $.ImagesIDList $ImageManifest.image) }}
47+
{{- end }}
48+
49+
{{- end }}
50+
51+
{{- end }}
52+
53+
{{- end }}

.werf/packages.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{{- define "packages_template" }}
2+
3+
{{- if eq .ImageInstructionType "Dockerfile" }}
4+
---
5+
image: images/{{ .ImageName }}
6+
context: images/{{ .ImageName }}
7+
dockerfile: Dockerfile
8+
{{- else }}
9+
{{- tpl .ImageBuildData . | nindent 0 }}
10+
{{- end }}
11+
12+
{{- end }}
13+
14+
{{- $Root := . }}
15+
16+
17+
{{ $ImagePackages := .Files.Glob "images/packages/*/*/{Dockerfile,werf.inc.yaml}" }}
18+
{{- range $path, $content := $ImagePackages }}
19+
{{- $ctx := dict }}
20+
21+
{{- if regexMatch "/werf.inc.yaml$" $path }}
22+
{{- $_ := set $ctx "ImageInstructionType" "Stapel" }}
23+
{{- else }}
24+
{{- $_ := set $ctx "ImageInstructionType" "Dockerfile" }}
25+
{{- end }}
26+
27+
# Parse variables for images from their path.
28+
# for example: `packages/binaries/swtpm/werf.inc.yaml` turns into
29+
# ImageType: packages/binaries
30+
# ImageName: swtpm
31+
32+
{{- $ImageData := regexReplaceAll "^images/(packages)/([0-9a-z-_]+)/([0-9a-z-_]+)/(Dockerfile|werf.inc.yaml)$" $path "${1}#${2}#${3}#${4}" | split "#" }}
33+
34+
{{- $_ := set $ctx "ImageType" (printf "%s/%s" $ImageData._0 $ImageData._1) }}
35+
{{- $_ := set $ctx "ImageName" $ImageData._2 }}
36+
{{- $_ := set $ctx "ImageBuildData" $content }}
37+
{{- $_ := set $ctx "Files" $Root.Files }}
38+
{{- $_ := set $ctx "SOURCE_REPO" $Root.SOURCE_REPO }}
39+
{{- $_ := set $ctx "SOURCE_REPO_GIT" $Root.SOURCE_REPO_GIT }}
40+
{{- $_ := set $ctx "MODULE_EDITION" $Root.MODULE_EDITION }}
41+
{{- $_ := set $ctx "Version" $Root.Version }}
42+
{{- $_ := set $ctx "Package" $Root.Packages }}
43+
44+
{{- include "packages_template" $ctx }}
45+
46+
{{- range $ImageYamlMainfest := regexSplit "\n?---[ \t]*\n" (include "packages_template" $ctx) -1 }}
47+
{{- $ImageManifest := $ImageYamlMainfest | fromYaml }}
48+
49+
{{- if $ImageManifest | dig "final" true }}
50+
51+
{{- if $ImageManifest.image }}
52+
{{- $_ := set $ "ImagesIDList" (append $.ImagesIDList $ImageManifest.image) }}
53+
{{- end }}
54+
55+
{{- end }}
56+
57+
{{- end }}
58+
59+
{{- end }}

base-images/alt_image_versions.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

base-images/deckhouse_image_versions.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

base-images/deckhouse_images.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# version v0.4.1
2+
# REGISTRY_PATH is a special key which is concatenated with other base images
3+
REGISTRY_PATH: registry.deckhouse.io/base_images
4+
base/distroless: "sha256:f2ac3320ce677484d7aef4608f99ddf0055d8907cc3509f8cccc8513f314c31a" # fromImage: builder/scratch
5+
base/nginx-static: "sha256:28a844d4ff777dc704d3808bdd1240108315f4d1ed1668e762627b9c4ddc8d66" # fromImage: base/distroless
6+
base/python: "sha256:432f19eaeb5035ea38e3fbc721576e6802c679fd0fb7a8e6d441fdb36944c180" # fromImage: base/distroless
7+
builder/alpine: "sha256:92adb9e8a387c645ba4eeedb08f9a6de0583c5d1d496bf9c9b3a89fe963a6a06" # from: alpine:3.20.6
8+
builder/alt: "sha256:6fe06774a942e293e28b85cf3307e0f6e79a1593352c9c5ca97a6cbefdce0a55" # from: registry.altlinux.org/p11/alt:20241211
9+
builder/golang-alpine: "sha256:482aab8cb49614acb14ce9397861b02d05cc222d893d689abd205c9bd2c17b46" # from: golang:1.24.2-alpine3.20
10+
builder/golang-bookworm: "sha256:3755a67e7d3f16995b1615694a2aae7a95618a1ff9603b23f347764dfa0242b2" # from: golang:1.24.2-bookworm
11+
builder/golang-bullseye: "sha256:7f2838a3779bb9759accba1cbea7ea7aa086cc67ec763718004febb47948570c" # from: golang:1.24.2-bullseye
12+
builder/node-alpine: "sha256:f09f957ee8e960c7afee93d7a30f20116e76660c0408d35109ee9a9fa2a4d5b0" # from: node:23.10.0-alpine3.20
13+
builder/scratch: "sha256:10b5855ae3e20ecc2ba6eb3d7f8365ee2facc98a62c9e4840927ad4074bd2317" # from: registry.werf.io/werf/scratch
14+
tools/bash: "sha256:892cd63bafb70b529377833c374009db5e9759c0aa72b165aff4ba52b59a45c6" # fromImage: builder/scratch
15+
tools/cosign: "sha256:d62c8deb048d9d02e5ea3b9f1efa9a940625c746f3c568a283c346c844a8acf8" # fromImage: builder/scratch
16+
tools/grep: "sha256:48e485161d6cec13d5283d03e69e2d1ff9e1c6146d040dc3bf623d856b62a636" # fromImage: builder/scratch
17+
tools/jq: "sha256:71aac8b711bef4dbef462d6309e283812358b9920301ad3de23a5734a18a23f2" # fromImage: builder/scratch
18+
tools/less: "sha256:259d88c1a732e7d3fc8d067ea0324684e1fe73a3bbb3eb7e2a9d88212a4ee2a0" # fromImage: builder/scratch
19+
tools/vim: "sha256:66db26b1475c389df02b8a8f9b98ff6993b2a2b51085f88a0cf618b915086de6" # fromImage: builder/scratch
20+
tools/yq4: "sha256:35911ea155806ec3b29c5d6eec90184d3d836bb42037f9865fb5949ab7a4cd6c" # fromImage: builder/scratch

0 commit comments

Comments
 (0)