Skip to content

Commit 7f618cc

Browse files
committed
support 'extension build/test/clean' command for TinyGo
Signed-off-by: mathetake <[email protected]>
1 parent c8513da commit 7f618cc

File tree

12 files changed

+153
-10
lines changed

12 files changed

+153
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
ENVOY = standard:1.11.1
1616
HUB ?= docker.io/getenvoy
1717
GETENVOY_TAG ?= dev
18-
BUILDERS_LANGS := rust
18+
BUILDERS_LANGS := rust tinygo
1919
BUILDERS_TAG ?= latest
2020
EXTRA_TAG ?=
2121

@@ -133,7 +133,7 @@ builder/$(1):
133133
$(if $(USE_DOCKER_BUILDKIT_CACHE),--build-arg BUILDKIT_INLINE_CACHE=1,) \
134134
$(if $(USE_DOCKER_BUILDKIT_CACHE),--cache-from $(call EXTENSION_BUILDER_IMAGE,$(1),$(EXTENSION_BUILDER_IMAGE_LATEST_VERSION)),) \
135135
-t $(call EXTENSION_BUILDER_IMAGE,$(1),$(BUILDERS_TAG)) \
136-
images/extension-builders/$(1)
136+
-f images/extension-builders/$(1)/Dockerfile images/extension-builders
137137
endef
138138
$(foreach lang,$(BUILDERS_LANGS),$(eval $(call GEN_BUILD_EXTENSION_BUILDER_IMAGE_TARGET,$(lang))))
139139

data/extension/init/templates/tinygo/envoy.filters.http/default/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module envoy.filters.http
22

3-
go 1.14
3+
go 1.15
44

55
require (
66
github.com/stretchr/testify v1.6.1

images/extension-builders/rust/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ RUN rustup target add wasm32-unknown-unknown
2424
ENV CARGO_HOME=
2525

2626
COPY ./entrypoint.sh /usr/local/getenvoy/extension/builder/entrypoint.sh
27-
COPY ./commands.sh /usr/local/getenvoy/extension/builder/commands.sh
27+
COPY ./rust/commands.sh /usr/local/getenvoy/extension/builder/commands.sh
2828
ENTRYPOINT ["/usr/local/getenvoy/extension/builder/entrypoint.sh"]
2929
CMD ["--help"]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Copyright 2020 Tetrate
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
#
16+
# Builder image for Envoy Wasm extensions written in Go.
17+
#
18+
19+
FROM golang:1.15
20+
21+
ENV TINYGO_VERSION=0.15.0
22+
23+
RUN wget https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_VERSION}/tinygo_${TINYGO_VERSION}_amd64.deb
24+
RUN dpkg -i tinygo_${TINYGO_VERSION}_amd64.deb && rm tinygo_${TINYGO_VERSION}_amd64.deb
25+
26+
ENV GOCACHE=/source/.gocache
27+
ENV GOMODCACHE=/source/.gomodcache
28+
ENV XDG_CACHE_HOME=/source/.cache
29+
30+
ENV TINYGO_SDK_NAME=github.com/tetratelabs/proxy-wasm-go-sdk
31+
ENV TINYGO_SDK_VERSION=v0.0.1
32+
ENV TINYGO_SDK_PATH=${GOMODCACHE}/${TINYGO_SDK_NAME}@${TINYGO_SDK_VERSION}
33+
34+
RUN mkdir -p ${TINYGO_SDK_PATH} && git clone https://${TINYGO_SDK_NAME} -b ${TINYGO_SDK_VERSION} ${TINYGO_SDK_PATH}
35+
36+
37+
COPY ./entrypoint.sh /usr/local/getenvoy/extension/builder/entrypoint.sh
38+
COPY ./tinygo/commands.sh /usr/local/getenvoy/extension/builder/commands.sh
39+
ENTRYPOINT ["/usr/local/getenvoy/extension/builder/entrypoint.sh"]
40+
CMD ["--help"]
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2020 Tetrate
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#########################################################################
18+
# Build Wasm extension and copy *.wasm file to a given location.
19+
# Globals:
20+
# CARGO_TARGET_DIR
21+
# GETENVOY_WORKSPACE_DIR
22+
# Arguments:
23+
# Path relative to the workspace root to copy *.wasm file to.
24+
#########################################################################
25+
extension_build() {
26+
tinygo build -o "$1" -wasm-abi=generic -target wasm main.go
27+
}
28+
29+
extension_test() {
30+
go test -tags=proxytest -v ./...
31+
}
32+
33+
extension_clean() {
34+
rm main.wasm || true
35+
rm -rf "${GOCACHE}" "${XDG_CACHE_HOME}" "${GOMODCACHE}" || true
36+
}

