build

package
v2.34.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildCmd = &cobra.Command{
	Use:   "build",
	Short: "Builds the agent and controller binaries",
	Long:  "Builds the agent and controller binaries",
	PersistentPreRunE: func(_ *cobra.Command, _ []string) error {

		userHomeDir, err := os.UserHomeDir()
		if err != nil {
			return err
		}
		builderCacheRoot = filepath.Join(userHomeDir, utils.AperturectlRootDir, utils.BuilderCacheRoot)
		err = os.MkdirAll(builderCacheRoot, os.ModePerm)
		if err != nil {
			return err
		}

		if apertureURI != "" && apertureVersion != "" {
			return errors.New("either the URI or version should be set, not both")
		}

		if apertureURI == "" {
			if apertureVersion == "" {
				apertureVersion = latestTag
			}
			apertureURI = fmt.Sprintf("%s@%s", defaultApertureRepo, apertureVersion)
		} else {

			if _, err = os.Stat(apertureURI); err == nil {

				apertureURI, err = filepath.Abs(apertureURI)
				if err != nil {
					return err
				}
			} else {
				// try to parse as url
				var apertureURL *url.URL
				apertureURL, err = url.Parse(apertureURI)
				if err != nil {
					return err
				}
				apertureURI = apertureURL.String()
			}
		}

		dirName := strings.ReplaceAll(apertureURI, "/", "_")
		builderURIRoot = filepath.Join(builderCacheRoot, dirName)
		err = os.MkdirAll(builderURIRoot, os.ModePerm)
		if err != nil {
			return err
		}

		lock = flock.New(filepath.Join(builderURIRoot, "lock"))
		locked, err := lock.TryLockContext(context.Background(), time.Millisecond*100)
		if err != nil {
			return err
		}
		if !locked {
			return errors.New("could not get lock on: " + builderURIRoot)
		}

		if !skipPull {
			err = utils.PullSource(builderURIRoot, apertureURI)
			if err != nil {
				return err
			}
		} else {
			log.Debug().Msg("skipping pulling aperture repository")
		}

		builderDir = filepath.Join(builderURIRoot, utils.GetRelPath(builderURIRoot))

		builderDir, err = filepath.EvalSymlinks(builderDir)
		if err != nil {
			return err
		}
		return nil
	},
	PersistentPostRunE: func(_ *cobra.Command, _ []string) error {
		if lock == nil {
			return nil
		}

		return lock.Unlock()
	},
}

BuildCmd is the root command for the build command.

Functions

This section is empty.

Types

type BuildConfig

type BuildConfig struct {
	Version       string   `json:"version" default:"unknown"`
	GitCommitHash string   `json:"git_commit_hash"`
	GitBranch     string   `json:"git_branch"`
	LdFlags       []string `json:"ldflags"`
	Flags         []string `json:"flags"`
}

BuildConfig picked up from environment variables.

type Config

type Config struct {
	Build                BuildConfig       `json:"build"`
	BundledExtensions    []string          `json:"bundled_extensions"`
	Extensions           []ExtensionConfig `json:"extensions"`
	Replaces             []ReplaceConfig   `json:"replaces"`
	EnableCoreExtensions bool              `json:"enable_core_extensions" default:"true"`
}

Config is the configuration for building the binary.

type ExtensionConfig

type ExtensionConfig struct {
	// GoModName. e.g. github.com/fluxninja/aperture-extensions/extension/test
	GoModName string `json:"go_mod_name" validate:"required"`
	// Version e.g. v0.0.1
	Version string `json:"version" validate:"required"`
	// PkgName name of the extension. e.g. test
	PkgName string `json:"pkg_name"`
}

ExtensionConfig is the configuration for an extension.

type ReplaceConfig

type ReplaceConfig struct {
	Old string `json:"old" validate:"required"`
	New string `json:"new" validate:"required"`
}

ReplaceConfig is the configuration for a replace directive.

Jump to

Keyboard shortcuts

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