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

rpk/transform/buildpack: upgrade tinygo #23969

Merged
merged 1 commit into from
Nov 1, 2024
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
5 changes: 4 additions & 1 deletion src/go/rpk/pkg/cli/transform/buildpack/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ go_library(
go_test(
name = "buildpack_test",
size = "small",
srcs = ["download_test.go"],
srcs = [
"download_test.go",
"url_test.go",
],
embed = [":buildpack"],
deps = [
"//src/go/rpk/pkg/testfs",
Expand Down
38 changes: 22 additions & 16 deletions src/go/rpk/pkg/cli/transform/buildpack/buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package buildpack

import (
"archive/tar"
"bytes"
"compress/gzip"
"context"
"crypto/sha256"
Expand All @@ -25,6 +26,7 @@ import (
"path/filepath"
"runtime"
"strings"
"text/template"
"time"

"github.com/redpanda-data/redpanda/src/go/rpk/pkg/httpapi"
Expand All @@ -36,24 +38,26 @@ import (
)

var Tinygo = Buildpack{
Name: "tinygo",
baseURL: "https://github.com/redpanda-data/tinygo/releases/download/v0.31.0-rpk2",
Name: "tinygo",
baseURL: "https://github.com/tinygo-org/tinygo/releases/download/v0.34.0/tinygo0.34.0",
template: "{{.BaseURL}}.{{.GOOS}}-{{.GOARCH}}.tar.gz",
shaSums: map[string]map[string]string{
"darwin": {
"amd64": "54f9f295f04c4dfc9584b771f71a199940746306927780b6447abc9785126de5",
"arm64": "efcf565bb0036f9d6921a418f0809b3a14eca1b9af6739435aa9bbaa6398cd41",
"amd64": "451c51a080b3b64d1ac99906840478f712ac62bbf7e1e9bc55ddd04e3730455e",
"arm64": "6a9bae4e57aaf8bf814cd62df6d527d402394eca59257b2bb1dddd3bcb3a51a7",
},
"linux": {
"amd64": "3c9f9b60efbbe4aecce847e6c0f5f5100558b1e4b44a1baf628c55c7c5fc74bb",
"arm64": "35f98e545992664b251d57f1674ea942d2528fcdeb6d0868294e7f63aa933c24",
"amd64": "8acd27a39090e1e5c3ca341e81350f813ec6a02bf8090c4fc7c4b1afd4186341",
"arm64": "a84b5134dc5144a494e3b7e78579536aca34c77951ddd0b19c300209d8b541e1",
},
},
}

var JavaScript = Buildpack{
Name: "javascript",
// TODO: Find a better place to host these binaries than the tinygo repo
baseURL: "https://github.com/redpanda-data/tinygo/releases/download/js-sdk-v1.1",
baseURL: "https://github.com/redpanda-data/tinygo/releases/download/js-sdk-v1.1",
template: "{{.BaseURL}}/{{.Name}}-{{.GOOS}}-{{.GOARCH}}.tar.gz",
shaSums: map[string]map[string]string{
"darwin": {
"amd64": "56eb59ddb320c9f8fb4f79910eaeebd68e1d6499d9827b9120ffc6135a8ada03",
Expand All @@ -71,9 +75,9 @@ type Buildpack struct {
// Name of the plugin, this will also be the command name.
Name string
// baseURL is where to download the plugin from.
//
// This baseURL will be appended with `/{name}-{goos}-{goarch}.tar.gz` to resolve the full URL.
baseURL string
// The pattern to resolve the full URL.
template string
// shaSums is the mapping of [GOOS][GOARCH] to sha256 of the tarball that is downloaded (before any decompression).
shaSums map[string]map[string]string
}
Expand All @@ -95,13 +99,15 @@ func (bp *Buildpack) PlatformSha() (sha string, err error) {

// URL is the fully resolved URL to download the gzipped tarball for the current platform.
func (bp *Buildpack) URL() string {
return fmt.Sprintf(
"%s/%s-%s-%s.tar.gz",
bp.baseURL,
bp.Name,
runtime.GOOS,
runtime.GOARCH,
)
t := template.Must(template.New("URL").Parse(bp.template))
b := bytes.NewBuffer(nil)
template.Must(t, t.Execute(b, map[string]string{
"Name": bp.Name,
"BaseURL": bp.baseURL,
Comment on lines +104 to +106
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: the "Name" field is quietly ignored if it doesn't appear in the base template then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes exactly

"GOOS": runtime.GOOS,
"GOARCH": runtime.GOARCH,
}))
return b.String()
}

// BinPath returns the path to the main binary for the buildpack that needs to be linked as a plugin.
Expand Down
21 changes: 21 additions & 0 deletions src/go/rpk/pkg/cli/transform/buildpack/url_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 Redpanda Data, Inc.
*
* Use of this software is governed by the Business Source License
* included in the file licenses/BSL.md
*
* As of the Change Date specified in that file, in accordance with
* the Business Source License, use of this software will be governed
* by the Apache License, Version 2.0
*/

package buildpack

import "testing"

func TestURLIsValidTemplate(t *testing.T) {
// Just ensure these functions don't panic
// as the templates are valid.
t.Log(Tinygo.URL())
t.Log(JavaScript.URL())
}