gliderlabs / logspout

Log routing for Docker container logs
MIT License
4.66k stars 680 forks source link

./build.sh: Permission denied #238

Closed nikki603 closed 7 years ago

nikki603 commented 8 years ago

Environment:

I had the missing gcc error and did the workaround of using gliderlabs/logspout:master and putting a copy of build.sh in my local directory. Now when I try to build, I get an error of ./build.sh: Permission denied. You can see full build log at https://hub.docker.com/r/nikki603/logspoutkinesis/builds/bchksm9an3agrmdxavr5o78/

I get the same error when running docker-compose locally.

docker-compose build logspout
Building logspout
Step 1 : FROM gliderlabs/logspout:master
# Executing 3 build triggers...
Step 1 : COPY ./build.sh /src/build.sh
Step 1 : COPY ./modules.go /src/modules.go
Step 1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom"
 ---> Running in 48852ae2f7b1
/bin/sh: ./build.sh: Permission denied
ERROR: Service 'logspout' failed to build: The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126

build.sh file permission locally are -rwxr-xr-x

I believe this is related to bug https://github.com/docker/compose/issues/3716

christianbundy commented 8 years ago

Yep, this will be resolved in Docker Compose 1.9.0. until then you'll need to add RUN chmod +x /src/build.sh to your Dockerfile.

anisimovsergey commented 7 years ago

Can RUN chmod +x /src/build.sh really help? A docker build executes ONBUILD commands before any command in a child Dockerfile. Therefore, ONBUILD RUN cd /src && ./build.sh "$(cat VERSION)-custom" will be executed before RUN chmod +x /src/build.sh.

I've got the same issue but in my case I build my custom image in a build pipeline and when the build agent (GOCD) pulls the files to build a custom logspout, build.sh has the following attributes -rw-r--r--. 1 go docker 417 Nov 11 11:12 build.sh and docker build fails with the same error.

I believe that RUN chmod +x /src/build.sh should be in logspout's Dockerfile.

christianbundy commented 7 years ago

@anisimovsergey What version of docker-compose are you using? This should be fixed in 1.9.0.

anisimovsergey commented 7 years ago

I'm not using docker-compose at all, a simple docker build is failing if you develop on Windows and build on Linux roudtriping your code through a Git server (in my case it's even worse, it's Microsoft's TFS Git) because the file permissions are different. There is no way to specify +x permission on Windows 7. Moreover, I don't think it's guaranteed by git spec to preserve the file permissions at all, it just happens that GitHub supports it for the Linux-to-Linux workflow. Please correct me if I'm wrong.

christianbundy commented 7 years ago

@anisimovsergey Which version of Git are you using? The executable bit is synthesized, meaning that when you're using Windows to build an image, Docker will chmod +x on each of the files being added to the image. This was resolved in https://github.com/docker/docker/pull/11148 for Docker, and https://github.com/docker/docker-py/pull/1228 for docker-py (which runs docker-compose and friends).

anisimovsergey commented 7 years ago

The Git version I'm using on Windows is "Git for Windows 2.8.1". I'm using windows git and building my Docker images on a Virtual Box VM with Ubuntu 14.04.5. All my files in a mapped folder from windows have permissions: -rwxrwxrwx and all the folders: drwxrwxrwx because Virtual Box doesn't know about the real permissions it falls back with enabling everything. Docker version I'm using for building in the VM is: 1.11.2 I can build my image successfully in this environment using logspout's original docker image, no problem at all.

However, on my build agent which is running on CentOS 7.2, I'm using Git client 1.8.3.1 and docker version 1.12.3. When my build agent pulls the repository with build.sh it has -rw-r--r-- permissions and the subsequent build fails with:

17:53:38.032 Step 1 : COPY ./build.sh /src/build.sh
17:53:38.033 Step 1 : COPY ./modules.go /src/modules.go
17:53:38.033 Step 1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom"
17:53:38.033  ---> Running in 0ac0f8ce2106
17:53:38.033 /bin/sh: ./build.sh: Permission denied

I have a workaround but I would rather prefer using the original logspout's Dockerfile.

josegonzalez commented 7 years ago

Can you change that line to chmod +x and then the execution?

anisimovsergey commented 7 years ago

No I can't, because those lines are from the logspout's Dockerfile

