woodpecker-ci / woodpecker

Woodpecker is a simple, yet powerful CI/CD engine with great extensibility.
https://woodpecker-ci.org
Apache License 2.0
4.24k stars 368 forks source link

Add option for pipeline to use custom network #813

Closed gbrlsnchs closed 2 years ago

gbrlsnchs commented 2 years ago

Clear and concise description of the problem

Currently, I'm trying to make Woodpecker work with Gitea, both locally, using Docker Compose.

I've set both server and agent, along with Gitea, to use a custom Docker network under the 10.0.0.0/8 subnet.

The issue lies when running a pipeline: containers from pipelines can't reach that custom network, so they fail when trying to clone the repository from Gitea.

Suggested solution

In Drone CI, it is possible to set DRONE_RUNNER_NETWORKS, so pipelines are able to use custom networks. Woodpecker CI could add an environment variable for that as well.

Alternative

N/A

Additional context

Docs for DRONE_RUNNER_NETWORKS: https://docs.drone.io/runner/docker/configuration/reference/drone-runner-networks/ The docker-compose.yml file for running Gitea and Woodpecker locally: https://codeberg.org/gbrlsnchs/void-pkgs/src/branch/trunk/docker-compose.yml

Validations

xseman commented 2 years ago

I struggle with the same problem, my motivation to combine these services into one docker-compose is to simplify local testing. As @gbrlsnchs mentioned, the DRONE_RUNNER_NETWORKS would be very helpful.

anbraten commented 2 years ago

For developing I currently solve this by adding this line to Exec in pipeline/backend/docker/docker.go:

e.client.NetworkConnect(ctx, "my_custom_network", proc.Name, &network.EndpointSettings{})

We could add it as you two wrote by some env variable like: `WOODPECKER_DOCKER_NETWORKS to the agent.

xseman commented 2 years ago

For developing I currently solve this by adding this line to Exec in pipeline/backend/docker/docker.go:

e.client.NetworkConnect(ctx, "my_custom_network", proc.Name, &network.EndpointSettings{})

Would that inject the network name to runners as well? Thanks!

edit: Thanks, it worked, I had to add it before return.