Skip to content

Docker-Based Developer Resource#5871

Merged
tgamblin merged 14 commits intospack:developfrom
opadron:docker-dev-resources
Feb 27, 2018
Merged

Docker-Based Developer Resource#5871
tgamblin merged 14 commits intospack:developfrom
opadron:docker-dev-resources

Conversation

@opadron
Copy link
Copy Markdown
Member

@opadron opadron commented Oct 23, 2017

Hi, folks!

Here's my docker-based development setup. It should be very easy to use, all you need is the latest versions of docker and docker-compose. There's a small README that explains the basic usage and there is support for running in a container running Ubuntu and Fedora, with more choices on the way if there is interest.

The code running spack in the container is the same as your local working copy, letting you experiment in a clean environment while you make changes. Installed packages show up under your local working copy under ./opt and are shared and persist between multiple containers.

We can merge, if enough people like this, or we can keep the branch as-is. The changes stand well enough on their own that they should be easy to cherry-pick.

@tgamblin
Copy link
Copy Markdown
Member

Is it worth referring to this from @ax3l's Docker workflow? Seems like this could be used to kickstart some of what is in there. @ax3l?

@tgamblin tgamblin requested a review from ax3l October 25, 2017 11:52
@opadron
Copy link
Copy Markdown
Member Author

opadron commented Oct 25, 2017

Another important lesson that I learned that is relevant to both @ax3l's documentation and this work:

On Mac and Windows, docker runs in a hypervisor that is allocated a low amount of memory by default (e.g.: 2 GB on my 16 GB Macbook Pro). This short supply of memory was actually the cause of the strange internal compiler errors I was running into while trying to build boost. We should definitely add a note for docker users to make sure that they increase the memory allocated to the hypervisor; ideally to as much as they can tolerate dedicating to docker. All my spack builds were running beautifully once I set my system to allocate 8 GB to docker.

@ax3l
Copy link
Copy Markdown
Member

ax3l commented Oct 26, 2017

Thanks for the ping and the PR!
I have not used docker-compose before but looks intuitive :)

A few thoughts:

If you install lmod (yay!) instead of modules, you might want to change the default in modules.yaml. Per default, only tcl and dotkit modules are created. Yes, lmod is backwards compatible to tcl but I think that is not how it is implemented here (or is it, @alalazo ?).

On git clone, I would use --depth <nowNumber> or use the tar download that I had in the workflow just to save resources.

MPI won't work without openssh-server installed.

For some downloads, I think ca-certificates is useful to have installed in ubuntu.

I like your use of WORKDIR, ENTRYPOINT and CMD. I did that a bit more noob-ish :)

On Mac and Windows, [...] short supply of memory [...]

Interesting observation! Yes, please add a note in the docker workflow section on that if you like!
I also made good experiences with limiting the amount of parallism for builds (in make -j) via config.yaml, especially on virtualized environments such as travis. Might also be worth a try here.

config:
  build_jobs: 2

Copy link
Copy Markdown
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few notorious inline comments :)
cool work!

@@ -0,0 +1,20 @@
Using this docker container for development.
------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the proper amount of -- for formating? :)

$ docker-compose run --rm ubuntu

This command should drop you into an interactive shell where you can run spack
within an isolated docker container running ubuntu. The copy of spack being
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos:

  • Ubuntu
  • double space

Using this docker container for development.
------------

$ cd share/spack/docker
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you like you can add syntax highlighting for bash like this in markdown

@@ -0,0 +1,25 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe remove this empty line?

