Skip to content
Open
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
5 changes: 5 additions & 0 deletions pkg/app/piped/toolregistry/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"os/exec"
"runtime"
"text/template"

"go.uber.org/zap"
Expand Down Expand Up @@ -58,6 +59,7 @@ func (r *registry) installKubectl(ctx context.Context, version string) error {
"Version": version,
"BinDir": r.binDir,
"AsDefault": asDefault,
"Arch": runtime.GOARCH,
}
)
if err := kubectlInstallScriptTmpl.Execute(&buf, data); err != nil {
Expand Down Expand Up @@ -105,6 +107,7 @@ func (r *registry) installKustomize(ctx context.Context, version string) error {
"Version": version,
"BinDir": r.binDir,
"AsDefault": asDefault,
"Arch": runtime.GOARCH,
}
)
if err := kustomizeInstallScriptTmpl.Execute(&buf, data); err != nil {
Expand Down Expand Up @@ -152,6 +155,7 @@ func (r *registry) installHelm(ctx context.Context, version string) error {
"Version": version,
"BinDir": r.binDir,
"AsDefault": asDefault,
"Arch": runtime.GOARCH,
}
)
if err := helmInstallScriptTmpl.Execute(&buf, data); err != nil {
Expand Down Expand Up @@ -199,6 +203,7 @@ func (r *registry) installTerraform(ctx context.Context, version string) error {
"Version": version,
"BinDir": r.binDir,
"AsDefault": asDefault,
"Arch": runtime.GOARCH,
}
)
if err := terraformInstallScriptTmpl.Execute(&buf, data); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/app/piped/toolregistry/tool_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package toolregistry

var kubectlInstallScript = `
cd {{ .WorkingDir }}
curl -LO https://dl.k8s.io/release/v{{ .Version }}/bin/darwin/amd64/kubectl
curl -LO https://dl.k8s.io/release/v{{ .Version }}/bin/darwin/{{ .Arch }}/kubectl
mv kubectl {{ .BinDir }}/kubectl-{{ .Version }}
chmod +x {{ .BinDir }}/kubectl-{{ .Version }}
{{ if .AsDefault }}
Expand All @@ -26,7 +26,7 @@ cp -f {{ .BinDir }}/kubectl-{{ .Version }} {{ .BinDir }}/kubectl

var kustomizeInstallScript = `
cd {{ .WorkingDir }}
curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v{{ .Version }}/kustomize_v{{ .Version }}_darwin_amd64.tar.gz | tar xvz
curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v{{ .Version }}/kustomize_v{{ .Version }}_darwin_{{ .Arch }}.tar.gz | tar xvz
mv kustomize {{ .BinDir }}/kustomize-{{ .Version }}
chmod +x {{ .BinDir }}/kustomize-{{ .Version }}
{{ if .AsDefault }}
Expand All @@ -36,8 +36,8 @@ cp -f {{ .BinDir }}/kustomize-{{ .Version }} {{ .BinDir }}/kustomize

var helmInstallScript = `
cd {{ .WorkingDir }}
curl -L https://get.helm.sh/helm-v{{ .Version }}-darwin-amd64.tar.gz | tar xvz
mv darwin-amd64/helm {{ .BinDir }}/helm-{{ .Version }}
curl -L https://get.helm.sh/helm-v{{ .Version }}-darwin-{{ .Arch }}.tar.gz | tar xvz
mv darwin-{{ .Arch }}/helm {{ .BinDir }}/helm-{{ .Version }}
chmod +x {{ .BinDir }}/helm-{{ .Version }}
{{ if .AsDefault }}
cp -f {{ .BinDir }}/helm-{{ .Version }} {{ .BinDir }}/helm
Expand All @@ -46,8 +46,8 @@ cp -f {{ .BinDir }}/helm-{{ .Version }} {{ .BinDir }}/helm

var terraformInstallScript = `
cd {{ .WorkingDir }}
curl https://releases.hashicorp.com/terraform/{{ .Version }}/terraform_{{ .Version }}_darwin_amd64.zip -o terraform_{{ .Version }}_linux_amd64.zip
unzip terraform_{{ .Version }}_linux_amd64.zip
curl https://releases.hashicorp.com/terraform/{{ .Version }}/terraform_{{ .Version }}_darwin_{{ .Arch }}.zip -o terraform_{{ .Version }}_darwin_{{ .Arch }}.zip
unzip terraform_{{ .Version }}_darwin_{{ .Arch }}.zip
mv terraform {{ .BinDir }}/terraform-{{ .Version }}
{{ if .AsDefault }}
cp -f {{ .BinDir }}/terraform-{{ .Version }} {{ .BinDir }}/terraform
Expand Down
54 changes: 54 additions & 0 deletions pkg/app/piped/toolregistry/tool_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package toolregistry

import (
"bytes"
"testing"

"github.com/stretchr/testify/assert"
)

func TestDarwinInstallScriptsUseHostArch(t *testing.T) {
data := map[string]interface{}{
"WorkingDir": "/tmp/work",
"Version": "1.2.3",
"BinDir": "/tmp/bin",
"AsDefault": false,
"Arch": "arm64",
}

var buf bytes.Buffer

buf.Reset()
assert.NoError(t, kubectlInstallScriptTmpl.Execute(&buf, data))
assert.Contains(t, buf.String(), "bin/darwin/arm64/kubectl")
assert.NotContains(t, buf.String(), "bin/darwin/amd64/kubectl")

buf.Reset()
assert.NoError(t, kustomizeInstallScriptTmpl.Execute(&buf, data))
assert.Contains(t, buf.String(), "kustomize_v1.2.3_darwin_arm64.tar.gz")
assert.NotContains(t, buf.String(), "kustomize_v1.2.3_darwin_amd64.tar.gz")

buf.Reset()
assert.NoError(t, helmInstallScriptTmpl.Execute(&buf, data))
assert.Contains(t, buf.String(), "helm-v1.2.3-darwin-arm64.tar.gz")
assert.NotContains(t, buf.String(), "helm-v1.2.3-darwin-amd64.tar.gz")

buf.Reset()
assert.NoError(t, terraformInstallScriptTmpl.Execute(&buf, data))
assert.Contains(t, buf.String(), "terraform_1.2.3_darwin_arm64.zip")
assert.NotContains(t, buf.String(), "terraform_1.2.3_darwin_amd64.zip")
}
Loading