Skip to content

Commit

Permalink
add cross-compilation support
Browse files Browse the repository at this point in the history
  • Loading branch information
szlend committed Oct 27, 2024
1 parent cc96df7 commit 70e0f1a
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 60 deletions.
8 changes: 5 additions & 3 deletions cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

var fromImageFilename string

var imageArch string
var created timeValue

type timeValue time.Time
Expand All @@ -39,7 +40,7 @@ var imageCmd = &cobra.Command{
Short: "Generate an image.json file from a image configuration and layers",
Args: cobra.MinimumNArgs(3),
Run: func(cmd *cobra.Command, args []string) {
err := image(args[0], args[1], fromImageFilename, args[2:], (time.Time)(created))
err := image(args[0], args[1], fromImageFilename, args[2:], imageArch, (time.Time)(created))
if err != nil {
fmt.Fprintf(os.Stderr, "%s", err)
os.Exit(1)
Expand Down Expand Up @@ -107,7 +108,7 @@ func imageFromManifest(outputFilename, manifestFilename string, blobsFilename st
return nil
}

func image(outputFilename, imageConfigPath string, fromImageFilename string, layerPaths []string, created time.Time) error {
func image(outputFilename, imageConfigPath string, fromImageFilename string, layerPaths []string, arch string, created time.Time) error {
var imageConfig v1.ImageConfig
var image types.Image

Expand All @@ -133,7 +134,7 @@ func image(outputFilename, imageConfigPath string, fromImageFilename string, lay
logrus.Infof("Using base image %s containing %d layers", fromImageFilename, len(fromImage.Layers))
}

image.Arch = runtime.GOARCH
image.Arch = arch

image.ImageConfig = imageConfig

Expand Down Expand Up @@ -167,6 +168,7 @@ func image(outputFilename, imageConfigPath string, fromImageFilename string, lay
func init() {
rootCmd.AddCommand(imageCmd)
imageCmd.Flags().StringVarP(&fromImageFilename, "from-image", "", "", "A JSON file describing the base image")
imageCmd.Flags().StringVarP(&imageArch, "arch", "", runtime.GOARCH, "Target CPU architecture of the image")
imageCmd.Flags().Var(&created, "created", "Timestamp at which the image was created")
rootCmd.AddCommand(imageFromDirCmd)
rootCmd.AddCommand(imageFromManifestCmd)
Expand Down
Loading

0 comments on commit 70e0f1a

Please sign in to comment.