Skip to content

Commit

Permalink
chore: building components in CI
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Fontes <[email protected]>
  • Loading branch information
lxfontes committed Dec 7, 2024
1 parent e3989dc commit c53deb9
Show file tree
Hide file tree
Showing 44 changed files with 58 additions and 16 deletions.
34 changes: 28 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# syntax=docker/dockerfile:1

FROM ghcr.io/bytecodealliance/wrpc:cb43ec8 AS wrpc

FROM golang:1.23 AS build
ENV TINYGO_RELEASE=0.34.0
ENV WASMTOOLS_VERSION=1.221.2
ENV PATH=${PATH}:/usr/local/tinygo/bin
ARG TARGETOS
ARG TARGETARCH

RUN <<EOF
cd /tmp
wget -q https://github.com/tinygo-org/tinygo/releases/download/v${TINYGO_RELEASE}/tinygo${TINYGO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz
tar zxf tinygo${TINYGO_RELEASE}.${TARGETOS}-${TARGETARCH}.tar.gz -C /usr/local

wget -q https://github.com/bytecodealliance/wasm-tools/releases/download/v${WASMTOOLS_VERSION}/wasm-tools-${WASMTOOLS_VERSION}-x86_64-linux.tar.gz
tar zxf wasm-tools-${WASMTOOLS_VERSION}-x86_64-linux.tar.gz
cp wasm-tools-${WASMTOOLS_VERSION}-x86_64-linux/wasm-tools /usr/local/bin/
rm -f *gz
EOF

RUN <<EOF
go install go.k6.io/xk6/cmd/xk6@latest
CGO_ENABLED=0 go install github.com/nats-io/natscli/[email protected]
CGO_ENABLED=0 go install github.com/rakyll/[email protected]
EOF

WORKDIR /go/src/xk6-wrpc
RUN go install go.k6.io/xk6/cmd/xk6@latest
RUN CGO_ENABLED=0 go install github.com/nats-io/natscli/[email protected]
RUN CGO_ENABLED=0 go install github.com/rakyll/[email protected]
COPY . .
RUN xk6 build --with xk6-wrpc=. --with github.com/grafana/xk6-dashboard@latest --with github.com/cosmonic-labs/xk6-nats@latest

COPY . .
RUN make build

FROM alpine:latest AS base
RUN apk add --no-cache \
Expand All @@ -22,6 +44,6 @@ COPY --from=wrpc /bin/wrpc-wasmtime /usr/bin/wrpc-wasmtime
COPY --from=build /go/bin/nats /usr/bin/nats
COPY --from=build /go/bin/hey /usr/bin/hey
COPY --from=build /go/src/xk6-wrpc/k6 /usr/bin/k6
COPY --from=build /go/src/xk6-wrpc/blaster-component/blaster-component.wasm /blaster-component.wasm
COPY --from=build /go/src/xk6-wrpc/components/blaster/blaster.wasm /components/
USER k6
ENTRYPOINT ["/usr/bin/k6"]
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ BUILD_TAG?=latest

all: build

k6: *.go
k6:
xk6 build --with xk6-wrpc=. --with github.com/grafana/xk6-dashboard@latest --with github.com/szkiba/xk6-top@latest --with github.com/cosmonic-labs/xk6-nats@latest

bindgen:
bindgen: k6-bindgen components-bindgen

k6-bindgen:
wit-deps && wit-bindgen-wrpc go --out-dir internal --package $(shell go list)/internal wit
(cd blaster-component && wit-deps && go generate)
components-bindgen:
@for component in components/*; do\
echo "==> $${component}";\
make -C $${component} bindgen;\
done

component:
(cd blaster-component && tinygo build -target wasip2 -wit-package wit -wit-world server)
components:
@for component in components/*; do\
echo "==> $${component}";\
make -C $${component} build;\
done

build: k6 component
build: k6 components

docker:
docker build -t $(BUILD_IMAGE):$(BUILD_TAG) .

.PHONY: build bindgen docker
.PHONY: build k6 bindgen docker components components-bindgen
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/internal/
/build/
/blaster.wasm
10 changes: 10 additions & 0 deletions components/blaster/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all: bindgen build

.PHONY: bindgen
bindgen:
wit-deps
go generate

.PHONY: build
build:
tinygo build -target wasip2 -wit-package wit -wit-world server -o blaster.wasm
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name = "blaster-component"
name = "blaster"
language = "tinygo"
type = "component"
version = "0.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ sha512 = "da2622210a9e3eea82b99f1a5b8a44ce5443d009cb943f7bca0bf9cf4360829b289913
deps = ["clocks", "filesystem", "io", "random", "sockets"]

[xk6-wrpc]
path = "../../shared-wit"
path = "../../../shared-wit"
sha256 = "de73abe3ad2da22ff1076bbf1be15109808f327228ad0f387c19d9a6441d3c95"
sha512 = "0d06f04b1a004d7bc4a6972b1a67f071f148666ccd202f2bfb1ff135e21894c88417b38109a50a3e0dbdeab8659616bb2549e3e9451492b418e611b6120035d1"
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xk6-wrpc = "../../shared-wit"
xk6-wrpc = "../../../shared-wit"
wasi-cli = "https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c53deb9

Please sign in to comment.