Z
Zeropsβ€’3mo ago
TonyT

Monorepo deployment

Hi I'm having trouble deploying a go application from a monorepo. Repo:
./db
./www
./zerops.yml
./db
./www
./zerops.yml
The go application is in ./www:
./assets/
./cmd/
./go.mod
./go.sum
./assets/
./cmd/
./go.mod
./go.sum
And here's my zerops.yml
zerops:
- setup: www
# ==== how to build your application ====
build:
# what technologies should the build
# container be based on (can be an array)
base: go@1

# build your application
buildCommands:
- go build -o ./build/server ./cmd/app/main.go

# select which files / folders to deploy
# after the build successfully finished
deployFiles:
- ./build/server
- ./assets/css/app.css

# ==== how to run your application ====
run:
# what technology should the runtime
# container be based on, can be extended
# in `run.prepareCommands` using
# `sudo zsc install nodejs@20`
base: go@1

# what ports your app listens on
# and whether it supports http traffic
ports:
- port: 3000
httpSupport: true

# how to start your application
start: ./server
zerops:
- setup: www
# ==== how to build your application ====
build:
# what technologies should the build
# container be based on (can be an array)
base: go@1

# build your application
buildCommands:
- go build -o ./build/server ./cmd/app/main.go

# select which files / folders to deploy
# after the build successfully finished
deployFiles:
- ./build/server
- ./assets/css/app.css

# ==== how to run your application ====
run:
# what technology should the runtime
# container be based on, can be extended
# in `run.prepareCommands` using
# `sudo zsc install nodejs@20`
base: go@1

# what ports your app listens on
# and whether it supports http traffic
ports:
- port: 3000
httpSupport: true

# how to start your application
start: ./server
And here's the output:
━━━━ πŸ™ go build -o ./build/server ./cmd/app/main.go ━━━━
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
━━━━ ❌ go build -o ./build/server ./cmd/app/main.go ━━━━
[BUILD ERROR] running build commands failed
βœ— ERR Application deploy failed
βœ— ERR last command has finished with error, identifier for communication with our support: bBMoYcX2QX2KZQ0M1OmAwA
━━━━ πŸ™ go build -o ./build/server ./cmd/app/main.go ━━━━
go: go.mod file not found in current directory or any parent directory; see 'go help modules'
━━━━ ❌ go build -o ./build/server ./cmd/app/main.go ━━━━
[BUILD ERROR] running build commands failed
βœ— ERR Application deploy failed
βœ— ERR last command has finished with error, identifier for communication with our support: bBMoYcX2QX2KZQ0M1OmAwA
I've tried changing the go build command to
go build -o ./www/build/server ./www/cmd/app/main.go
go build -o ./www/build/server ./www/cmd/app/main.go
Any ideas? Thanks
3 Replies
Jan Saidl
Jan Saidlβ€’3mo ago
Hi @TonyT I'd say the current directory for the build needs to be adjusted, and then deployFiles needs to be set up correctly. I think it could be something like this:
buildCommands:
- cd www; go build -o ../server ./cmd/app/main.go
deployFiles:
- ./server
- ./www/~/assets/css/app.css
buildCommands:
- cd www; go build -o ../server ./cmd/app/main.go
deployFiles:
- ./server
- ./www/~/assets/css/app.css
Try it, and if it doesn't work, we can still enable debug mode and look directly into the build container to see what's happening there. BTW, it might be worth embedding those assets directly into the Go binary using //go:embed and then returning them directly from there. https://docs.zerops.io/zerops-yaml/specification#using-wildcards
TonyT
TonyTOPβ€’3mo ago
Hi Jan Looks good - deploy started successfully (although failed due to a different error, something for me to fix in an imported library). Thanks for your quick response. Tony
Jan Saidl
Jan Saidlβ€’3mo ago
If anything else doesn't work, don't hesitate to contact us.

Did you find this page helpful?