I need to incorporate the wasm build process into docker-compose.
While running docker-compose I get the following error:
can't load package: cannot find module providing package wasm.go: unrecognized import path "wasm.go": https fetch: Get "https://wasm.go/?go-get=1":
I attempted to use a go.mod next to the docker-compose.yml but that gives me the exact same error.
Below are the files are in use.
docker-compose.yml
version : '3'
services:
mysql:
image: library/mysql:8.0
container_name: container_mysql
env_file:
- ./MySQL/.env
environment:
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
volumes:
- ./MySQL/sql-scripts/test.sql:/docker-entrypoint-initdb.d/test.sql
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: container_phpmyadmin
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
PMA_ARBITRARY: 1
restart: always
ports:
- 8183:80
app:
container_name: container_api
command: /bin/sh -c "./script.compile.wasm.sh"
env_file:
- ./Go/.env
build:
context: ./Go
ports:
- 9000:9000
restart: always
depends_on:
- mysql
wasm.go
package main
import (
"os"
"strconv"
"syscall/js"
)
func key(this js.Value, arg []js.Value) interface{} {
arg[0].Call("stopPropagation")
arg[0].Call("preventDefault")
return nil
}
func sum(this js.Value, args []js.Value) interface{} {
var rv interface{}
value1 := js.Global().Get("document").Call("getElementById", "num1").Get("value").String()
value2 := js.Global().Get("document").Call("getElementById", "num2").Get("value").String()
int1, _ := strconv.Atoi(value1)
int2, _ := strconv.Atoi(value2)
js.Global().Get("document").Call("getElementById", "result").Set("value", int1+int2)
return rv
}
func register_callbacks() {
js.Global().Set("key", js.FuncOf(key))
js.Global().Set("sum", js.FuncOf(sum))
}
func main() {
register_callbacks()
appKey := os.Getenv("APP_KEY")
js.Global().Get("document").Call("getElementById", "env").Set("value", appKey)
js.Global().Get("document").Call("getElementById", "env2").Set("value", "hardcoded")
select {}
}
script.compile.wasm.sh
#!/bin/sh
GOOS=js GOARCH=wasm go build -o ./Go/assets/main.wasm main.wasm.go
File structure looks like:
|app/docker-compose.yml
|app/wasm.go
|app/script.compile.wasm.sh
|app/Go
|app/Go/assets
Running the script alone works fine
app$ ./script.compile.wasm.sh