# Mender-artifact Docker build (make build-contained) fails

**URL:** <https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051>\
**Category:** General Discussions\
**Tags:** mender-artifact\
**Created:** [September 20, 2019, 6:41pm UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051 "2019-09-20T18:41:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stadicus](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/stadicus/32/362_2.png) [@Stadicus](https://hub.mender.io/u/Stadicus)\
**Post date:** [September 20, 2019, 6:41pm UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/1 "2019-09-20T18:41:45Z")

</div>

Building the `mender-artifact` is straight-forward:

- Install and configure Docker
- Clone repository from [https://github.com/mendersoftware/mender-artifact](https://github.com/mendersoftware/mender-artifact)
- Run `make build-contained`

This build fails, however, as within the Docker container the `mender-artifact` binary is not created in `/go/bin/` but in `/go/src/github.com/mendersoftware/mender-artifact`. Thus, the final command of the `Makefile` fails:

```
$ sudo make build-contained
rm -f mender-artifact && \
image_id=$(docker build -f Dockerfile . | awk '/Successfully built/{print $NF;}') && \
docker run --rm --entrypoint "/bin/sh" -v /mnt/hdd/github/bitbox-base-signing/mender-artifact:/binary $image_id -c "cp /go/bin/mender-artifact /binary" && \
docker image rm $image_id
cp: cannot stat '/go/bin/mender-artifact': No such file or directory
Makefile:62: recipe for target 'build-contained' failed
make: *** [build-contained] Error 1

```

Changing the `cp` command [in this line](https://github.com/mendersoftware/mender-artifact/blob/e88b02ca6e75b1a8f3953c68e7d153f020ec32aa/Makefile#L64) within `Makefile` to the following, everything works out fine.

```
build-contained:
    rm -f mender-artifact && \
    image_id=$$(docker build -f Dockerfile . | awk '/Successfully built/{print $$NF;}') && \
    docker run --rm --entrypoint "/bin/sh" -v $(shell pwd):/binary $$image_id -c "cp /go/src/github.com/mendersoftware/mender-artifact/mender-artifact /binary" && \
    docker image rm $$image_id

```

Am I missing something and this hack is not necessary? Or did nobody report that just yet?

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [September 23, 2019, 6:51am UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/2 "2019-09-23T06:51:18Z")

</div>

Looks like this has been overlooked indeed. We would appreciate a pull  
request!

---

<div class="post-metadata">

**Author:** ![kacf](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/kacf/32/146_2.png) [@kacf](https://hub.mender.io/u/kacf)\
**Post date:** [September 23, 2019, 9:34am UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/3 "2019-09-23T09:34:21Z")

</div>

Hold on, there is something weird going on here. This has suddenly  
started failing on our end too. But nothing has changed in  
mender-artifact, so what happened…?

We will be investigating this.

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 23, 2019, 11:43am UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/4 "2019-09-23T11:43:59Z")

</div>

Hello @Stadicus and thanks for reporting!

We just merged fix for this, see [mender-artifact PR #220](https://github.com/mendersoftware/mender-artifact/pull/220). If you are using master, you should be able to do `git pull` and retry the build.

See the PR changes for details.

---

<div class="post-metadata">

**Author:** ![Stadicus](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/stadicus/32/362_2.png) [@Stadicus](https://hub.mender.io/u/Stadicus)\
**Post date:** [September 23, 2019, 2:03pm UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/5 "2019-09-23T14:03:29Z")

</div>

Hej Lluis, just cloned master from scratch, but I still get the same issue:

```auto
$ sudo make build-contained

rm -f mender-artifact && \
image_id=$(docker build -f Dockerfile . | awk '/Successfully built/{print $NF;}') && \
docker run --rm --entrypoint "/bin/sh" -v /mnt/hdd/github/mender-artifact:/binary $image_id -c "cp /go/bin/mender-artifact /binary" && \
docker image rm $image_id
cp: cannot stat '/go/bin/mender-artifact': No such file or directory
Makefile:62: recipe for target 'build-contained' failed
make: *** [build-contained] Error 1

```

Breaking this down, here are the individual commands:

```auto
$ sudo docker build -f Dockerfile .

Sending build context to Docker daemon 11.24MB
Step 1/7 : FROM golang:1.11 as builder
 ---> 43a154fee764
Step 2/7 : RUN apt-get update && apt-get install -qyy liblzma-dev
 ---> Using cache
 ---> 68f45b8c31ae
Step 3/7 : RUN mkdir -p /go/src/github.com/mendersoftware/mender-artifact
 ---> Using cache
 ---> d337706800c9
Step 4/7 : WORKDIR /go/src/github.com/mendersoftware/mender-artifact
 ---> Using cache
 ---> 59cf5beb6c57
Step 5/7 : ADD ./ .
 ---> 361efd2c0875
Step 6/7 : RUN make build
 ---> Running in 0dd4ee5507e2
go build -ldflags "-X main.Version=3b729b4" -o mender-artifact cli/mender-artifact/artifacts.go cli/mender-artifact/copy.go cli/mender-artifact/log.go cli/mender-artifact/debugfs.go cli/mender-artifact/main.go cli/mender-artifact/partition.go cli/mender-artifact/sign.go cli/mender-artifact/read.go cli/mender-artifact/validate.go cli/mender-artifact/modify.go cli/mender-artifact/write.go cli/mender-artifact/dump.go
Removing intermediate container 0dd4ee5507e2
 ---> d09d6ff3e245
Step 7/7 : ENTRYPOINT ["/go/src/github.com/mendersoftware/mender-artifact/mender-artifact"]
 ---> Running in 13b6e54b5ed7
Removing intermediate container 13b6e54b5ed7
 ---> 11fdc9c62876
Successfully built 11fdc9c62876

$ sudo docker run --rm --entrypoint "/bin/sh" -v $(pwd):/binary 11fdc9c62876 -c "cp /go/bin/mender-artifact /binary"
cp: cannot stat '/go/bin/mender-artifact': No such file or directory

$ sudo docker run --rm --entrypoint "/bin/sh" -v $(pwd):/binary 11fdc9c62876 -c "cp /go/src/github.com/mendersoftware/mender-artifact/mender-artifact /binary"

```

The last command works and copies the `mender-convert` binary into the current directory. (note: I had to adapt `$(shell pwd)` to `$(pwd)` due to my use of zsh)

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 23, 2019, 2:40pm UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/6 "2019-09-23T14:40:03Z")

</div>

Hi again!

Thanks for reporting back.

My bad, I miss-read your original report. I thought that you were affected by an error we saw this morning in our build system related to `build-natives-contained` target, not `build-contained` target as you actually reported. Funny that it is an independent error with a very similar error message…

Anyway, I fixed now your issue and launched this new [mender-artifact PR #222](https://github.com/mendersoftware/mender-artifact/pull/222). It will be merged into master soon.

---

<div class="post-metadata">

**Author:** ![lluiscampos](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/lluiscampos/32/112_2.png) [@lluiscampos](https://hub.mender.io/u/lluiscampos)\
**Post date:** [September 23, 2019, 3:01pm UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/7 "2019-09-23T15:01:22Z")

</div>

Merged now.

@Stadicus please update and let me know if your issue was finally resolved.

---

<div class="post-metadata">

**Author:** ![Stadicus](https://yyz2.discourse-cdn.com/flex036/user_avatar/hub.mender.io/stadicus/32/362_2.png) [@Stadicus](https://hub.mender.io/u/Stadicus)\
**Post date:** [September 25, 2019, 6:51am UTC](https://hub.mender.io/t/mender-artifact-docker-build-make-build-contained-fails/1051/8 "2019-09-25T06:51:17Z")

</div>

Thanks, works like a charm now! 👨‍🚀👍
