Skip to content

Build and deploy

maxence-charriere edited this page Jun 28, 2020 · 18 revisions

Table of Contents

Build

Having a working progressive web app built with the go-app package requires 2 parts to be built.

build

Server

The server is a classic Go program. It uses the Handler to serve the WebAssembly part. It is built with the standard go build command:

go build

See the HTTP Handler topic.

WebAssembly app

The WebAssembly app part is where all the UI is implemented. It is served by the server part from the /app.wasm endpoint. Building this requires using the go build command while specifying the wasm architecture and the js operating system:

GOARCH=wasm GOOS=js go build -o app.wasm

Once built, app.wasm must be moved in the web directory, located by the side of the server binary:

.                   # Directory root
├── server          # Server binary
├── main.go         # Server source code
└── web             # Directory for static resources
    └── app.wasm    # Wasm binary

Unit tests

While unit testing the server is a standard go test command, testing the WebAssembly part requires some setup.

Since the app is working on a web browser, the unit tests should run in a similar environment. Set up WebAssembly go test to run in the browser with the following command:

go get -u github.com/agnivade/wasmbrowsertest && \
	mv $GOPATH/bin/wasmbrowsertest $GOPATH/bin/go_js_wasm_exec

It installs wasmbrowsertest which is a program that allows go test to be executed on Chrome with headless mode. Because it uses resources bound to a specific version of Go, the command above has to be used whenever you update Go.

Then, as for the build command, the unit test can be launched by specifying the wasm architecture and the js operating system:

GOARCH=wasm GOOS=js go test

Deploy

From local machines to cloud providers, progressive web apps built with go-app can be deployed in multiple places. Refer to the demo examples to see how it can be done:

Sources Description
hello Hello app.
hello-local Hello app that runs on a local server.
hello-local-external-root Hello app that runs on a local server but with a custom root directory.
hello-docker Hello app that run in a Docker container.
hello-gcloud-appengine Hello app that run on Google Cloud App Engine.
See live
hello-gcloud-func Hello app that run on Google a Cloud Function.
See live
Clone this wiki locally