-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from Itxaka/osbuilder_go
- Loading branch information
Showing
26 changed files
with
3,547 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
name: 'run enki unit tests' | ||
|
||
on: | ||
pull_request: | ||
|
||
concurrency: | ||
group: enki-${{ github.ref || github.head_ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
FORCE_COLOR: 1 | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: earthly/[email protected] | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Build | ||
run: cd tools-image/enki && earthly -P +test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
VERSION 0.7 | ||
|
||
# renovate: datasource=docker depName=golang | ||
ARG --global GO_VERSION=1.20-alpine3.18 | ||
|
||
test: | ||
FROM golang:$GO_VERSION | ||
RUN apk add rsync gcc musl-dev docker jq | ||
WORKDIR /build | ||
COPY . . | ||
RUN go mod download | ||
ARG TEST_PATHS=./... | ||
ARG LABEL_FILTER= | ||
ENV CGO_ENABLED=1 | ||
# Some test require the docker sock exposed | ||
WITH DOCKER | ||
RUN go run github.com/onsi/ginkgo/v2/ginkgo run --label-filter "$LABEL_FILTER" -v --fail-fast --race --covermode=atomic --coverprofile=coverage.out --coverpkg=github.com/kairos-io/enki/... -p -r $TEST_PATHS | ||
END | ||
SAVE ARTIFACT coverage.out AS LOCAL coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/kairos-io/enki/pkg/action" | ||
"github.com/kairos-io/enki/pkg/config" | ||
"github.com/kairos-io/enki/pkg/utils" | ||
v1 "github.com/kairos-io/kairos-agent/v2/pkg/types/v1" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
"k8s.io/mount-utils" | ||
) | ||
|
||
// NewBuildISOCmd returns a new instance of the build-iso subcommand and appends it to | ||
// the root command. | ||
func NewBuildISOCmd() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "build-iso SOURCE", | ||
Short: "Build bootable installation media ISOs", | ||
Long: "Build bootable installation media ISOs\n\n" + | ||
"SOURCE - should be provided as uri in following format <sourceType>:<sourceName>\n" + | ||
" * <sourceType> - might be [\"dir\", \"file\", \"oci\", \"docker\"], as default is \"docker\"\n" + | ||
" * <sourceName> - is path to file or directory, image name with tag version", | ||
Args: cobra.MaximumNArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return CheckRoot() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
path, err := exec.LookPath("mount") | ||
if err != nil { | ||
return err | ||
} | ||
mounter := mount.New(path) | ||
|
||
cfg, err := config.ReadConfigBuild(viper.GetString("config-dir"), cmd.Flags(), mounter) | ||
if err != nil { | ||
cfg.Logger.Errorf("Error reading config: %s\n", err) | ||
} | ||
|
||
flags := cmd.Flags() | ||
|
||
// Set this after parsing of the flags, so it fails on parsing and prints usage properly | ||
cmd.SilenceUsage = true | ||
cmd.SilenceErrors = true // Do not propagate errors down the line, we control them | ||
spec, err := config.ReadBuildISO(cfg, flags) | ||
if err != nil { | ||
cfg.Logger.Errorf("invalid install command setup %v", err) | ||
return err | ||
} | ||
|
||
if len(args) == 1 { | ||
imgSource, err := v1.NewSrcFromURI(args[0]) | ||
if err != nil { | ||
cfg.Logger.Errorf("not a valid rootfs source image argument: %s", args[0]) | ||
return err | ||
} | ||
spec.RootFS = []*v1.ImageSource{imgSource} | ||
} else if len(spec.RootFS) == 0 { | ||
errmsg := "rootfs source image for building ISO was not provided" | ||
cfg.Logger.Errorf(errmsg) | ||
return fmt.Errorf(errmsg) | ||
} | ||
|
||
// Repos and overlays can't be unmarshaled directly as they require | ||
// to be merged on top and flags do not match any config value key | ||
oRootfs, _ := flags.GetString("overlay-rootfs") | ||
oUEFI, _ := flags.GetString("overlay-uefi") | ||
oISO, _ := flags.GetString("overlay-iso") | ||
|
||
if oRootfs != "" { | ||
if ok, err := utils.Exists(cfg.Fs, oRootfs); ok { | ||
spec.RootFS = append(spec.RootFS, v1.NewDirSrc(oRootfs)) | ||
} else { | ||
cfg.Logger.Errorf("Invalid value for overlay-rootfs") | ||
return fmt.Errorf("Invalid path '%s': %v", oRootfs, err) | ||
} | ||
} | ||
if oUEFI != "" { | ||
if ok, err := utils.Exists(cfg.Fs, oUEFI); ok { | ||
spec.UEFI = append(spec.UEFI, v1.NewDirSrc(oUEFI)) | ||
} else { | ||
cfg.Logger.Errorf("Invalid value for overlay-uefi") | ||
return fmt.Errorf("Invalid path '%s': %v", oUEFI, err) | ||
} | ||
} | ||
if oISO != "" { | ||
if ok, err := utils.Exists(cfg.Fs, oISO); ok { | ||
spec.Image = append(spec.Image, v1.NewDirSrc(oISO)) | ||
} else { | ||
cfg.Logger.Errorf("Invalid value for overlay-iso") | ||
return fmt.Errorf("Invalid path '%s': %v", oISO, err) | ||
} | ||
} | ||
|
||
buildISO := action.NewBuildISOAction(cfg, spec) | ||
err = buildISO.ISORun() | ||
if err != nil { | ||
cfg.Logger.Errorf(err.Error()) | ||
return err | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
c.Flags().StringP("name", "n", "", "Basename of the generated ISO file") | ||
c.Flags().StringP("output", "o", "", "Output directory (defaults to current directory)") | ||
c.Flags().Bool("date", false, "Adds a date suffix into the generated ISO file") | ||
c.Flags().String("overlay-rootfs", "", "Path of the overlayed rootfs data") | ||
c.Flags().String("overlay-uefi", "", "Path of the overlayed uefi data") | ||
c.Flags().String("overlay-iso", "", "Path of the overlayed iso data") | ||
c.Flags().String("label", "", "Label of the ISO volume") | ||
archType := newEnumFlag([]string{"x86_64", "arm64"}, "x86_64") | ||
c.Flags().Bool("squash-no-compression", true, "Disable squashfs compression.") | ||
c.Flags().VarP(archType, "arch", "a", "Arch to build the image for") | ||
return c | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(NewBuildISOCmd()) | ||
} |
Oops, something went wrong.