From 2f0d06b835730fe08612ec98e1a842687d323af9 Mon Sep 17 00:00:00 2001 From: Dimitris Karakasilis Date: Fri, 22 Sep 2023 17:16:23 +0300 Subject: [PATCH] Don't assume /bin/sh is there in the base image In other words, don't run `RUN` commands that might not be there. Ideally all `RUN` commands should run on the builder stage and at the final step, we just copy everything over. Signed-off-by: Dimitris Karakasilis --- tools-image/enki/cmd/convert.go | 4 ++-- tools-image/enki/pkg/action/converter.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/tools-image/enki/cmd/convert.go b/tools-image/enki/cmd/convert.go index fb40d52..5ad5861 100644 --- a/tools-image/enki/cmd/convert.go +++ b/tools-image/enki/cmd/convert.go @@ -10,12 +10,12 @@ import ( // the root command. func NewConvertCmd() *cobra.Command { c := &cobra.Command{ - Use: "convert rootfs", + Use: "convert /path/to/rootfs /path/to/result image_name", Short: "Convert a base image to a Kairos image", Long: "Convert a base image to a Kairos image\n\n" + "This is best effort. Enki will try to detect the distribution and add\n" + "the necessary bits to convert it to a Kairos image", - Args: cobra.ExactArgs(2), + Args: cobra.ExactArgs(3), PreRunE: func(cmd *cobra.Command, args []string) error { return CheckRoot() // TODO: Do we need root? }, diff --git a/tools-image/enki/pkg/action/converter.go b/tools-image/enki/pkg/action/converter.go index 4ef9503..d162bc5 100644 --- a/tools-image/enki/pkg/action/converter.go +++ b/tools-image/enki/pkg/action/converter.go @@ -84,14 +84,19 @@ func (ca *ConverterAction) createDockerfile() (string, error) { // write data to the temporary file data := []byte(` +FROM busybox as builder +RUN mkdir /rootfs +COPY . /rootfs/. + +RUN echo "nameserver 8.8.8.8" > /rootfs/etc/resolv.conf +RUN cat /rootfs/etc/resolv.conf + FROM scratch as rootfs -COPY . . + +COPY --from=builder /rootfs/ . FROM rootfs -RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf -RUN cat /etc/resolv.conf - # TODO: Do more clever things RUN apt-get update && apt-get install -y curl `) @@ -136,6 +141,7 @@ func (ca *ConverterAction) removeDockerIgnore() error { func (ca *ConverterAction) BuildWithKaniko(dockerfile, resultPath string) (string, error) { d, err := ca.Runner.Run( "executor", + //"--verbosity", "debug", "--dockerfile", dockerfile, "--context", ca.rootFSPath, "--destination", ca.imageName, // This is the name of the image when you: cat image.tar | docker load