Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set GOOS=windows when building go_install package with AQUA_GOOS=windows #2868

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkg/cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/aquaproj/aqua/v2/pkg/config"
"github.com/aquaproj/aqua/v2/pkg/controller"
"github.com/aquaproj/aqua/v2/pkg/runtime"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -53,7 +54,7 @@ func (r *Runner) execAction(c *cli.Context) error {
if err := r.setParam(c, "exec", param); err != nil {
return fmt.Errorf("parse the command line arguments: %w", err)
}
ctrl := controller.InitializeExecCommandController(c.Context, param, http.DefaultClient, r.Runtime)
ctrl := controller.InitializeExecCommandController(c.Context, param, http.DefaultClient, runtime.NewR())
exeName, args, err := parseExecArgs(c.Args().Slice())
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func getArch(rosetta2, windowsARMEmulation bool, replacements registry.Replaceme
// Rosetta 2
return replace("amd64", replacements)
}
if windowsARMEmulation && rt.GOOS == "windows" && rt.GOARCH == "arm64" {
if windowsARMEmulation && rt.IsWindows() && rt.GOARCH == "arm64" {
// Windows ARM Emulation
return replace("amd64", replacements)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/cp/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func (c *Controller) copy(logE *logrus.Entry, param *config.Param, findResult *which.FindResult, exeName string) error {
p := filepath.Join(param.Dest, exeName)
if c.runtime.GOOS == "windows" && filepath.Ext(exeName) == "" {
if c.runtime.IsWindows() && filepath.Ext(exeName) == "" {
p += ".exe"
}
logE.WithFields(logrus.Fields{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c *Controller) mkBinBatDir() error {
if err := osfile.MkdirAll(c.fs, rootBin); err != nil {
return fmt.Errorf("create the directory: %w", err)
}
if c.runtime.GOOS == "windows" {
if c.runtime.IsWindows() {
if err := osfile.MkdirAll(c.fs, filepath.Join(c.rootDir, "bat")); err != nil {
return fmt.Errorf("create the directory: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cosign/exe_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ParamExePath struct {

func ExePath(param *ParamExePath) string {
assetName := fmt.Sprintf("cosign-%s-%s", param.Runtime.GOOS, param.Runtime.GOARCH)
if param.Runtime.GOOS == "windows" {
if param.Runtime.IsWindows() {
assetName += ".exe"
}
return filepath.Join(param.RootDir, "pkgs", "github_release", "github.com", "sigstore", "cosign", Version, assetName, assetName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cosign/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewVerifier(executor Executor, fs afero.Fs, downloader download.ClientAPI,
Runtime: rt,
}),
// assets for windows/arm64 aren't released.
disabled: rt.GOOS == "windows" && rt.GOARCH == "arm64",
disabled: rt.IsWindows() && rt.GOARCH == "arm64",
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/installpackage/aqua.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (is *Installer) InstallAqua(ctx context.Context, logE *logrus.Entry, versio
Format: "tar.gz",
Overrides: []*registry.Override{
{
GOOS: "windows",
GOOS: osWindows,
Format: "zip",
},
},
Expand Down Expand Up @@ -132,7 +132,7 @@ func (is *Installer) InstallAqua(ctx context.Context, logE *logrus.Entry, versio
return fmt.Errorf("get the executable file path: %w", err)
}

if is.runtime.GOOS == "windows" {
if is.runtime.IsWindows() {
return is.Copy(filepath.Join(is.rootDir, "bin", "aqua.exe"), exePath)
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/installpackage/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package installpackage

const (
osWindows = "windows"
)
2 changes: 1 addition & 1 deletion pkg/installpackage/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (is *Installer) download(ctx context.Context, logE *logrus.Entry, param *Do
pkgInfo := param.Package.PackageInfo

if pkgInfo.Type == "go_install" {
return is.downloadGoInstall(ctx, ppkg, param.Dest, logE)
return is.downloadGoInstall(ctx, logE, ppkg, param.Dest, is.runtime.GOOS)
}

if pkgInfo.Type == "cargo" {
Expand Down
15 changes: 9 additions & 6 deletions pkg/installpackage/go_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

type GoInstallInstaller interface {
Install(ctx context.Context, path, gobin string) error
Install(ctx context.Context, path, gobin, goos string) error
}

type GoInstallInstallerImpl struct {
Expand All @@ -22,15 +22,18 @@ func NewGoInstallInstallerImpl(exec Executor) *GoInstallInstallerImpl {
}
}

func (is *GoInstallInstallerImpl) Install(ctx context.Context, path, gobin string) error {
_, err := is.exec.ExecWithEnvs(ctx, "go", []string{"install", path}, []string{"GOBIN=" + gobin})
if err != nil {
func (is *GoInstallInstallerImpl) Install(ctx context.Context, path, gobin, goos string) error {
envs := []string{"GOBIN=" + gobin}
if goos == "windows" {
envs = append(envs, "GOOS=windows")
}
if _, err := is.exec.ExecWithEnvs(ctx, "go", []string{"install", path}, envs); err != nil {
return fmt.Errorf("install a go package: %w", err)
}
return nil
}

func (is *Installer) downloadGoInstall(ctx context.Context, pkg *config.Package, dest string, logE *logrus.Entry) error {
func (is *Installer) downloadGoInstall(ctx context.Context, logE *logrus.Entry, pkg *config.Package, dest, goos string) error {
p, err := pkg.RenderPath()
if err != nil {
return fmt.Errorf("render Go Module Path: %w", err)
Expand All @@ -40,7 +43,7 @@ func (is *Installer) downloadGoInstall(ctx context.Context, pkg *config.Package,
"gobin": dest,
"go_package_path": goPkgPath,
}).Info("Installing a Go tool")
if err := is.goInstallInstaller.Install(ctx, goPkgPath, dest); err != nil {
if err := is.goInstallInstaller.Install(ctx, goPkgPath, dest, goos); err != nil {
return fmt.Errorf("build Go tool: %w", err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/installpackage/mock_go_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ type MockGoInstallInstaller struct {
Err error
}

func (m *MockGoInstallInstaller) Install(ctx context.Context, path, gobin string) error {
func (m *MockGoInstallInstaller) Install(ctx context.Context, path, gobin, goos string) error {
return m.Err
}
4 changes: 4 additions & 0 deletions pkg/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (rt *Runtime) Env() string {
return fmt.Sprintf("%s/%s", rt.GOOS, rt.GOARCH)
}

func (rt *Runtime) IsWindows() bool {
return rt.GOOS == "windows"
}

func goos() string {
if s := os.Getenv("AQUA_GOOS"); s != "" {
return s
Expand Down
2 changes: 1 addition & 1 deletion pkg/slsa/exe_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ParamExePath struct {

func ExePath(param *ParamExePath) string {
assetName := fmt.Sprintf("slsa-verifier-%s-%s", param.Runtime.GOOS, param.Runtime.GOARCH)
if param.Runtime.GOOS == "windows" {
if param.Runtime.IsWindows() {
assetName += ".exe"
}
return filepath.Join(param.RootDir, "pkgs", "github_release", "github.com", "slsa-framework", "slsa-verifier", Version, assetName, assetName)
Expand Down