Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to set Docker network and custom hosts during build #1057

Open
andrasbacsai opened this issue Jan 28, 2024 · 7 comments
Open

Able to set Docker network and custom hosts during build #1057

andrasbacsai opened this issue Jan 28, 2024 · 7 comments

Comments

@andrasbacsai
Copy link

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.

@JakeCooper
Copy link
Contributor

Would defs take a PR for this!

@Thijmen
Copy link
Contributor

Thijmen commented Jun 11, 2024

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 😄

@Thijmen
Copy link
Contributor

Thijmen commented Jun 11, 2024

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?

@JakeCooper
Copy link
Contributor

Ideally both but start with the command line arg?

@Thijmen
Copy link
Contributor

Thijmen commented Jun 11, 2024

Uh... there are some issues with this unfortunately. It seems that it is not possible with the --network build argument;

moby/buildkit#978
docker/buildx#175

This looks worrying for this feature to be honest. Any ideas here?


Perhaps this could be possible;

  1. docker network create foonet
  2. Create builder
  --name mybuilder \
  --driver docker-container \
  --driver-opt "network=foonet"
  1. docker buildx use mybuilder
  2. docker buildx build -t my_image .

What are your thoughts?

@Thijmen
Copy link
Contributor

Thijmen commented Jun 12, 2024

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);

  1. We create a new builder instance.
    docker buildx create --name random-builder-uuid --driver docker-container --driver-opt network=my-network --use
  2. 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;

  1. When the --docker-network option is provided, Nixpacks will create a builder.
  2. It will then use that builder
  3. After building, it will need to reset to the previous builder
  4. ... 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;

  1. Implements the steps above and,
  2. Adds unit tests to validate the behaviour and cleanup of the builder instances.

How do you feel about this, @JakeCooper?

@Thijmen
Copy link
Contributor

Thijmen commented Jun 14, 2024

I've created #1119 to allow -add-host during build time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants