From 8fe829d5fd321b2fbaa8f74d5a19ba3d9c95230d Mon Sep 17 00:00:00 2001 From: Stefan Benten Date: Fri, 11 Dec 2020 02:23:39 +0100 Subject: [PATCH] build: add wasm bits to Dockerfile and bump to go v1.15.6 (#3992) --- Makefile | 19 +++++++++++++++++-- cmd/satellite/Dockerfile | 2 ++ satellite/console/wasm/README.md | 2 +- scripts/build-wasm.sh | 13 +++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100755 scripts/build-wasm.sh diff --git a/Makefile b/Makefile index f6e52c851..805eaeb75 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -GO_VERSION ?= 1.15.5 +GO_VERSION ?= 1.15.6 GOOS ?= linux GOARCH ?= amd64 GOPATH ?= $(shell go env GOPATH) @@ -144,6 +144,14 @@ storagenode-console: /usr/bin/env echo -e '\nfunc init() { FileSystem = AssetFile() }' >> storagenode/console/consoleassets/bindata.resource.go gofmt -w -s storagenode/console/consoleassets/bindata.resource.go +.PHONY: satellite-wasm +satellite-wasm: + docker run --rm -i -v "${PWD}":/go/src/storj.io/storj -e GO111MODULE=on \ + -e GOOS=js -e GOARCH=wasm -e GOARM=6 -e CGO_ENABLED=1 \ + -v /tmp/go-cache:/tmp/.cache/go-build -v /tmp/go-pkg:/go/pkg \ + -w /go/src/storj.io/storj -e GOPROXY -e TAG=${TAG} -u $(shell id -u):$(shell id -g) storjlabs/golang:${GO_VERSION} \ + scripts/build-wasm.sh ;\ + .PHONY: images images: satellite-image segment-reaper-image storagenode-image uplink-image versioncontrol-image ## Build satellite, segment-reaper, storagenode, uplink, and versioncontrol Docker images echo Built version: ${TAG} @@ -228,6 +236,13 @@ binary: -w /go/src/storj.io/storj -e GOPROXY -u $(shell id -u):$(shell id -g) storjlabs/golang:${GO_VERSION} \ scripts/release.sh build $(EXTRA_ARGS) -o release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT} \ storj.io/storj/cmd/${COMPONENT} + + if [ "${COMPONENT}" = "satellite" ] && [ "${GOARCH}" = "amd64" ]; \ + then \ + echo "Building wasm code"; \ + $(MAKE) satellite-wasm; \ + fi + chmod 755 release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT} [ "${FILEEXT}" = ".exe" ] && storj-sign release/${TAG}/$(COMPONENT)_${GOOS}_${GOARCH}${FILEEXT} || echo "Skipping signing" rm -f release/${TAG}/${COMPONENT}_${GOOS}_${GOARCH}.zip @@ -307,7 +322,7 @@ push-images: ## Push Docker images to Docker Hub (jenkins) binaries-upload: ## Upload binaries to Google Storage (jenkins) cd "release/${TAG}"; for f in *; do \ zipname=$$(echo $${f} | sed 's/.exe//g') && \ - zip "$${zipname}.zip" "$${f}" \ + zip -r "$${zipname}.zip" "$${f}" \ ; done cd "release/${TAG}"; gsutil -m cp -r *.zip "gs://storj-v3-alpha-builds/${TAG}/" diff --git a/cmd/satellite/Dockerfile b/cmd/satellite/Dockerfile index faed54edd..6fd5c5c4a 100644 --- a/cmd/satellite/Dockerfile +++ b/cmd/satellite/Dockerfile @@ -26,6 +26,8 @@ COPY --from=ui /app/static /app/static COPY --from=ui /app/dist /app/dist COPY --from=ui /app/marketing /app/marketing COPY --from=ca-cert /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY release/${TAG}/wasm/access.wasm /app/static/wasm/ +COPY release/${TAG}/wasm/wasm_exec.js /app/static/wasm/ COPY release/${TAG}/satellite_linux_${GOARCH:-amd64} /app/satellite COPY release/${TAG}/inspector_linux_${GOARCH:-amd64} /app/inspector COPY cmd/satellite/entrypoint /entrypoint diff --git a/satellite/console/wasm/README.md b/satellite/console/wasm/README.md index 7fdbe8622..96174ac1a 100644 --- a/satellite/console/wasm/README.md +++ b/satellite/console/wasm/README.md @@ -6,7 +6,7 @@ In order to use the uplink library from the browser, we can compile the uplink l To generate wasm code that can create access grants in the web browser, run the following from the storj/wasm directory: ``` -$ GOOS=js GOARCH=wasm go build -o access.wasm access.go +$ GOOS=js GOARCH=wasm go build -o access.wasm storj.io/storj/satellite/console/wasm ``` The `access.wasm` code can then be loaded into the browser in a script tag in an html page. Also needed is a JavaScript support file which ships with golang. diff --git a/scripts/build-wasm.sh b/scripts/build-wasm.sh new file mode 100755 index 000000000..74ec9f012 --- /dev/null +++ b/scripts/build-wasm.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +set -eu +set -o pipefail + +# Ensure the directory exists +mkdir -p release/$TAG/wasm/ + +# Copy wasm javascript to match the go version +cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" release/$TAG/wasm/ + +# Build wasm code +exec go build -o release/$TAG/wasm/access.wasm storj.io/storj/satellite/console/wasm