nixpacks
nixpacks copied to clipboard
Able to set Docker network and custom hosts during build
Feature request
Simply able to set custom docker network (--network) and add hosts (--add-host) to the nixpacks command, so the build process will have access to the internal resources - and in case of a user defined network - and dns.
Motivation
For example, if you build a NodeJS based project with Prisma(prisma.io), the build process is not able to access the database to generate types for the final image.
Contribution
I can help with more details, or even submit a PR.
Would defs take a PR for this!
I'll tinker around a little bit, see if I can open up a PR. No Rust experience yet though, going to be a bumpy ride but I'm in for it 😄
Out of curiosity @JakeCooper; would you like to see this as a configuration option in the toml (the nixpack plan) or a command line argument?
Ideally both but start with the command line arg?
Uh... there are some issues with this unfortunately. It seems that it is not possible with the --network
build argument;
https://github.com/moby/buildkit/issues/978 https://github.com/docker/buildx/issues/175
This looks worrying for this feature to be honest. Any ideas here?
Perhaps this could be possible;
-
docker network create foonet
- Create builder
--name mybuilder \
--driver docker-container \
--driver-opt "network=foonet"
-
docker buildx use mybuilder
-
docker buildx build -t my_image .
What are your thoughts?
After tinkering a lot with it, I believe I can make this work. Here's my proposal;
When the --docker-network
option is provided (in this case my-network
);
- We create a new builder instance.
docker buildx create --name random-builder-uuid --driver docker-container --driver-opt network=my-network --use
- We create an image with this buildx instance and publish it to docker. `docker buildx b -f Dockerfile --load --no-cache
This allows the Dockerfile to fetch endpoints in the network my-network
.
This would involve some small changes to the working of nixpack, being;
- When the
--docker-network
option is provided, Nixpacks will create a builder. - It will then use that builder
- After building, it will need to reset to the previous builder
- ... and ofcouse, remove the builder instance.
This can add some complexity to Nixpacks that I can understand, you folks perhaps don't want in Nixpacks. I myself see this as an added value to Nixpacks, seeing as it might be used for applications which need to fetch some data from database containers in order to build a performant production build.
Admitted; Rust is not my primary language at all, but I feel confident that I am able to draft up a PR that;
- Implements the steps above and,
- Adds unit tests to validate the behaviour and cleanup of the builder instances.
How do you feel about this, @JakeCooper?
I've created https://github.com/railwayapp/nixpacks/pull/1119 to allow -add-host
during build time.