ONBUILD COPY ./build.sh /src/build.sh ONBUILD COPY ./modules.go /src/modules.go ONBUILD RUN cd /src && ./build.sh "$(cat VERSION)-custom"

Nether can I do RUN chmod +x /src/build.sh in my Dockerfile because ONBUILD commands are executed before the commands in the inherited Dockerfile (mine).

josegonzalez commented 7 years ago

Would this fix it?

ONBUILD RUN cd /src && chmod +x build.sh && ./build.sh "$(cat VERSION)-custom"
anisimovsergey commented 7 years ago

@josegonzalez Yes, indeed, the proposed change should fix the problem.

stour commented 7 years ago

I'm getting the same error and that prevents me from running my custom logspout image. @josegonzalez: Any plan to apply the suggested fix in logspout's Dockerfile ?

trondvh commented 6 years ago

This issue was reintroduced in ae888cca7f4b9009079e84139fe18ff0c6f89d12? @michaelshobbs

josegonzalez commented 6 years ago

@trondvh can you file a new issue with the full output of the issue you are seeing?

djeeg commented 6 years ago

Same, am getting this issue again

As @trondvh says, the previous fix, "&& chmod +x build.sh", looks like it was removed from the Dockerfile as part of recent update

Is it not needed anymore?

christianbundy commented 6 years ago

@djeeg Can you post more info about your environment (e.g. your Docker version)?

michaelshobbs commented 6 years ago

I checked the file in with the executable bit set and I just verified that a new clone of the repo shows that it's executable. Not sure why you're still seeing this issue. Feel free to open a PR to bring back the chmod cmd if needed.

djeeg commented 6 years ago

Note: this works when I build the image locally using [Windows host + hyper-V + docker-machine + boot2docker + docker 17.11.0]

It doesn't work if I build the image in the cloud using [Visual Studio Online + GIT repository]

Project structure is standard directory: logspout

Dockerfile has FROM gliderlabs/logspout:master

modules.go has "github.com/looplab/logspout-logstash"

When triggering a build in VSTS, this happens (other images in VSTS are building okay)

2017-11-30T11:11:33.5307250Z ##[section]Starting: Build an image 2017-11-30T11:11:33.5602790Z ============================================================================== 2017-11-30T11:11:33.5618200Z Task : Docker 2017-11-30T11:11:33.5633410Z Description : Build, tag, push, or run Docker images, or run a Docker command. Task can be used with Docker or Azure Container registry. 2017-11-30T11:11:33.5647590Z Version : 0.3.2 2017-11-30T11:11:33.5661550Z Author : Microsoft Corporation 2017-11-30T11:11:33.5675660Z Help : More Information 2017-11-30T11:11:33.5690690Z ============================================================================== 2017-11-30T11:11:36.6498410Z Sending build context to Docker daemon 6.144kB 2017-11-30T11:11:36.6507080Z 2017-11-30T11:11:36.6969280Z Step 1/2 : FROM gliderlabs/logspout:master 2017-11-30T11:11:37.1598370Z master: Pulling from gliderlabs/logspout 2017-11-30T11:11:37.1627880Z b56ae66c2937: Pulling fs layer 2017-11-30T11:11:37.1744340Z 08ba3ad758a2: Pulling fs layer 2017-11-30T11:11:37.1761370Z 6ede64ba6796: Pulling fs layer 2017-11-30T11:11:37.3392110Z 08ba3ad758a2: Verifying Checksum 2017-11-30T11:11:37.3414840Z 08ba3ad758a2: Download complete 2017-11-30T11:11:37.3632530Z b56ae66c2937: Verifying Checksum 2017-11-30T11:11:37.3647590Z b56ae66c2937: Download complete 2017-11-30T11:11:37.4137140Z 6ede64ba6796: Verifying Checksum 2017-11-30T11:11:37.4153800Z 6ede64ba6796: Download complete 2017-11-30T11:11:37.6433240Z b56ae66c2937: Pull complete 2017-11-30T11:11:37.7559270Z 08ba3ad758a2: Pull complete 2017-11-30T11:11:38.1644620Z 6ede64ba6796: Pull complete 2017-11-30T11:11:38.1897650Z Digest: sha256:bdd052e42ff519202b8c4e4be11f4803803118dc4ecfa41970c573afecf90ac6 2017-11-30T11:11:38.2152390Z Status: Downloaded newer image for gliderlabs/logspout:master 2017-11-30T11:11:38.2179230Z # Executing 3 build triggers... 2017-11-30T11:11:38.2238690Z Step 1/1 : COPY ./build.sh /src/build.sh 2017-11-30T11:11:38.5869930Z Step 1/1 : COPY ./modules.go /src/modules.go 2017-11-30T11:11:38.9167170Z Step 1/1 : RUN cd /src && ./build.sh "$(cat VERSION)-custom" 2017-11-30T11:11:39.0152290Z ---> Running in 2ff187d235ae 2017-11-30T11:11:39.3676710Z /bin/sh: ./build.sh: Permission denied 2017-11-30T11:11:39.6158700Z The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126 2017-11-30T11:11:39.6340170Z ##[error]The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126 2017-11-30T11:11:39.6404080Z ##[error]/usr/bin/docker failed with return code: 126

michaelshobbs commented 6 years ago

are you copying build.sh from the root of this repo or is that your own script? either way chmod +x that bad boy and all should be good...i think

trondvh commented 6 years ago

The same for me, building a custom image with gitlab-ci:

Running with gitlab-runner 10.2.0 (0a75cdd1)
  on Docker Runner docker-in-docker 02-3 (vmgir02it) (a0f863e8)
Using Docker executor with image docker:latest ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image docker:dind ID=sha256:2b5312e84355e6e50dd36c61663df237e8f0431f5af003710a7b3d10cd73b6bc for docker service...
Waiting for services to be up and running...
Using docker image sha256:ddaf92ee2c588ceab09a84852e72d0d532164a8efdef915717f5b479eedad79a for predefined container...
Pulling docker image docker:latest ...
Using docker image docker:latest ID=sha256:97e854a6493aedda8bf6e7f0dc256135cb4dbe525d2186655cb45368a42cab9c for build container...
Running on runner-a0f863e8-project-335-concurrent-0 via vmgir02it...
Cloning repository...
Cloning into '/builds/devops/dockers/docker-logspout-kafka'...
Checking out 24a10d3f as master...
Skipping Git submodules setup
$ docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
$ docker build --pull -t "$CI_REGISTRY_IMAGE" .
Sending build context to Docker daemon  36.35kB

Step 1/4 : FROM gliderlabs/logspout:v3.2.3
v3.2.3: Pulling from gliderlabs/logspout
019300c8a437: Pulling fs layer
1b19e7c0b70f: Pulling fs layer
93ff2b51dfee: Pulling fs layer
1b19e7c0b70f: Verifying Checksum
1b19e7c0b70f: Download complete
019300c8a437: Verifying Checksum
019300c8a437: Download complete
93ff2b51dfee: Verifying Checksum
93ff2b51dfee: Download complete
019300c8a437: Pull complete
1b19e7c0b70f: Pull complete
93ff2b51dfee: Pull complete
Digest: sha256:a18d697fbc797d541a45c26c53a855febe0af25728fbc32e77d1e0532af58f1d
Status: Downloaded newer image for gliderlabs/logspout:v3.2.3
# Executing 3 build triggers
 ---> Running in ba8409efd963
/bin/sh: ./build.sh: Permission denied
The command '/bin/sh -c cd /src && ./build.sh "$(cat VERSION)-custom"' returned a non-zero code: 126
ERROR: Job failed: exit code 126

As you are using ONBUILD in the base file, I don't believe that a chmod in the downstream Dockerfile will help, as build.sh is executed by ONBUILD in the base file.

michaelshobbs commented 6 years ago

I don't think I follow what you're saying. It doesn't matter which dockerfile calls the script as long as the script itself is executable in current docker build context. That being said, I will gladly accept a PR that brings back the RUN chmod +x directive.

djeeg commented 6 years ago

Looks fixed, thanks for merging!

... Status: Downloaded newer image for gliderlabs/logspout:master [91m# Executing 3 build triggers... [0mStep 1/1 : COPY ./build.sh /src/build.sh Step 1/1 : COPY ./modules.go /src/modules.go Step 1/1 : RUN cd /src && chmod +x ./build.sh && ./build.sh "$(cat VERSION)-custom" ---> Running in 8ef1c975d884 Starting ... fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz (1/49) Installing fakeroot (1.21-r1) (2/49) Installing sudo (1.8.21_p2-r1) (3/49) Installing libcap (2.25-r1) ...