aws / aws/aws-codebuild-docker-images
Local Builds has problem with docker-in-docker-in-docker and source volume
- Dominant language
- Dockerfile
- Stars
- 1.2k
- Forks
- 971
- Avg merge
- 2h 47m
- Merged PRs (30d)
- 1
Description
Docker-in-Docker-in-Docker sounds like fun. I am author of the [localci](https://github.com/piotrkubisa/localci) which I unfortunately (also fortunately) developed few days before public release of AWS CodeBuild Local Builds. When I read blog post with announcement I was a bit sad but I attempted to finish it to learn how I can manage Docker containers using Golang. Thanks to it I have noticed there is the same problem I had during development `localci`.
I wanted to prepare tough test for `localci` if my `buildspec.yml` will be parsed correctly and also will properly execute CodeBuild job as it would on production server. It uses `aws/codebuild/docker:17.09.0` image and in phase there is a command to run a next Docker container (docker-in-docker-in-docker) with a shared volume to compile a Go binary ([link to example](https://github.com/piotrkubisa/localci/tree/master/_examples/aws-codebuild/sample)).
```bash
docker run --rm
-v "$(pwd)":/gopath/src/sample
-w "/gopath/src/sample"
-e "GOPATH=/gopath" \
golang:1 \
sh -c "GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-a \
-v \
-o ./app \
-ldflags \"-s -w -X main.buildVersion=${SOURCE_VERSION} -X main.buildDate=${CURRENT_DATETIME}\" \
./main.go \
"
```
Frankly, it might not be complicated for no-gophers but I wanted tough test, huh? In AWS CodeBuild Local Builds it will report following error:
```console
agent_1 | [Container] 2018/05/26 17:26:38 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: docker run --rm -v "$(pwd)":/gopath/src/${REPOSITORY_PATH} -w "/gopath/src/${REPOSITORY_PATH}" -e "GOPATH=/gopath" $DOCKER_IMAGE_GO sh -c "GOOS=linux GOARCH=amd64CGO_ENABLED=0 go build -a -v -o ./${BINARY_NAME} -ldflags \"-s -w -X main.buildVersion=${SOURCE_VERSION} -X main.buildDate=${CURRENT_DATETIME}\" $SOURCE_CODE". Reason: exit status 1
```
It seemed to me similar, because I had the same problem during development the `localci` - problem with shared volumes:
```console
agent_1 | [Container] 2018/05/26 17:29:45 Running command docker run --rm -v "$(pwd)":/gopath/src/sample -w "/gopath/src/sample" -e "GOPATH=/gopath" golang:1 sh -c ls -laGH
agent_1 |
agent_1 | [Container] 2018/05/26 17:29:46 Phase complete: BUILD Success: true
```
Empty directory on guest-guest docker? It has also shed some light on the issue. In `localci` I had to remove the docker.sock as a shared volume (https://github.com/piotrkubisa/localci/pull/2/commits/4d078748683ba01484940ed53378454a447f7c46) between host and guest docker. Then I noticed everything started working just like CodeBuild in AWS cloud.
Today, I tried to replace logic in `localci` to use AWS CodeBuild Local Builds instead of current state of art and I was also eager to try it after the announcement. Sadly, I need to move on to next project and wait for fixes. I look forward to updates in changelog related to this issue.
Contributor guide
Assessment
This issue has not been assessed yet.