Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
fix(hack): fix porto update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Jan 31, 2024
1 parent 3242eec commit eb89b1f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sha256 e64a55d5f44d4b3bc1111b20efb0b020154cfb7e7ae28213968db18c846596dd porto_focal_v5.3.30-alpha.9_amd64.tgz
sha256 6fc245b4c2911354609b53b7ab1962586561389ded653de82e45170d7aee1ef6 porto_focal_v5.3.31_amd64.tgz
sha256 c15282342770b12a97b4991bd9b4c4e2f72d3f145aa7737618ba059316037a59 porto_focal_v5.3.31_amd64.tgz
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sha256 f7e2ed9f5048b820a58e2332ae70bed46018b59919dc009cd28c18d4d7d69719 portoshim_focal_v1.0.9-alpha.2_amd64.tgz
sha256 6174c696abb18304431d1c21cd731d3caff7c97fb96e083178c22d0edf714817 portoshim_focal_v1.0.9-alpha.4_amd64.tgz
sha256 bfa1e5db825fe4b73f7a4aec9b30a8a825435fa85de0124e77054684a1a6d421 portoshim_focal_v1.0.11-alpha.5_amd64.tgz
sha256 cade4fc8e3ca5946fb3ccdd59aa06c98920b9b18dc0265fb3d14183180e6c42c portoshim_focal_v1.0.11-alpha.5_amd64.tgz
21 changes: 13 additions & 8 deletions hack/update/porto_version/update_porto_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"k8s.io/klog/v2"

"k8s.io/minikube/hack/update"
)

Expand Down Expand Up @@ -64,18 +65,22 @@ func main() {
}

func updateHashFile(version, arch, packagePath string) error {
r, err := http.Get(fmt.Sprintf("https://github.com/go-faster/porto/releases/download/v%s/porto_focal_%s_%s.tgz", version, version, arch))
// https://github.com/go-faster/porto/releases/download/v5.3.31/porto_focal_v5.3.31_amd64.tgz
link := fmt.Sprintf("https://github.com/go-faster/porto/releases/download/%[1]s/porto_focal_%[1]s_%[2]s.tgz", version, arch)
r, err := http.Get(link)
if err != nil {
return fmt.Errorf("failed to download source code: %v", err)
return fmt.Errorf("failed to download binary: %v", err)
}
defer r.Body.Close()
b, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %v", err)
if r.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download binary: %s", r.Status)
}
h := sha256.New()
if _, err := io.Copy(h, r.Body); err != nil {
return fmt.Errorf("failed to copy response body: %v", err)
}
sum := sha256.Sum256(b)
filePath := fmt.Sprintf("../../../deploy/iso/minikube-iso/arch/%s/porto-bin.hash", packagePath)
b, err = os.ReadFile(filePath)
b, err := os.ReadFile(filePath)
if err != nil {
return fmt.Errorf("failed to read hash file: %v", err)
}
Expand All @@ -88,7 +93,7 @@ func updateHashFile(version, arch, packagePath string) error {
return fmt.Errorf("failed to open hash file: %v", err)
}
defer f.Close()
if _, err := f.WriteString(fmt.Sprintf("sha256 %x porto_focal_%s_%s.tgz\n", sum, version, arch)); err != nil {
if _, err := f.WriteString(fmt.Sprintf("sha256 %x porto_focal_%s_%s.tgz\n", h.Sum(nil), version, arch)); err != nil {
return fmt.Errorf("failed to write to hash file: %v", err)
}
return nil
Expand Down
20 changes: 12 additions & 8 deletions hack/update/portoshim_version/update_portoshim_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"time"

"k8s.io/klog/v2"

"k8s.io/minikube/hack/update"
)

Expand Down Expand Up @@ -64,18 +65,21 @@ func main() {
}

func updateHashFile(version, arch, packagePath string) error {
r, err := http.Get(fmt.Sprintf("https://github.com/go-faster/portoshim/releases/download/v%s/portoshim_focal_%s_%s.tgz", version, version, arch))
link := fmt.Sprintf("https://github.com/go-faster/portoshim/releases/download/%[1]s/portoshim_focal_%[1]s_%[2]s.tgz", version, arch)
r, err := http.Get(link)
if err != nil {
return fmt.Errorf("failed to download source code: %v", err)
return fmt.Errorf("failed to download binary: %v", err)
}
defer r.Body.Close()
b, err := io.ReadAll(r.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %v", err)
if r.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download binary: %s", r.Status)
}
h := sha256.New()
if _, err := io.Copy(h, r.Body); err != nil {
return fmt.Errorf("failed to copy response body: %v", err)
}
sum := sha256.Sum256(b)
filePath := fmt.Sprintf("../../../deploy/iso/minikube-iso/arch/%s/portoshim-bin.hash", packagePath)
b, err = os.ReadFile(filePath)
b, err := os.ReadFile(filePath)
if err != nil {
return fmt.Errorf("failed to read hash file: %v", err)
}
Expand All @@ -88,7 +92,7 @@ func updateHashFile(version, arch, packagePath string) error {
return fmt.Errorf("failed to open hash file: %v", err)
}
defer f.Close()
if _, err := f.WriteString(fmt.Sprintf("sha256 %x portoshim_focal_%s_%s.tgz\n", sum, version, arch)); err != nil {
if _, err := f.WriteString(fmt.Sprintf("sha256 %x portoshim_focal_%s_%s.tgz\n", h.Sum(nil), version, arch)); err != nil {
return fmt.Errorf("failed to write to hash file: %v", err)
}
return nil
Expand Down

0 comments on commit eb89b1f

Please sign in to comment.