openaustralia / yinyo

A wonderfully simple API driven service to reliably execute many long running scrapers in a super scaleable way
https://yinyo.io
Apache License 2.0
6 stars 1 forks source link

`make build-in-docker` assumes that $PWD is mounted into minikube vm as $PWD #7

Closed jamezpolley closed 5 years ago

jamezpolley commented 5 years ago

Second run output:

[james@bully:~/src/oaf/morph-ng/herokuish] for-morph-ng ± make build-in-docker
docker build --rm -f Dockerfile.build -t herokuish-build .
Sending build context to Docker daemon  81.92kB
Step 1/5 : FROM golang:1.12.0
 ---> cee68f119e19
Step 2/5 : ENV DEBIAN_FRONTEND noninteractive
 ---> Using cache
 ---> bdee1c547b07
Step 3/5 : RUN apt-get update -qq  && apt-get install -qq -y --force-yes      apt-transport-https      apt-utils      ca-certificates      curl      gnupg2      software-properties-common  && curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | apt-key add -  && add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") $(lsb_release -cs) stable"                                                                               
 ---> Using cache
 ---> 630f1305ac17
Step 4/5 : RUN apt-get update -qq  && apt-get install -qq -y --force-yes docker-ce=17.12.0~ce-0~debian                                                                  
 ---> Using cache
 ---> 3e8ea7c32a15
Step 5/5 : WORKDIR /src
 ---> Using cache
 ---> 54b8f0dcd657
Successfully built 54b8f0dcd657
Successfully tagged herokuish-build:latest
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro \
        -v /var/lib/docker:/var/lib/docker \
        -v /home/james/src/oaf/morph-ng/herokuish:/src/github.com/gliderlabs/herokuish -w /src/github.com/gliderlabs/herokuish \                                        
        -e IMAGE_NAME=herokuish -e BUILD_TAG=dev -e VERSION=master \
        herokuish-build make -e deps build
make: *** No rule to make target 'deps'.  Stop.
make: *** [Makefile:39: build-in-docker] Error 2
mlandauer commented 5 years ago

@jamezpolley Weird! There's a "deps" target in the Makefile, isn't there?

jamezpolley commented 5 years ago

Yeah. I think the CWD is wrong though.

mlandauer commented 5 years ago

@jamezpolley why is herokuish under a morph-ng directory? It's not checked out inside another repo is it?

jamezpolley commented 5 years ago

no, not inside another repo :)

workdir seems to be correct.. continuing to explore

jamezpolley commented 5 years ago

https://kubernetes.io/docs/setup/learning-environment/minikube/#mounted-host-folders On linux, using the Virtualbox driver, /home is mounted at /hosthome

so $PWD isn't useful.

We could do something to detect the right path to use based on the host OS ($PWD for macOS; something under /c/Users for Windows; s/home/hosthome/ for linux).

Maybe it's easier to use minikube mount ${PWD}:/src/github.com/gliderlabs/herokuish so that the Makefile can always look in a consistent location? Downside is that the minikube mount process needs to stay running..

mlandauer commented 5 years ago

I don't understand your comment at all. I don't know where $PWD is being referenced and I don't understand why the location of home is being used at all and I don't understand why minikube has anything to do with this.

jamezpolley commented 5 years ago

https://github.com/mlandauer/herokuish/blob/4778a23a76f94444523af5c63740a3540ecc593c/Makefile#L39

    docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro \
        -v /var/lib/docker:/var/lib/docker \
        -v ${PWD}:/src/github.com/gliderlabs/herokuish -w /src/github.com/gliderlabs/herokuish \
        -e IMAGE_NAME=$(IMAGE_NAME) -e BUILD_TAG=$(BUILD_TAG) -e VERSION=master \
        $(NAME)-build make -e deps build

If this was pointing at my local docker daemon, -v ${PWD}:/src/github.com/gliderlabs/herokuish would mount $PWD into the docker container as it runs.

But I've used eval $(minikube docker-env) so docker is talking to the dockerd inside the VirtualBox VM that minikube created.

On Mac, /Users on the host is mounted as /Users inside the minikube VM, so this still works, because when make on the host runs $PWD it expands to a path that the dockerd inside the minikube VM can read.

On Linux, /home on the host is mounted to /hosthome on the VM. -v /hosthome/james/src/oaf/morph-ng/herokuish:/src/github.com/gliderlabs/herokuish would work, but -v /home/james/src/oaf/morph-ng/herokuish:/src/github.com/gliderlabs/herokuish doesn't.

mlandauer commented 5 years ago

Ah gotcha. Thanks for the explanation! Well that's a pain isn't it. Would this be solved by converting the "build-in-docker" to a multi-stage build Dockerfile instead?

jamezpolley commented 5 years ago

I don't think so - you'd still need to map to the correct path inside the minikube vm, and that varies for different OS/driver combinations.

I think I can work around it with something like minikube start --mount --mount-string $HOME:$HOME. Testing that now.

jamezpolley commented 5 years ago

Yep, that works; see #8