Building workspace modules as individual projects


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 file lists all the modules, and attempting to build a single module with the full 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 file within each module’s Dockerfile?

Thanks, example below:


3 modules, a and b both depend on common.

use ./common
use ./a
use ./b

— a.Dockerfile
cp .
cp ./common ./common
cp ./a ./a

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

Hi you could use

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

after the copy in your Dockerfile

Hi @zwanggolang,

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

Note that Go workspaces are a way for locally working with multiple modules. A 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.