-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #558 from wd15/docker
Use Nix to build Docker instance
- Loading branch information
Showing
5 changed files
with
173 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Run PyMKS in a Docker Instance | ||
|
||
## Install Docker | ||
|
||
Install Docker and run the Daemon. See | ||
https://docs.docker.com/engine/install/ for installation | ||
details. Launch the Daemon if necessary. | ||
|
||
$ sudo service docker start | ||
|
||
## Pull the Docker instance | ||
|
||
Pull the Docker Instance from Dockerhub | ||
|
||
$ docker pull docker.io/wd15/pymks | ||
|
||
## Run the Tests | ||
|
||
Run the tests. | ||
|
||
$ docker run -i -t wd15/pymks:latest | ||
# python -c "import pymks; pymks.test()" | ||
|
||
## Use PyMKS in a Jupyter notebook | ||
|
||
$ docker run -i -t -p 8888:8888 wd15/fipy:latest | ||
# jupyter notebook --ip 0.0.0.0 --no-browser | ||
|
||
The PyMKS example notebooks are availabe inside the image after | ||
opening the notebook using http://127.0.0.1:8888. | ||
|
||
## Build the Docker instance | ||
|
||
Clone this repository and build the instance. | ||
|
||
$ docker load < $(nix-build docker.nix) | ||
|
||
or to build and then launch use | ||
|
||
$ docker load < $(nix-build docker.nix) && docker run -p 8888:8888 -it wd15/pymks:latest | ||
|
||
## Push the Docker instance | ||
|
||
Create the repository in Dockerhub and then push it. | ||
|
||
$ docker login | ||
$ docker push docker.io/wd15/pymks |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# View DOCKER.md to see how to use this | ||
|
||
{ | ||
tag ? "20.09", | ||
withSfepy ? true, | ||
withGraspi ? true, | ||
graspiVersion ? "59f6a8a2e1ca7c8744a4e37701b919131efb2f45" | ||
}: | ||
let | ||
pkgs = import (builtins.fetchTarball "https://github.com/NixOS/nixpkgs/archive/${tag}.tar.gz") {}; | ||
pypkgs = pkgs.python3Packages; | ||
pymks = pypkgs.callPackage ./default.nix { | ||
sfepy=(if withSfepy then pypkgs.sfepy else null); | ||
graspi=(if withGraspi then graspi else null); | ||
}; | ||
graspisrc = builtins.fetchTarball "https://github.com/owodolab/graspi/archive/${graspiVersion}.tar.gz"; | ||
graspi = pypkgs.callPackage "${graspisrc}/default.nix" {}; | ||
|
||
lib = pkgs.lib; | ||
USER = "main"; | ||
|
||
from_directory = dir: (lib.mapAttrsToList (name: type: | ||
if type == "directory" || (lib.hasSuffix "~" name) then | ||
null | ||
else | ||
dir + "/${name}" | ||
) (builtins.readDir dir)); | ||
|
||
## files to copy into the user's home area in container | ||
files_to_copy = [ ] ++ (lib.remove null (from_directory ./notebooks)); | ||
|
||
## functions necessary to copy files to USER's home area | ||
## is there an easier way??? | ||
filetail = path: lib.last (builtins.split "(/)" (toString path)); | ||
make_cmd = path: "cp ${path} ./home/${USER}/${filetail path}"; | ||
copy_cmd = paths: builtins.concatStringsSep ";\n" (map make_cmd paths); | ||
|
||
python-env = pkgs.python3.buildEnv.override { | ||
ignoreCollisions = true; | ||
extraLibs = with pypkgs; [ | ||
pymks | ||
ipywidgets | ||
] ++ pymks.propagatedBuildInputs; | ||
}; | ||
in | ||
pkgs.dockerTools.buildImage { | ||
name = "wd15/pymks"; | ||
tag = "latest"; | ||
|
||
contents = [ | ||
python-env | ||
pkgs.bash | ||
pkgs.busybox | ||
pkgs.coreutils | ||
pkgs.openssh | ||
pkgs.bashInteractive | ||
]; | ||
|
||
runAsRoot = '' | ||
#!${pkgs.stdenv.shell} | ||
${pkgs.dockerTools.shadowSetup} | ||
groupadd --system --gid 65543 ${USER} | ||
useradd --system --uid 65543 --gid 65543 -d / -s /sbin/nologin ${USER} | ||
''; | ||
|
||
extraCommands = '' | ||
mkdir -m 1777 ./tmp | ||
mkdir -m 777 -p ./home/${USER} | ||
# echo 'extra commands' | ||
# pwd | ||
# cp -r notebooks ./home/${USER}/ | ||
'' + copy_cmd files_to_copy; | ||
|
||
config = { | ||
Cmd = [ "bash" ]; | ||
User = USER; | ||
Env = [ | ||
"OMPI_MCA_plm_rsh_agent=${pkgs.openssh}/bin/ssh" | ||
"HOME=/home/${USER}" | ||
]; | ||
WorkingDir = "/home/${USER}"; | ||
Expose = { | ||
"8888/tcp" = {}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters