Packer builds from inside a docker container (gitlab-ci-runner)

1,608 views
Skip to first unread message

Greg Fitzgerald

unread,
Apr 8, 2016, 6:51:18 PM4/8/16
to packe...@googlegroups.com
Does anyone have any experience in automating packer builds. We are
building docker images, and we want to automatically build and push from
inside gitlab-ci.

We currently spin up gitlab-runners on digitalocean using coreos. A
docker image is run which starts docker in docker, and runs packer
validate template && packer build template.

Packer pulls down the base image, but when the template runs our scripts
it hangs. I can't seem to find out what is going on. Any tips would be
useful.

Best Regards,

--gregf

Alvaro Miranda Aguilera

unread,
Apr 8, 2016, 11:02:19 PM4/8/16
to packe...@googlegroups.com
Hello

If the scripts are bash, try to enable or run them as verbose mode.

ie 

#!/bin/bash -x

if you can insolate whats the problem and create some code that you can share, I am happy to have a look.

If you can share what you have, but for some reason won't put on GitHub, feel free to send me an email if you need extra eyes there

Thanks
Alvaro.



--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.

GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/20160408221158.GB5161%40betsy.gregf.org.
For more options, visit https://groups.google.com/d/optout.

Greg Fitzgerald

unread,
Apr 9, 2016, 8:34:17 AM4/9/16
to packe...@googlegroups.com, Alvaro Miranda Aguilera
On Sat Apr 09 03:02PM, Alvaro Miranda Aguilera wrote:
> Hello
>
> If the scripts are bash, try to enable or run them as verbose mode.
>
> ie
>
> #!/bin/bash -x

This sadly didn't really reveal anything nothing outputs once the script
is run. Even with bash -x.

>
> if you can insolate whats the problem and create some code that you can
> share, I am happy to have a look.
>
> If you can share what you have, but for some reason won't put on GitHub,
> feel free to send me an email if you need extra eyes there

Heres some config files and a screen shot of where it hangs.

https://gist.github.com/gregf/a71c185615b90ed3514e06a9af78a9d0

https://i.imgur.com/BTpUETy.png

I simplified my packer provisioner to a simple echo command, it still
hangs at that step.
> To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CAHqq0eyvyvdsLQEFjT60PYNHVv7wDK29AByqyyGhbd4i45Z0UA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

--gregf

Alvaro Miranda Aguilera

unread,
Apr 10, 2016, 2:37:25 AM4/10/16
to Greg Fitzgerald, packe...@googlegroups.com
Hello

Try to replace this:

"/bin/bash"


with this


"/bin/bash”, “-l"


Alvaro.

Greg Fitzgerald

unread,
Apr 10, 2016, 7:31:50 AM4/10/16
to Alvaro Miranda Aguilera, packe...@googlegroups.com
I tried "-l" and "-x" no output still. I also tried packer build -debug
and didn't get anything useful from that either.
--gregf

Alvaro Miranda Aguilera

unread,
Apr 10, 2016, 8:44:09 AM4/10/16
to Greg Fitzgerald, packe...@googlegroups.com
AH!

I think I know what it s

on some OS there is a OS package called packer that does something different.

Try to download packer to a folder and run it with full path
ie

/usr/local/bin/packer build template.json

Alvaro.

Greg Fitzgerald

unread,
Apr 10, 2016, 9:01:15 AM4/10/16
to Alvaro Miranda Aguilera, packe...@googlegroups.com
Still hangs at the same spot. :(

$ unzip packer_0.10.0_linux_amd64.zip -d /usr/local/bin
Archive: packer_0.10.0_linux_amd64.zip
inflating: packer
$ rm -f packer_0.10.0_linux_amd64.zip
$ /usr/local/bin/packer validate dockerimage.json
Template validated successfully.
$ /usr/local/bin/packer build dockerimage.json
docker output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: debian:8.4
docker: 8.4: Pulling from library/debian
docker: efd26ecc9548: Pulling fs layer
docker: a3ed95caeb02: Pulling fs layer
docker: a3ed95caeb02: Verifying Checksum
docker: a3ed95caeb02: Download complete
docker: efd26ecc9548: Verifying Checksum
docker: efd26ecc9548: Download complete
docker: efd26ecc9548: Pull complete
docker: efd26ecc9548: Pull complete
docker: a3ed95caeb02: Pull complete
docker: a3ed95caeb02: Pull complete
docker: Digest: sha256:99c2477a731c3ff5875b70f2d90f3328fb9de735772c08a2d97fb36ac8d5739f
docker: Status: Downloaded newer image for debian:8.4
==> docker: Starting docker container...
docker: Run command: docker run -v /root/.packer.d/tmp/packer-docker155563732:/packer-files -h=gitlabci.gregf.org -d -i -t debian:8.4 /bin/bash -l -x
docker: Container ID: b6701b52dcb17a71b4e108ca49f390057622c3f987f53656a0f99b385e938561
==> docker: Provisioning with shell script: /tmp/packer-shell926048473
--gregf

Alvaro Miranda Aguilera

unread,
Apr 10, 2016, 10:16:53 AM4/10/16
to Greg Fitzgerald, packe...@googlegroups.com
When I run it on my computer, it run just fine

not from where the error is comming from

this will be ugly, but if you can share, I can have a look.

strace -f  /usr/local/bin/packer build dockerimage.json 2>&1 > packer.strace.log

Less verbose:
PACKER_LOG=1 /usr/local/bin/packer build dockerimage.json

If you can share those in a gist, those will help

:

kikitux@desktop:~/g$ packer build dockerimage.json
docker output will be in this color.

==> docker: Creating a temporary directory for sharing data...
==> docker: Pulling Docker image: debian:8.4
    docker: 8.4: Pulling from library/debian
    docker: efd26ecc9548: Already exists
    docker: a3ed95caeb02: Already exists
    docker: Digest: sha256:99c2477a731c3ff5875b70f2d90f3328fb9de735772c08a2d97fb36ac8d5739f
    docker: Status: Image is up to date for debian:8.4
==> docker: Starting docker container...
    docker: Run command: docker run -v /home/kikitux/.packer.d/tmp/packer-docker297217588:/packer-files -h=gitlabci.gregf.org --privileged=true -d -i -t debian:8.4 /bin/bash -l
    docker: Container ID: e2cc80e3973181460b1466b3e857e3327899dc743c09f85b0b022abda027da4e
==> docker: Provisioning with shell script: /tmp/packer-shell856868665
==> docker: Exporting the container
==> docker: Killing the container: e2cc80e3973181460b1466b3e857e3327899dc743c09f85b0b022abda027da4e
==> docker: Running post-processor: docker-import
    docker (docker-import): Importing image: Container
    docker (docker-import): Repository: gregf/gitlabci-runner:latest
    docker (docker-import): Imported ID: sha256:c9b84cd439014e7b68d0131e9685e2f96a9e17f19175c18277b31999f86c5705
==> docker: Running post-processor: docker-push
    docker (docker-push): Pushing: gregf/gitlabci-runner
    docker (docker-push): The push refers to a repository [docker.io/gregf/gitlabci-runner]
    docker (docker-push): aa9ee30d95ca: Preparing


Not sure 
Reply all
Reply to author
Forward
0 new messages