git clone git://github.com/llnl/spack.git /spack && \
rm -rf /spack/.git && rm -rf /var/lib/apt/lists/*


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dbl empty newline :)

WORKDIR /spack
ENTRYPOINT ["bash"]
CMD ["-l"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double instead of single EOF newline

WORKDIR /spack
ENTRYPOINT ["bash"]
CMD ["-l"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double instead of single EOF newline

you make should be immediately reflected in the running docker container.

To work within a container running a different linux distro, change the "ubuntu"
argument to any one of the services listed under the ``docker-compose.yml``
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the double "`" is rst not md :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you write this file in full .rst instead of .md one can also easier include it into the main sphinx docs into the developer workflows :)

@opadron opadron closed this Oct 27, 2017
@opadron opadron deleted the docker-dev-resources branch October 27, 2017 16:11
@opadron opadron restored the docker-dev-resources branch October 27, 2017 16:13
@opadron
Copy link
Copy Markdown
Member Author

opadron commented Oct 27, 2017

Holy hell, thank goodness for Github's "restore branch" feature...today, I am worthy of the "bonehead of the year" award! 👎

@opadron
Copy link
Copy Markdown
Member Author

opadron commented Oct 27, 2017

Also, if someone can reopen, that would be great! :)

@scheibelp scheibelp reopened this Oct 27, 2017
@opadron
Copy link
Copy Markdown
Member Author

opadron commented Oct 27, 2017

@ax3l thanks a bunch for the valuable feedback. Please have a look at my latest additions and let me know what you think. Please, keep in mind that I haven't yet had the chance to update the Fedora environment, and that there seems to be a known issue related to running Fedora on docker (see https://bugzilla.redhat.com/show_bug.cgi?id=1483553 for details).

Copy link
Copy Markdown
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you for the updates!

I have a few structural inline comments to reduce duplication.

I am wondering if someone wants to add a centos and arch image to the composer as well?

=================================

This guide is intended for people who want to use our prepared docker
environments to work on developing Spack or working on spack packages. It is
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you intentionally making double spaces after .s? :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aye; chalk it up to a habit I learned from grade school. I should write a quick script to look for these things. [:

# image run hook: the -l will make sure /etc/profile environments are loaded
CMD /bin/bash -l

For examples of how we use docker in development, see
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to keep this section focused, I would move this fully in the Best Practices section immediately below.

New sub-sections with """" level:

  • docker in development (this reference)
  • OSX, Windows (the paragraph as text instead of a note)

# Per-user settings (overrides default and site settings):
# ~/.spack/modules.yaml
# -------------------------------------------------------------------------
modules:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to overwrite the default within user space, it should be enough to write the section

modules:
  enable:
     - lmod

in this file.

I would also check this file in only once in the directory above for all docker recipes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know. Is there a way to reference files for COPY that lie outside the Dockerfile's current directory? It was my understanding that this wasn't possible. Hence, the duplicate copy.

@@ -0,0 +1,24 @@
uid="`id -u`"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this file needed in fedora as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Fedora et al is coming, soon (TM),

@@ -0,0 +1,47 @@
# -------------------------------------------------------------------------
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above :)

@ax3l
Copy link
Copy Markdown
Member

ax3l commented Oct 30, 2017 via email

@opadron
Copy link
Copy Markdown
Member Author

opadron commented Oct 31, 2017

@ax3l, I think you'll really like these latest additions.

Unfortunately, github doesn't cope with my rebases well, so you should focus on the history in the actual branch -- not as it is shown on the PR.

In addition to the changes you've suggested, I've also added arch and centos docker images, giving us 4 total distros to test and develop in. You can install spack packages from all four side-by-side within the same installation root; even simultaneously, if you really wanted to and could spare the memory!

As you review, I'd like to point out specific commits:

  • 9811cdd~3: Contains the bulk of the work, with your suggested edits and the new images.
  • 9811cdd~2: Is an experiment I tried with making a custom prompt to help developers keep track of when they're in a docker container. The real tricky part was trying to figure out how to get prompt updates to work asynchronously, to maximize responsiveness. I ended up firing off a subshell and communicating with it using old-school temp files. I think it's pretty neat, but it did end up being more involved than I had originally planned. Give it a try and let me know what you think.
  • 9811cdd~1: I switched a few things around to make the prompt experiment opt-in. On this commit, you can try out the prompt by setting the CUSTOM_PROMPT environment variable within the container:
 $ docker-compose run --rm -e CUSTOM_PROMPT=1 ubuntu
  • 9811cdd: Is a tiny and temporary commit that just works around an issue with fedora by downgrading to an older version of the image. It should be removed once the issue is fixed upstream.

It's too bad the way docker works forces us to duplicate some files, but once I've gotten over the minor headache of editing some things four times, I've come to really appreciate the convenience of developing across several distros with minimal effort. I think we're getting pretty close to a really nice development asset.

Edit: Changed HEAD references to hashes so that they still work after adding more commits.

@opadron opadron force-pushed the docker-dev-resources branch from 3160279 to 9811cdd Compare October 31, 2017 03:54
Copy link
Copy Markdown
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really nice work and well documented, thank you!

I tried it with docker-compose version 1.16.1, build 6d1ac21 + Docker version 1.6.2, build 7c8fca2 and are currently getting network errors. Is there anything I am missing?

@@ -0,0 +1,59 @@
FROM pritunl/archlinux
Copy link
Copy Markdown
Member

@ax3l ax3l Nov 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the minimal image, but this image does not look too popular for arch.
Although there seems not to be an official arch image, there are certainly more popular and automated ones in: https://hub.docker.com/search/?isAutomated=1&isOfficial=0&q=arch
Shall we use one of those?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, there doesn't seem to be an official arch image, and I went with the one I found mentioned in Arch's docker documentation. https://wiki.archlinux.org/index.php/Docker

I remember trying the base/archlinux image and having trouble with it, though I can't recall exactly what the issue was. In any case, I'll give these other images a try and report back.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I can't remember what problems I had before, but they seem to be gone, now! I'll go ahead and push up the change for the arch image's base to base/archlinux.

$ docker-compose config --services
fedora
ubuntu
$ docker-compose run --rm fedora
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

somehow I get a

Creating network "spack_default" with the default driver
ERROR: 404 page not found

at this point :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the 404 means, exactly, but the version of docker you reported is almost certainly too old. You will need a relatively recent version of the docker client and server in order for the different containers to work.

For comparison, this is what I get on my Macbook using the new docker for mac engine:

 $ docker version
Client:
 Version:      17.09.0-ce
 API version:  1.32
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:40:09 2017
 OS/Arch:      darwin/amd64

Server:
 Version:      17.09.0-ce
 API version:  1.32 (minimum version 1.12)
 Go version:   go1.8.3
 Git commit:   afdb6d4
 Built:        Tue Sep 26 22:45:38 2017
 OS/Arch:      linux/amd64
 Experimental: true

Copy link
Copy Markdown
Member

@ax3l ax3l Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay and thx for ping-ing!

I updated to

$ docker --version
Docker version 17.09.0-ce, build afdb6d4

$ docker-compose --version
docker-compose version 1.17.0, build ac53b73

now... will report back in a few minutes :)

@opadron
Copy link
Copy Markdown
Member Author

opadron commented Nov 13, 2017

@ax3l LGTY? 🤞

@ax3l
Copy link
Copy Markdown
Member

ax3l commented Nov 14, 2017

@opadron install works so far like a charm for me!

But did you try loading the installed packages? e.g. on fedora it fails for me:

$ spack install zlib
# ok! :)

$ spack load zlib
Lmod has detected the following error:  The following module(s) are
unknown: "zlib-1.2.11-gcc-5.4.1-5nuhji2" "zlib-1.2.11-clang-3.8.1-24-crspzo2"
"zlib-1.2.11-gcc-6.3.1-dmwlk6z" "zlib-1.2.11-gcc-6.3.0-hwcs5w5"

Please check the spelling or version number. Also try "module spider ..."




[root@c37e1a9d3a96 ~]# module spider zlib
Lmod has detected the following error:  Unable to find: "zlib"

on ubuntu:

# spack load zlib

Lmod Warning: MODULEPATH is undefined


Lmod has detected the following error: 
The following module(s) are unknown: "zlib-1.2.11-clang-3.8.1-24-crspzo2" "zlib-1.2.11-gcc-5.4.1-5nuhji2" "zlib-1.2.11-gcc-6.3.1-dmwlk6z" "zlib-1.2.11-gcc-5.4.0-swly52a" "zlib-1.2.11-gcc-6.3.0-hwcs5w5"

   Please check the spelling or version number. Also try "module spider ..."

@opadron
Copy link
Copy Markdown
Member Author

opadron commented Nov 15, 2017

I'm inclined to call this a bug in Spack, because it runs counter to what I had come to expect as a Spack user. Considering that Spack doesn't seem to have a problem installing and reporting on installed packages from multiple distributions side-by-side (that is, within the same Spack database), it would seem to imply that Spack should be able to cope with such a situation when asked to load a module, but I have confirmed that this multi-distro scenario is what causes the various errors you are seeing.

To test this yourself, just rm -r ./opt from within the spack git dir, and then try your zlib test, again. Spack works as expected on all four distros when starting from a clean DB. When there is installation data from other distros lying around is when Spack's load function seems to break down.

There is a simple workaround that I have already prepared where every distro uses a separate Spack DB, but I think we should have a discussion about the underlying issue before deciding that we want this workaround.

/cc @tgamblin

@opadron
Copy link
Copy Markdown
Member Author

opadron commented Nov 15, 2017

#6245 Seems to be related to the issue I wrote about above, which tells me at least one other person thinks this is a bug in Spack.

If we're indeed willing to call this a bug in Spack, I would suggest that we continue to consider this PR for merging in spite of the bug.

Copy link
Copy Markdown
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all right from my side, besides the loading issue on multi arch installs which is an orthogonal issue

python \
sudo \
tcl && \
git clone --depth 1 git://github.com/llnl/spack.git /spack && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the urls should be updated.

Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took the time to go through the code, and I really like the idea of bind mounting volumes to get a light-weight multi-platform environment using docker.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Nov 20, 2017

If you install lmod (yay!) instead of modules, you might want to change the default in modules.yaml. Per default, only tcl and dotkit modules are created. Yes, lmod is backwards compatible to tcl but I think that is not how it is implemented here (or is it, @alalazo ?).

@ax3l We have to distinguish between lmod the tool (which is completely backward compatible with environment-modules) and lmod the module file format. The latter could have been called "hierarchical lua module files", because it's what we actually generate.

So, to summarize:

  1. lmod as a tool can be installed and used instead of environment-modules. It can interpret both tcl and lmod module files.
  2. lmod as a module file format means we are using "hierarchical lua" module files. It's only understood by the lmod tool, and imo it's useful only if you plan to expose software directly (without any mediation layer, like spack load)

@ax3l
Copy link
Copy Markdown
Member

ax3l commented Nov 20, 2017

and lmod the module file format

sorry for my short note, I was referring indeed to the lmod tool that is still able to read "legacy" lua tcl files from environment-modules...

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Nov 20, 2017

is still able to read "legacy" lua...

"legacy" tcl...

@ax3l
Copy link
Copy Markdown
Member

ax3l commented Jan 24, 2018

@opadron @alalazo should we merge/finalize this PR in anyway?

@tgamblin tgamblin merged commit 3a9cd26 into spack:develop Feb 27, 2018
@tgamblin
Copy link
Copy Markdown
Member

Thanks @opadron!

@opadron opadron deleted the docker-dev-resources branch February 27, 2018 13:48
smuething pushed a commit to smuething/spack that referenced this pull request Feb 28, 2018
* add docker-based development resources

* incorporate feedback from @ax3l

* fix docs/improve ssh handling

* experiment with custom prompt

* add arch/fix missing core_compilers key

* add centos/minor tweaks

* make prompt experiment optional

* workaround problem with latest fedora docker image

* add docker documentation page to index toc

* try another documentation fix

* switch arch linux base to base/archlinux

* update the git urls in the Dockerfiles

* add opensuse

* switch CUSTOM_PROMPT variable to simply "PROMPT"
ch741 pushed a commit to ch741/spack that referenced this pull request Apr 20, 2018
* add docker-based development resources

* incorporate feedback from @ax3l

* fix docs/improve ssh handling

* experiment with custom prompt

* add arch/fix missing core_compilers key

* add centos/minor tweaks

* make prompt experiment optional

* workaround problem with latest fedora docker image

* add docker documentation page to index toc

* try another documentation fix

* switch arch linux base to base/archlinux

* update the git urls in the Dockerfiles

* add opensuse

* switch CUSTOM_PROMPT variable to simply "PROMPT"
@opadron opadron mentioned this pull request Jun 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants