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: download conftest binary for correct arch #4089

Merged
merged 2 commits into from
Dec 27, 2023
Merged
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
27 changes: 23 additions & 4 deletions server/core/runtime/policy/conftest_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/events/models"
"github.com/runatlantis/atlantis/server/logging"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)

const (
DefaultConftestVersionEnvKey = "DEFAULT_CONFTEST_VERSION"
conftestBinaryName = "conftest"
conftestDownloadURLPrefix = "https://github.com/open-policy-agent/conftest/releases/download/v"
conftestArch = "x86_64"
)

type Arg struct {
Expand Down Expand Up @@ -113,8 +110,13 @@ type ConfTestVersionDownloader struct {
func (c ConfTestVersionDownloader) downloadConfTestVersion(v *version.Version, destPath string) (runtime_models.FilePath, error) {
versionURLPrefix := fmt.Sprintf("%s%s", conftestDownloadURLPrefix, v.Original())

conftestPlatform := getPlatform()
if conftestPlatform == "" {
return runtime_models.LocalFilePath(""), fmt.Errorf("don't know where to find conftest for %s on %s", runtime.GOOS, runtime.GOARCH)
}

// download binary in addition to checksum file
binURL := fmt.Sprintf("%s/conftest_%s_%s_%s.tar.gz", versionURLPrefix, v.Original(), cases.Title(language.English).String(runtime.GOOS), conftestArch)
binURL := fmt.Sprintf("%s/conftest_%s_%s.tar.gz", versionURLPrefix, v.Original(), conftestPlatform)
checksumURL := fmt.Sprintf("%s/checksums.txt", versionURLPrefix)

// underlying implementation uses go-getter so the URL is formatted as such.
Expand Down Expand Up @@ -313,3 +315,20 @@ func hasFailures(output string) bool {
}
return false
}

func getPlatform() string {
platform := runtime.GOOS + "_" + runtime.GOARCH

switch platform {
case "linux_amd64":
return "Linux_x86_64"
case "linux_arm64":
return "Linux_arm64"
case "darwin_amd64":
return "Darwin_x86_64"
case "darwin_arm64":
return "Darwin_arm64"
default:
return ""
}
}
8 changes: 2 additions & 6 deletions server/core/runtime/policy/conftest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"path/filepath"
"runtime"
"testing"

"github.com/hashicorp/go-version"
Expand All @@ -17,17 +16,14 @@ import (
"github.com/runatlantis/atlantis/server/events/command"
"github.com/runatlantis/atlantis/server/logging"
. "github.com/runatlantis/atlantis/testing"

"golang.org/x/text/cases"
"golang.org/x/text/language"
)

func TestConfTestVersionDownloader(t *testing.T) {

version, _ := version.NewVersion("0.25.0")
destPath := "some/path"

fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s_x86_64.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", cases.Title(language.English).String(runtime.GOOS))
platform := getPlatform()
fullURL := fmt.Sprintf("https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/conftest_0.25.0_%s.tar.gz?checksum=file:https://github.com/open-policy-agent/conftest/releases/download/v0.25.0/checksums.txt", platform)

RegisterMockTestingT(t)

Expand Down