pkg/cmd/extension/test/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Run unit tests on Envoy extension.`,
8282
err = toolchain.Test(types.TestContext{
8383
IO: cmdutil.StreamsOf(cmd),
8484
})
85+
8586
if err != nil {
8687
return errors.Wrapf(err, "failed to unit test Envoy extension using %q toolchain", opts.Toolchain.Name)
8788
}

pkg/extension/workspace/config/extension/types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ func (l Language) String() string {
4747
}
4848

4949
const (
50-
// LanguageRust represens a Rust programming language.
51-
LanguageRust Language = "rust"
50+
// LanguageRust represents a Rust programming language.
51+
LanguageRust Language = "rust"
52+
// LanguageTinyGo represents a TinyGo programming language.
5253
LanguageTinyGo Language = "tinygo"
5354
)
5455

pkg/extension/workspace/toolchain/builtin/default_config.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var (
3636
return version.Build.Version
3737
}()
3838
// defaultRustBuildImage represents a full name of the default Rust builder image in a Docker registry.
39-
defaultRustBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-rust-builder", Tag: defaultBuildImageTag}.String()
39+
defaultRustBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-rust-builder", Tag: defaultBuildImageTag}.String()
40+
defaultTinyGoBuildImage = dockerutil.ImageName{Org: defaultBuildImageOrg, Name: "extension-tinygo-builder", Tag: defaultBuildImageTag}.String()
4041
)
4142

4243
// defaultConfigFor returns a default toolchain config for a given extension.
@@ -57,6 +58,8 @@ func defaultBuildImageFor(language extensionconfig.Language) string {
5758
switch language {
5859
case extensionconfig.LanguageRust:
5960
return defaultRustBuildImage
61+
case extensionconfig.LanguageTinyGo:
62+
return defaultTinyGoBuildImage
6063
default:
6164
// must be caught by unit tests
6265
panic(errors.Errorf("failed to determine default build image for unsupported programming language %q", language))
@@ -69,6 +72,8 @@ func defaultOutputPathFor(language extensionconfig.Language) string {
6972
case extensionconfig.LanguageRust:
7073
// keep *.wasm file inside Cargo build dir (to be cleaned up automatically)
7174
return "target/getenvoy/extension.wasm"
75+
case extensionconfig.LanguageTinyGo:
76+
return "main.wasm"
7277
default:
7378
// must be caught by unit tests
7479
panic(errors.Errorf("failed to determine default output path for unsupported programming language %q", language))

pkg/extension/workspace/toolchain/builtin/example_config_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import (
2121
. "github.com/onsi/ginkgo"
2222
. "github.com/onsi/ginkgo/extensions/table"
2323
. "github.com/onsi/gomega"
24-
25-
. "github.com/tetratelabs/getenvoy/pkg/extension/workspace/toolchain/builtin"
26-
2724
"github.com/pkg/errors"
2825

2926
"github.com/tetratelabs/getenvoy/pkg/extension/workspace/config/extension"
27+
. "github.com/tetratelabs/getenvoy/pkg/extension/workspace/toolchain/builtin"
3028
)
3129

3230
var _ = Describe("ExampleConfig()", func() {

0 commit comments

Comments
 (0)