Skip to content

Commit

Permalink
Rework dockerfile to have example, rework inputs
Browse files Browse the repository at this point in the history
Now we can pass the requried info in the cli call directly

Signed-off-by: Itxaka <[email protected]>
  • Loading branch information
Itxaka committed Jan 16, 2025
1 parent 918ca91 commit 78df679
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ jobs:
file: Dockerfile
platforms: linux/amd64, linux/arm64
push: true
target: kairos-init
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 15 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
ARG BASE_IMAGE=ubuntu:24.04

FROM golang AS build
WORKDIR /app
COPY go.mod go.sum .
Expand All @@ -7,5 +9,16 @@ ENV CGO_ENABLED=0
RUN go build -o /app/kairos-init .


FROM scratch AS default
COPY --from=build /app/kairos-init /kairos-init
FROM scratch AS kairos-init
COPY --from=build /app/kairos-init /kairos-init

FROM ${BASE_IMAGE}
ARG MODEL=generic
ARG VARIANT=core
ARG FRAMEWORK_VERSION=""
ARG TRUSTED_BOOT=false

COPY --from=kairos-init /kairos-init /kairos-init
RUN /kairos-init -l debug -s install -m "${MODEL}" -v "${VARIANT}" -f "${FRAMEWORK_VERSION}" -t "${TRUSTED_BOOT}"
RUN /kairos-init -l debug -s init -m "${MODEL}" -v "${VARIANT}" -f "${FRAMEWORK_VERSION}" -t "${TRUSTED_BOOT}"
RUN rm /kairos-init
43 changes: 32 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/mudler/yip/pkg/schema"
"os"
"strings"

"github.com/kairos-io/kairos-init/pkg/config"
"github.com/kairos-io/kairos-init/pkg/stages"
Expand All @@ -14,16 +15,36 @@ import (
)

func main() {
flag.StringVar(&config.DefaultConfig.Level, "level", "info", "set the log level (shorthand: -l)")
flag.StringVar(&config.DefaultConfig.Level, "l", "info", "set the log level (shorthand: -l)")
flag.StringVar(&config.DefaultConfig.Stage, "stage", "", "set the stage to run (shorthand: -s)")
flag.StringVar(&config.DefaultConfig.Stage, "s", "", "set the stage to run (shorthand: -s)")
flag.StringVar(&config.DefaultConfig.Model, "model", "generic", "model to build for, like generic or rpi4 (shorthand: -m)")
flag.StringVar(&config.DefaultConfig.Model, "m", "generic", "model to build for, like generic or rpi4 (shorthand: -m)")
flag.BoolVar(&config.DefaultConfig.TrustedBoot, "trustedboot", false, "init the system for Trusted Boot, changes bootloader to systemd (shorthand: -t)")
flag.BoolVar(&config.DefaultConfig.TrustedBoot, "t", false, "init the system for Trusted Boot, changes bootloader to systemd (shorthand: -t)")
var trusted string
flag.StringVar(&config.DefaultConfig.Level, "l", "info", "set the log level")
flag.StringVar(&config.DefaultConfig.Stage, "s", "all", "set the stage to run")
flag.StringVar(&config.DefaultConfig.Model, "m", "generic", "model to build for, like generic or rpi4")
flag.StringVar(&config.DefaultConfig.Variant, "v", "core", "variant to build (core or standard for k3s flavor) (shorthand: -v)")
flag.StringVar(&trusted, "t", "false", "init the system for Trusted Boot, changes bootloader to systemd")
flag.StringVar(&config.DefaultConfig.FrameworkVersion, "f", values.GetFrameworkVersion(), "set the framework version to use")
showHelp := flag.Bool("help", false, "show help")

if strings.ToLower(trusted) == "true" {
config.DefaultConfig.TrustedBoot = true
}

// Custom usage function
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.VisitAll(func(f *flag.Flag) {
if f.Name != "cpuprofile" && f.Name != "memprofile" && f.Name != "stubs" && f.Name != "help" && f.Name != "pkg" && f.Name != "log" && f.Name != "e" && f.Name != "out" {
fmt.Fprintf(os.Stderr, " -%s: %s (default: %s)\n", f.Name, f.Usage, f.DefValue)
}
})
}

flag.Parse()

if *showHelp {
flag.Usage()
os.Exit(0)
}

logger := types.NewKairosLogger("kairos-init", config.DefaultConfig.Level, false)
logger.Infof("Starting kairos-init version %s", values.GetVersion())
logger.Debug(litter.Sdump(values.GetFullVersion()))
Expand All @@ -39,12 +60,12 @@ func main() {
runStages, err = stages.RunInstallStage(logger)
case "init":
runStages, err = stages.RunInitStage(logger)
case "all":
runStages, err = stages.RunAllStages(logger)
default:
logger.Errorf("Unknown stage %s", config.DefaultConfig.Stage)
logger.Errorf("Unknown stage %s. Valid values are install, init and all", config.DefaultConfig.Stage)
os.Exit(1)
}
} else {
runStages, err = stages.RunAllStages(logger)
}

if err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package config
// Config is the struct to track the config of the init image
// So we can access it from anywhere
type Config struct {
Level string
Stage string
Model string
TrustedBoot bool
Level string
Stage string
Model string
FrameworkVersion string
Variant string
TrustedBoot bool
}

var DefaultConfig = Config{}
9 changes: 8 additions & 1 deletion pkg/stages/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ func GetCleanupStage(_ values.System, _ types.KairosLogger) []schema.Stage {
}

func GetInstallFrameworkStage(_ values.System, _ types.KairosLogger) []schema.Stage {
var frameworkVersion string
// If the framework version is set in the config use that, otherwise use the version from the values which usually its the latest
if config.DefaultConfig.FrameworkVersion != "" {
frameworkVersion = config.DefaultConfig.FrameworkVersion
} else {
frameworkVersion = values.GetFrameworkVersion()
}
return []schema.Stage{
{
Name: "Create kairos directory",
Expand All @@ -182,7 +189,7 @@ func GetInstallFrameworkStage(_ values.System, _ types.KairosLogger) []schema.St
Name: "Install framework",
UnpackImages: []schema.UnpackImageConf{
{
Source: fmt.Sprintf("quay.io/kairos/framework:%s", values.GetFrameworkVersion()),
Source: fmt.Sprintf("quay.io/kairos/framework:%s", frameworkVersion),
Target: "/",
},
},
Expand Down

0 comments on commit 78df679

Please sign in to comment.