我在docker中的机器上运行-编写以下内容:

  • gitlab
  • 无人机(服务器)
  • 无人机(代理)

  • 当我触发构建(或由git push触发)时,无人机继续在该问题上失败:
    git init
    Initialized empty Git repository in /drone/src/.git/
    git remote add origin http://my-git/amaziagur/location-service.git
    git fetch --no-tags origin +refs/heads/master:
    fatal: unable to access 'http://my-git/amaziagur/location-service.git/': Couldn't resolve host 'my-git'
    exit status 128
    

    这是docker-compose.yml:
    version: '2'
    services:
      #PROXY
      gitlab:
        image: 'gitlab/gitlab-ce:9.1.0-ce.0'
        restart: always
        hostname: 'my-git'
        links:
          - postgresql:postgresql
          - redis:redis
        environment:
          GITLAB_OMNIBUS_CONFIG: |
            postgresql['enable'] = false
            gitlab_rails['db_username'] = "gitlab"
            gitlab_rails['db_password'] = "gitlab"
            gitlab_rails['db_host'] = "postgresql"
            gitlab_rails['db_port'] = "5432"
            gitlab_rails['db_database'] = "gitlabhq_production"
            gitlab_rails['db_adapter'] = 'postgresql'
            gitlab_rails['db_encoding'] = 'utf8'
            redis['enable'] = false
            gitlab_rails['redis_host'] = 'redis'
            gitlab_rails['redis_port'] = '6379'
            external_url 'http://my-git'
            gitlab_rails['gitlab_shell_ssh_port'] = 30022
        ports:
          # both ports must match the port from external_url above
          - "80:80"
          # the mapped port must match ssh_port specified above.
          - "30022:22"
      # the following are hints on what volumes to mount if you want to persist data
        volumes:
         - /data/gitlab/config:/etc/gitlab:rw
         - /data/gitlab/logs:/var/log/gitlab:rw
         - /data/gitlab/data:/var/opt/gitlab:rw
    
      postgresql:
        restart: always
        image: postgres:9.6.2-alpine
        environment:
          - POSTGRES_USER=gitlab
          - POSTGRES_PASSWORD=gitlab
          - POSTGRES_DB=gitlabhq_production
      # the following are hints on what volumes to mount if you want to persist data
        volumes:
         - /home/foresight/postgresql:/var/lib/postgresql:rw
    
      redis:
        restart: always
        image: redis:3.0.7-alpine
      # DRONE
      drone-server:
        image: drone/drone:0.7.3
        ports:
          - "8000:8000"
        networks:
          - drone
          - gitlab
        links:
         - gitlab
        volumes:
          - /home/drone:/var/lib/drone/
        environment:
          #@@@@@
          DRONE_OPEN: "true"
          DRONE_HOST: "http://10.0.0.200:8000"
          DRONE_ADMIN: amaziagur
          DRONE_GITLAB: "true"
          DRONE_GITLAB_URL: "http://10.0.0.200"
          DRONE_GITLAB_CLIENT: "secret"
          DRONE_GITLAB_SECRET: "secret"
          DRONE_SECRET: "my_secret"
          #@@@@@@@
      drone-agent:
        image: drone/drone:0.7.3
        command: agent
        depends_on:
          - drone-server
        networks:
          - drone
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
        environment:
          DRONE_SERVER: ws://drone-server:8000/ws/broker
          DRONE_DEBUG: "true"
          DRONE_SECRET: "our_secret_4ever_and_ever"
    
    networks:
      drone:
        driver: bridge
      gitlab:
        driver: bridge
    

    两者都安装在同一台机器上,我无法弄清楚我在做什么错,这是无人机始终无法识别git主机的原因。

    我已经在本地的/ etc / hosts以及在网上找到的/etc/resolve.conf提示中添加了映射。
    有人可以帮忙吗?

    最佳答案

    TL; DR

    主要原因是因为实际的克隆步骤是由特定的独立docker容器驱动的,即在其自己的docker网络中。因此,它无法解析名称my-git,即使它能够解析它,也无法找到它。

    预期的解决方法失败:

    首先,您会注意到您的错误是与解决my-git有关。必须在实际进行克隆的docker git容器实例上解决此,而不是在其他任何地方。这意味着修改此Docker实例的/etc/hosts。这可以在.drone.yml中完成,方法是替换您的克隆步骤,并使用docker-composeextra_hosts功能(cf docs)。这是这样做的:

    kind: pipeline
    name: default
    
    clone:
      disable: true
    
    steps:
    - name: myclone
      image: docker:git
      ## If you wanted to solve resolving part
      extra_hosts:
        - "my-git:10.0.0.200"
      ## Alas this will also be needed, and is NOT supported yet
      # networks:
      #  - gitlab
      commands:
        ## this will show you if ``my-git`` is resolved.
        - ping -c 1 my-git
        - git clone http://my-git/amaziagur/location-service.git/
    
    ##
    ## ... your normal steps follows ...
    ##
    
    

    ,如果您的容器现在可以将my-git解析为实际IP,则它仍将无法访问,因为它是在未连接到另一个的自定义网络中生成的。

    为此,我们还需要能够指定Docker实例应该连接到的网络,这通常是通过networks中的docker-compose键完成的(您可以在docker-compose reference about specifying custom networks中检查)。

    las,目前drone不支持此功能,并且是this issue当前跟踪的错误。截至撰写本文时,即使在1.0.0-rc.5中,该问题仍未解决。

    请注意,如果networks键可以按预期工作,则extra_hosts将是多余的。

    09-27 07:45