From b7a7fdc4b8a715157bfa2614c9541b96643cd2ba Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Thu, 26 Dec 2024 19:41:53 +0400 Subject: [PATCH] refactor: generate /etc/os-release file static way The file which is exported back to source via `make generate` is using short tag (vX.Y.Z), while the one generated for the actual build comes with full version tag. Fixes #8898 Signed-off-by: Andrey Smirnov --- Dockerfile | 84 ++++++++++--------- Makefile | 4 +- .../app/machined/pkg/startup/os_release.go | 60 ------------- internal/app/machined/pkg/startup/startup.go | 1 - pkg/machinery/version/gen.go | 25 ++++++ pkg/machinery/version/os-release | 8 ++ pkg/machinery/version/osrelease.go | 2 + 7 files changed, 83 insertions(+), 101 deletions(-) delete mode 100644 internal/app/machined/pkg/startup/os_release.go create mode 100644 pkg/machinery/version/gen.go create mode 100644 pkg/machinery/version/os-release diff --git a/Dockerfile b/Dockerfile index 999d34018b..2e377a47ce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,8 @@ ARG PKG_TALOSCTL_CNI_BUNDLE_INSTALL=scratch ARG DEBUG_TOOLS_SOURCE=scratch +ARG EMBED_TARGET=embed + # Resolve package images using ${PKGS} to be used later in COPY --from=. FROM ${PKG_FHS} AS pkg-fhs @@ -285,6 +287,43 @@ RUN --mount=type=cache,target=/.cache go mod verify # The generate target generates code from protobuf service definitions and machinery config. +FROM build AS embed-generate +ARG NAME +ARG SHA +ARG USERNAME +ARG REGISTRY +ARG TAG +ARG ARTIFACTS +ARG PKGS +ARG EXTRAS +RUN mkdir -p pkg/machinery/gendata/data && \ + echo -n ${NAME} > pkg/machinery/gendata/data/name && \ + echo -n ${SHA} > pkg/machinery/gendata/data/sha && \ + echo -n ${USERNAME} > pkg/machinery/gendata/data/username && \ + echo -n ${REGISTRY} > pkg/machinery/gendata/data/registry && \ + echo -n ${EXTRAS} > pkg/machinery/gendata/data/extras && \ + echo -n ${PKGS} > pkg/machinery/gendata/data/pkgs && \ + echo -n ${TAG} > pkg/machinery/gendata/data/tag && \ + echo -n ${ARTIFACTS} > pkg/machinery/gendata/data/artifacts + +FROM scratch AS embed +COPY --from=embed-generate /src/pkg/machinery/gendata/data /pkg/machinery/gendata/data + +FROM embed-generate AS embed-abbrev-generate +ARG ABBREV_TAG +RUN echo -n "undefined" > pkg/machinery/gendata/data/sha && \ + echo -n ${ABBREV_TAG} > pkg/machinery/gendata/data/tag +RUN mkdir -p _out && \ + echo PKGS=${PKGS} >> _out/talos-metadata && \ + echo TAG=${TAG} >> _out/talos-metadata && \ + echo EXTRAS=${EXTRAS} >> _out/talos-metadata + +FROM scratch AS embed-abbrev +COPY --from=embed-abbrev-generate /src/pkg/machinery/gendata/data /pkg/machinery/gendata/data +COPY --from=embed-abbrev-generate /src/_out/talos-metadata /_out/talos-metadata + +FROM ${EMBED_TARGET} AS embed-target + # generate API descriptors FROM build AS api-descriptors-build WORKDIR /src/api @@ -308,6 +347,7 @@ COPY --from=proto-format-build /src/api/ /api/ FROM build-go AS go-generate COPY ./pkg ./pkg COPY ./hack/boilerplate.txt ./hack/boilerplate.txt +COPY --from=embed-target / ./ RUN --mount=type=cache,target=/.cache go generate ./pkg/... RUN goimports -w -local github.com/siderolabs/talos ./pkg/ RUN gofumpt -w ./pkg/ @@ -350,43 +390,6 @@ RUN find /api/resource/definitions/ -type f -name "*.proto" | xargs -I {} /bin/s RUN goimports -w -local github.com/siderolabs/talos /api/ RUN gofumpt -w /api/ -FROM build AS embed-generate -ARG NAME -ARG SHA -ARG USERNAME -ARG REGISTRY -ARG TAG -ARG ARTIFACTS -ARG PKGS -ARG EXTRAS -RUN mkdir -p pkg/machinery/gendata/data && \ - echo -n ${NAME} > pkg/machinery/gendata/data/name && \ - echo -n ${SHA} > pkg/machinery/gendata/data/sha && \ - echo -n ${USERNAME} > pkg/machinery/gendata/data/username && \ - echo -n ${REGISTRY} > pkg/machinery/gendata/data/registry && \ - echo -n ${EXTRAS} > pkg/machinery/gendata/data/extras && \ - echo -n ${PKGS} > pkg/machinery/gendata/data/pkgs && \ - echo -n ${TAG} > pkg/machinery/gendata/data/tag && \ - echo -n ${ARTIFACTS} > pkg/machinery/gendata/data/artifacts - -FROM scratch AS embed -COPY --from=embed-generate /src/pkg/machinery/gendata/data /pkg/machinery/gendata/data - -FROM embed-generate AS embed-abbrev-generate -ARG ABBREV_TAG -RUN echo -n "undefined" > pkg/machinery/gendata/data/sha && \ - echo -n ${ABBREV_TAG} > pkg/machinery/gendata/data/tag -RUN mkdir -p _out && \ - echo PKGS=${PKGS} >> _out/talos-metadata && \ - echo TAG=${TAG} >> _out/talos-metadata && \ - echo EXTRAS=${EXTRAS} >> _out/talos-metadata -COPY --from=pkg-kernel /certs/signing_key.x509 _out/signing_key.x509 - -FROM scratch AS embed-abbrev -COPY --from=embed-abbrev-generate /src/pkg/machinery/gendata/data /pkg/machinery/gendata/data -COPY --from=embed-abbrev-generate /src/_out/talos-metadata /_out/talos-metadata -COPY --from=embed-abbrev-generate /src/_out/signing_key.x509 /_out/signing_key.x509 - FROM tools AS selinux COPY ./internal/pkg/selinux/policy/* /selinux/ RUN mkdir /policy; secilc -o /policy/policy.33 -f /policy/file_contexts -c 33 /selinux/**/*.cil -vvvvv -O @@ -430,6 +433,7 @@ COPY --from=go-generate /src/pkg/machinery/config/schemas/ /pkg/machinery/config COPY --from=go-generate /src/pkg/machinery/config/types/ /pkg/machinery/config/types/ COPY --from=go-generate /src/pkg/machinery/nethelpers/ /pkg/machinery/nethelpers/ COPY --from=go-generate /src/pkg/machinery/extensions/ /pkg/machinery/extensions/ +COPY --from=go-generate /src/pkg/machinery/version/os-release /pkg/machinery/version/os-release COPY --from=ipxe-generate / /pkg/provision/providers/vm/internal/ipxe/data/ipxe/ COPY --from=selinux-generate / /internal/pkg/selinux/ COPY --from=embed-abbrev / / @@ -743,9 +747,10 @@ COPY --chmod=0644 hack/cri-plugin.part /rootfs/etc/cri/conf.d/00-base.part COPY --chmod=0644 hack/udevd/99-default.link /rootfs/usr/lib/systemd/network/ COPY --chmod=0644 hack/udevd/90-selinux.rules /rootfs/usr/lib/udev/rules.d/ COPY --chmod=0644 hack/lvm.conf /rootfs/etc/lvm/lvm.conf +COPY --chmod=0644 --from=base /src/pkg/machinery/version/os-release /rootfs/etc/os-release RUN <