Golang Shared Monorepo
danieltitkov
HOBBYOP

a year ago

I have a golang monorepo that is structured roughly like this:

pkg
..go.mod 
..lib.go
service
..go.mod
..main.go
..Dockefile

Services are importing pkg with the replace directive

replace github.com/my/repo/pkg => ../pkg

Thus, I cannot set a root directory as /service since then it won't be able to access ../pkg.

I don't want to let it go the the github and download the code from there from inside the building container since in this case I would have to have quite an unenjoyable hustle with github access tokens and it also kinda negates the benefits of having a monorepo.

Alternatives that i consider:

  • using vendor (also seems kinda stupid inside a monorepo)

  • building images outside Railway and deploying from external registry

But since those are clearly suboptimal I wonder: is it possible to make this work with custom build command? Should be so, I guess, but I haven't found any documentation about what this command should be. The only example is for JS.

Should it be go build...? Or docker build? Or something else? I also don't mind moving my dockerfiles from services' individual folders to the root if this is needed to provide them with the correct context. But I just don't know what the command should be.

I'll appreciate if you would help with this since I really liked the feel of Railway I want to continue using it.

Solved

6 Replies

a year ago

Hello,

Since this is more application level support than platform support we would need a minimal reproducible example.


danieltitkov
HOBBYOP

a year ago

Ok, I've created an example project. https://github.com/tinygodsdev/rlw-mrepo-test

Though I see this more as a documentation issue. No information or examples for custom build commands. The solution is simple in theory - just to build the correct docker file with the correct context. Should be possible? Dockerfile can be built from inside the service directory with an outside context, or from the parent, or the Dockerfile itself can be placed in the parent. Any of those should suffice.


a year ago

You are using a Dockerfile, build commands are defined in the Dockerfile.

As for how to set the location of the Dockerfile -

https://docs.railway.app/guides/dockerfiles#custom-dockerfile-path


a year ago

You had some simple issues with the Dockerfile -

https://github.com/brody192/rlw-mrepo-test/commit/3bdc1cf1da88d5a9805fb8e508d0cc0ad329ffe3

Works now -

Attachments


danieltitkov
HOBBYOP

a year ago

Thanks a lot! That helped.

For future reference, the solution is:

  • Railway deployment points at the root of the repository (or common root of the service and lib)

  • add variable RAILWAY_DOCKERFILE_PATH=/service/Dockerfile

  • structure the Dockerfile to be built from the root of the repository


a year ago

Glad I could help!


Status changed to Solved brody over 1 year ago


Loading...