Skip to content

Commit

Permalink
Don't assume /bin/sh is there in the base image
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jimmykarily committed Sep 29, 2023
1 parent 791b780 commit 2f0d06b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tools-image/enki/cmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
},
Expand Down
14 changes: 10 additions & 4 deletions tools-image/enki/pkg/action/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ 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 . .
FROM rootfs
COPY --from=builder /rootfs/ .
RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf
RUN cat /etc/resolv.conf
FROM rootfs
# TODO: Do more clever things
RUN apt-get update && apt-get install -y curl
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2f0d06b

Please sign in to comment.