cli

package
v0.31.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildCommand = &cli.Command{
	Name:                  "build",
	Aliases:               []string{"b"},
	Usage:                 "build an image with BuildKit",
	ArgsUsage:             "DIRECTORY",
	EnableShellCompletion: true,
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "name",
			Usage: "name of the image to build",
		},
		&cli.StringFlag{
			Name:  "output",
			Usage: "output the final filesystem to a local directory",
		},
		&cli.StringFlag{
			Name:  "platform",
			Usage: "platform to build for (e.g. linux/amd64, linux/arm64)",
		},
		&cli.StringFlag{
			Name:  "progress",
			Usage: "buildkit progress output mode. Values: auto, plain, tty",
			Value: "auto",
		},
		&cli.BoolFlag{
			Name:  "show-plan",
			Usage: "Show the build plan before building. This is useful for development and debugging.",
			Value: false,
		},
		&cli.StringFlag{
			Name:  "cache-key",
			Usage: "Unique id to prefix to cache keys",
		},
		&cli.StringSliceFlag{
			Name:  "cache-from",
			Usage: "External cache sources",
		},
		&cli.StringSliceFlag{
			Name:  "cache-to",
			Usage: "Cache export destinations",
		},
		&cli.BoolFlag{
			Name:   "dump-llb",
			Hidden: true,
			Value:  false,
		},
	}, commonPlanFlags()...),
	Action: func(ctx context.Context, cmd *cli.Command) error {
		buildResult, app, env, err := GenerateBuildResultForCommand(cmd)
		if err != nil {
			return cli.Exit(err, 1)
		}

		if !cmd.Bool("dump-llb") {
			core.PrettyPrintBuildResult(buildResult, core.PrintOptions{Version: Version})
		}

		if !buildResult.Success {
			os.Exit(1)
			return nil
		}

		if cmd.Bool("show-plan") && !cmd.Bool("dump-llb") {
			planMap, err := addSchemaToPlanMap(buildResult.Plan)
			if err != nil {
				return cli.Exit(err, 1)
			}

			serializedPlan, err := json.MarshalIndent(planMap, "", "  ")
			if err != nil {
				return cli.Exit(err, 1)
			}
			fmt.Println(string(serializedPlan))
		}

		err = validateSecrets(buildResult.Plan, env)
		if err != nil {
			return cli.Exit(err, 1)
		}

		secretsHash := getSecretsHash(env)

		platformStr := cmd.String("platform")
		err = buildkit.BuildWithBuildkitClient(app.Source, buildResult.Plan, buildkit.BuildWithBuildkitClientOptions{
			ImageName:    cmd.String("name"),
			DumpLLB:      cmd.Bool("dump-llb"),
			OutputDir:    cmd.String("output"),
			ProgressMode: cmd.String("progress"),
			CacheKey:     cmd.String("cache-key"),

			ImportCache: cmd.StringSlice("cache-from"),
			ExportCache: cmd.StringSlice("cache-to"),
			SecretsHash: secretsHash,
			Secrets:     env.Variables,
			Platform:    platformStr,
			GitHubToken: os.Getenv("GITHUB_TOKEN"),
		})
		if err != nil {
			return cli.Exit(err, 1)
		}

		return nil
	},
}
View Source
var FrontendCommand = &cli.Command{
	Name:  "frontend",
	Usage: "Start the BuildKit GRPC frontend server",
	Action: func(ctx context.Context, cmd *cli.Command) error {
		buildkit.StartFrontend()

		return nil
	},
}
View Source
var InfoCommand = &cli.Command{
	Name:                  "info",
	Aliases:               []string{"i"},
	Usage:                 "get as much information as possible about an app",
	ArgsUsage:             "DIRECTORY",
	EnableShellCompletion: true,
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "format",
			Usage: "output format. one of: pretty, json",
			Value: "pretty",
		},
		&cli.StringFlag{
			Name:  "out",
			Usage: "output file name",
		},
	}, commonPlanFlags()...),
	Action: func(ctx context.Context, cmd *cli.Command) error {
		buildResult, _, _, err := GenerateBuildResultForCommand(cmd)
		if err != nil {
			return cli.Exit(err, 1)
		}

		format := cmd.String("format")

		var buildResultString string
		if format == "pretty" {
			buildResultString = core.FormatBuildResult(buildResult, core.PrintOptions{
				Metadata: true,
				Version:  Version,
			})
		} else {
			serializedResult, err := json.MarshalIndent(buildResult, "", "  ")
			if err != nil {
				return cli.Exit(err, 1)
			}
			buildResultString = string(serializedResult)
		}

		output := cmd.String("out")
		if output == "" {

			_, _ = os.Stdout.Write([]byte(buildResultString))
			_, _ = os.Stdout.Write([]byte("\n"))
			return nil
		} else {
			if err := os.MkdirAll(filepath.Dir(output), 0755); err != nil {
				return cli.Exit(err, 1)
			}

			err = os.WriteFile(output, []byte(buildResultString), 0644)
			if err != nil {
				return cli.Exit(err, 1)
			}

			log.Infof("Plan written to %s", output)
		}

		if !buildResult.Success {
			os.Exit(1)
			return nil
		}

		return nil
	},
}
View Source
var PlanCommand = &cli.Command{
	Name:                  "plan",
	Aliases:               []string{"p"},
	Usage:                 "generate a build plan for a directory",
	ArgsUsage:             "DIRECTORY",
	EnableShellCompletion: true,
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:    "out",
			Aliases: []string{"o"},
			Usage:   "output file name",
		},
	}, commonPlanFlags()...),
	Action: func(ctx context.Context, cmd *cli.Command) error {
		buildResult, _, _, err := GenerateBuildResultForCommand(cmd)
		if err != nil {
			return cli.Exit(err, 1)
		}

		planMap, err := addSchemaToPlanMap(buildResult.Plan)
		if err != nil {
			return cli.Exit(err, 1)
		}
		serializedPlan, err := json.MarshalIndent(planMap, "", "  ")
		if err != nil {
			return cli.Exit(err, 1)
		}
		buildResultString := serializedPlan

		output := cmd.String("out")
		if output == "" {

			_, _ = os.Stdout.Write([]byte(buildResultString))
			_, _ = os.Stdout.Write([]byte("\n"))
			return nil
		} else {
			if err := os.MkdirAll(filepath.Dir(output), 0755); err != nil {
				return cli.Exit(err, 1)
			}

			err = os.WriteFile(output, []byte(buildResultString), 0644)
			if err != nil {
				return cli.Exit(err, 1)
			}

			log.Infof("Plan written to %s", output)
		}

		return nil
	},
}
View Source
var PrepareCommand = &cli.Command{
	Name:                  "prepare",
	Aliases:               []string{"p"},
	Usage:                 "prepares all the files necessary for a platform to build an app with the BuildKit frontend",
	ArgsUsage:             "DIRECTORY",
	EnableShellCompletion: true,
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "plan-out",
			Usage: "output file for the JSON serialized build plan",
		},
		&cli.StringFlag{
			Name:  "info-out",
			Usage: "output file for the JSON serialized build result info",
		},
		&cli.BoolFlag{
			Name:  "show-plan",
			Usage: "dump the build plan to stdout",
		},
		&cli.BoolFlag{
			Name:  "hide-pretty-plan",
			Usage: "hide the pretty-printed build result output",
		},
	}, commonPlanFlags()...),
	Action: func(ctx context.Context, cmd *cli.Command) error {
		buildResult, _, _, err := GenerateBuildResultForCommand(cmd)
		if err != nil {
			return cli.Exit(err, 1)
		}

		if !cmd.Bool("hide-pretty-plan") {
			core.PrettyPrintBuildResult(buildResult, core.PrintOptions{Version: Version})
		}

		if !buildResult.Success {
			os.Exit(1)
			return nil
		}

		if cmd.Bool("show-plan") {
			planMap, err := addSchemaToPlanMap(buildResult.Plan)
			if err != nil {
				return cli.Exit(err, 1)
			}
			serialized, err := json.MarshalIndent(planMap, "", "  ")
			if err != nil {
				return cli.Exit(err, 1)
			}
			_, _ = os.Stdout.Write(serialized)
		}

		if planOut := cmd.String("plan-out"); planOut != "" {

			planMap, err := addSchemaToPlanMap(buildResult.Plan)
			if err != nil {
				return cli.Exit(err, 1)
			}
			if err := writeJSONFile(planOut, planMap, "Build plan written to %s"); err != nil {
				return cli.Exit(err, 1)
			}
		}

		if infoOut := cmd.String("info-out"); infoOut != "" {
			buildResult.Plan = nil
			if err := writeJSONFile(infoOut, buildResult, "Build result info written to %s"); err != nil {
				return cli.Exit(err, 1)
			}
		}

		return nil
	},
}
View Source
var SchemaCommand = &cli.Command{
	Name:                  "schema",
	Usage:                 "outputs the JSON schema for the Railpack config",
	EnableShellCompletion: true,
	Flags:                 []cli.Flag{},
	Action: func(ctx context.Context, cmd *cli.Command) error {
		schema := config.GetJsonSchema()

		schemaJson, err := json.MarshalIndent(schema, "", "  ")
		if err != nil {
			return cli.Exit(err, 1)
		}

		_, _ = os.Stdout.Write(schemaJson)
		_, _ = os.Stdout.Write([]byte("\n"))

		return nil
	},
}
View Source
var Version string // This will be set by main

Functions

func GenerateBuildResultForCommand

func GenerateBuildResultForCommand(cmd *cli.Command) (*core.BuildResult, *a.App, *a.Environment, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL