Drone docker agents on custom network?


#1

Hi, I have a Gitea and drone setup running on my localhost. When drone launches an agent to run the build, the agent is put on a different Docker network to the Gitea instance so I get the error:

fatal: unable to access 'http://gitea:3000/<username>/<some repo>/': Could not resolve host: gitea

In my docker-compose.yml I have two docker networks: gitea_net and gitea_drone. Gitea is connected to both with Gitea’s database running only on gitea_net. The Drone instance is only connected to gitea_drone.

Is there a way to tell Drone to stick agents on gitea_drone?

Note: I would love for this to all run internally via docker as I don’t have the means to setup a static IP or custom DNS server on my network.

Compose file:

version: '2'
services:
  gitea:
    image: gitea/gitea
    restart: always
    networks:
      gitea_net:
      gitea_drone:
    volumes:
      - /srv/gitea/data:/data
    ports:
      - "3000:3000"
      - "2223:22"
    depends_on:
      - db
    environment:
      - SSH_PORT=2223
      - SSH_LISTEN_PORT=22
      - ROOT_URL=http://gitea:3000
  db:
    image: mariadb:10
    restart: always
    networks:
      gitea_net:
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=gitea
      - MYSQL_USER=gitea
      - MYSQL_PASSWORD=gitea
    volumes:
      - /srv/gitea/db:/var/lib/mysql
  drone:
    image: drone/drone:1.0.0-rc.5
    restart: always
    depends_on:
      - gitea
    networks:
      gitea_drone:
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /srv/gitea/drone:/data
    environment:
      - DRONE_GITEA_SERVER=http://gitea:3000
      - DRONE_GIT_ALWAYS_AUTH=false
      - DRONE_RUNNER_CAPACITY=2
      - DRONE_SERVER_HOST=drone
      - DRONE_SERVER_PROTO=http
      - DRONE_TLS_AUTOCERT=false
    ports:
      - "3001:80"
      - "3002:443"
networks:
  gitea_net:
  gitea_drone:

test pipline:

kind: pipeline
name: default

steps:
  - name: gitea_release
    image: plugins/gitea-release
    settings:
      api_key:
        from_secret: API_KEY
        base_url: http://web:3000
        files: test.txt
    when:
      event: tag

#2

you can set DRONE_RUNNER_NETWROKS=<network> which will attach all pipeline containers to your specified network.


#3

Perfect, just what I needed. The option isn’t mentioned in the docs as far as I can see.

The only downside is that the network name needs to be full name including the name of the stack inside the compose yml, so in my case gitea_gitea_drone Instead of just gitea_drone which is somewhat unfortunate.

Is there a way to fix this?


#4

Is there a way to fix this?

I believe docker compose allows you to override networks names, however, this is outside my area of expertise.


#5

I believe docker compose allows you to override networks names, however, this is outside my area of expertise.

That is a good point, perhaps using an existing docker network would be better in this case. At least then the network name would have already been defined instead of leaving docker-compose to create it.

From the docs: https://docs.docker.com/compose/networking/#use-a-pre-existing-network

networks:
  default:
    external:
      name: my-pre-existing-network