xsteadfastx
(Marvin Steadfast)
November 28, 2018, 9:21am
1
See also Build Docker image and re-use in the next step
im using a specific image for testing my python code. and i want ti build a fresh image on every build without uploading it to a registry all the time. so i thought if i build it, tag it, it will be available to the agent. but doesnt seem to be the case. does the agent use a own docker daemon? why it doesnt seem local images?
here is my .drone.yml
kind: pipeline
name: default
steps:
- name: build test image
image: docker:latest
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker build --no-cache -t cookiecutter-python-tests -f Dockerfile.tests .
- name: py36
image: cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py36
- name: py37
image: cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py37
- name: flake8
image: cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e flake8
- name: pylint
image: cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e pylint
- name: black
image: cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e black-only-check
volumes:
- name: docker_sock
host:
path: /var/run/docker.sock
the building works fine⦠but the agent cant find the image⦠i get this error:
Error response from daemon: pull access denied for cookiecutter-python-tests, repository does not exist or may require ādocker loginā
1 Like
xsteadfastx
(Marvin Steadfast)
November 28, 2018, 9:45am
2
i forget to say⦠everything else works. the agent is started with /var/run/docker.sock volume⦠i just dont know why the image cant be found.
flah00
(Philip Champon)
November 28, 2018, 5:40pm
3
Perhaps drone is trying to pull the image from docker.io by default. Have you tried pushing the image to a docker.io repo and redefining your images to match new image path?
steps:
- name: build test image
image: docker:latest
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker build --no-cache -t ORG/cookiecutter-python-tests -f Dockerfile.tests .
- docker push ORG/cookiecutter-python-tests:latest
- name: py36
image: ORG/cookiecutter-python-tests:latest
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py36
...
xsteadfastx
(Marvin Steadfast)
November 29, 2018, 9:58am
4
i think i found a way that this works⦠even if i dont know why it does
kind: pipeline
name: default
steps:
- name: build test image
image: docker:latest
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker build --no-cache -t cookiecutter-python-tests:${DRONE_COMMIT} -f Dockerfile.tests .
- name: py36
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py36
i set a own tag aka the DRONE_COMMIT hash. and then it works. no idea why its like this.
Raffo
(Raffaele Di Fazio)
November 29, 2018, 2:25pm
5
It works because you are mounting the docker socket, thus the image is already present locally.
flah00
(Philip Champon)
November 29, 2018, 3:48pm
6
@Raffo
Perhaps Iāve missed something, but it seems to me that @xsteadfastx posted two versions, both mounted the socket. The working version used an env var (DRONE_COMMIT
) to tag the image. As he said, that seems to be the reason it suddenly works.
Does drone allow steps to be executed on different agents?
Raffo
(Raffaele Di Fazio)
November 29, 2018, 10:36pm
7
Iām unsure why it works actually, the ālatestā tag should also work as itās no different from the other tag.
xsteadfastx
(Marvin Steadfast)
December 1, 2018, 11:57am
8
it doesnt work with latest. i posted two version. i shortened it⦠here is the full one:
kind: pipeline
name: default
steps:
- name: build test image
image: docker:latest
volumes:
- name: docker_sock
path: /var/run/docker.sock
commands:
- docker build --no-cache -t cookiecutter-python-tests:${DRONE_COMMIT} -f Dockerfile.tests .
- name: py36
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py36
- name: py37
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py37
- name: flake8
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e flake8
- name: pylint
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e pylint
- name: black
image: cookiecutter-python-tests:${DRONE_COMMIT}
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e black-only-check
volumes:
- name: docker_sock
host:
path: /var/run/docker.sock
and the whole difference was the docker image tag. with latest
i dont get it working.
this is because drone behaves the same way as kubernetes, and will always try to pull the latest
tag from the registry. In your case, this results in your cached latest
tag being replaced with the image from the remote registry. If you do not desire this behavior, you can override the default pull behavior like this:
- name: py36
image: cookiecutter-python-tests:latest
+ pull: if-not-exists
environment:
TOX_WORK_DIR: /tmp/tox
commands:
- tox -e py36
See also Build Docker image and re-use in the next step
3 Likes
xsteadfastx
(Marvin Steadfast)
December 4, 2018, 12:12pm
10
this is great. thanks for the answer. that explains it well.