AlphaDu
AlphaDu

Reputation: 81

How can I pass a external environment variable to drone docker runner?

The scene is: I want to exec docker run & push in docker runner, and the docker registry and docker runner is in same server. so I want to pass host ip as variable into drone pipeline container so I can push docker image without a remote registry server. But it seem that only drone allowable environment variable can be used in ‘${}’. I try to export EXTERNALIP in host machine and try to get ${EXTERNALIP} but got nothing. so Is there some way I can get external ip for communicating to localhost or another way to achieve this?

Upvotes: 2

Views: 4280

Answers (1)

hikerspath
hikerspath

Reputation: 106

You should be able to push to localhost if its on the same host, that said, I was not able to do this using the packages plugin but was able to to replicate using direct docker:

steps:
- name: docker-${DRONE_EVENT}
  image: docker:19.03
  when:
    event: [ push, pull_request ]
    status: [ success ]
  environment:
    DOCKER_PASSWORD:
      from_secret: docker_password
  commands:
    - echo $DOCKER_PASSWORD | docker login --username user_name --password-stdin localhost
    - docker build -t localhost/demo-web:latest .
    - if [ "${DRONE_EVENT}" == "push" ]; then docker push localhost/demo-web:latest; fi;
  volumes:
    - name: docker-socket
      path: /var/run/docker.sock

volumes:
- name: docker-socket
  host:
    path:
      /var/run/docker.sock

Couple caveats, obviously you will need to have trusted access in the repo configuration or --trusted if using local exec. Enjoy!

Upvotes: 3

Related Questions