Building workspace modules as individual projects

Hello,

I have a monorepo with multiple modules that I recently converted to a workspace.

Since there are many modules, each module’s Dockerfile is set up to only contain its own code and any dependencies within the monorepo.

This poses an issue as the go.work file lists all the modules, and attempting to build a single module with the full go.work file errors out as some modules are missing.

I’m not keen on including the entire monorepo in the builds of individual modules, since most of the time each module only depends on one other module.

Is there a suggestion other than manually editing the go.work file within each module’s Dockerfile?

Thanks, example below:

EXAMPLE

3 modules, a and b both depend on common.

— go.work
use ./common
use ./a
use ./b

— a.Dockerfile
cp go.work .
cp ./common ./common
cp ./a ./a

Building a.Dockerfile fails as go.work expects module b to exist.

Hi you could use

go work edit -dropuse=<path to be excluded> go.work

after the copy in your Dockerfile

Hi @zwanggolang,

I conclude this means that you added go.work to the repository, correct?.

Note that Go workspaces are a way for locally working with multiple modules. A go.work file is not supposed to be checked in to version control although the official docs fail to mention this.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.