Skip to content

Commit

Permalink
make the default arch the system arch (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDen authored May 13, 2024
1 parent d91854b commit 6074d36
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cmd/anchor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/signal"
"path/filepath"
"runtime"
"strings"
"syscall"

Expand All @@ -29,7 +30,7 @@ func init() {
rootCmd.PersistentFlags().
StringP("output", "o", "Dockerfile", "Name of the output dockerfile. If using multiple architectures, the architecture will be appended to the output file name")
rootCmd.PersistentFlags().
StringP("architectures", "a", "arm64", "Comma delimited list of architectures to anchor")
StringP("architectures", "a", "", "Comma delimited list of architectures to anchor: \"amd64\" and \"arm64\" are supported. If the flag is not used, the system architecture will be used")
rootCmd.PersistentFlags().
BoolP("dry-run", "", false, "Write the output to stdout instead of a file")
rootCmd.PersistentFlags().
Expand Down Expand Up @@ -69,6 +70,12 @@ var rootCmd = &cobra.Command{
if err != nil {
return err
}
if architectures == "" {
architectures, err = getArchitecture()
if err != nil {
return err
}
}
input, err := cmd.Flags().GetString("input")
if err != nil {
return err
Expand Down Expand Up @@ -171,3 +178,14 @@ func Execute() {
os.Exit(1)
}
}

func getArchitecture() (string, error) {
switch runtime.GOARCH {
case "amd64":
return "amd64", nil
case "arm64":
return "arm64", nil
default:
return "unknown", fmt.Errorf("unsupported architecture: %s", runtime.GOARCH)
}
}

0 comments on commit 6074d36

Please sign in to comment.