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 <dimitris@karakasilis.me>
This commit is contained in:
Dimitris Karakasilis 2023-09-22 17:16:23 +03:00
parent 791b780cd2
commit 2f0d06b835
2 changed files with 12 additions and 6 deletions

View File

@ -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?
},

View File

@ -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