Skip to content

Commit 8f24bd3

Browse files
committed
adding asciicasts for demo for @satra
1 parent 6ae4b8c commit 8f24bd3

5 files changed

Lines changed: 28040 additions & 0 deletions

File tree

_includes/asciicast-custom.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<button style='color:white;margin-top:5px' class="btn btn-primary btn-lg asciinema-button" id="{{ include.title | replace:' ','-' }}">Show Video Tutorial</button>
2+
<div class="hidden" id="asciinema-{{ include.title | replace:' ','-' }}">
3+
<asciinema-player
4+
src="assets/asciicast/{{include.source}}"
5+
poster="data:text/plain,{{include.title}}"
6+
title="{{include.title}}"
7+
author="{{include.author}}"
8+
cols="{{include.cols}}"
9+
rows="{{include.rows}}"
10+
speed="{{site.asciicast.speed}}"
11+
theme="{{site.asciicast.theme}}">
12+
</asciinema-player>
13+
</div>
14+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
---
2+
title: "Getting Started with Singularity and Singularity Hub"
3+
category: recipes
4+
permalink: singularity-tutorial
5+
---
6+
7+
So you want to put your scientific analysis in a nice package and run it on a cluster? You’ve probably heard of the container technology called Docker?
8+
9+
<img src="/assets/img/tutorial/horsecarrot.png"><br>
10+
11+
...too bad you can’t use it on your research cluster, because it introduces huge security issues. You’ve probably also heard of <a href="https://www.vagrantup.com/docs/virtualbox/" target="_blank">virtual machines</a>, but most clusters won’t let you run those either. What options does this leave us? Oh wait, duh, you are reading this website. You already know the answer to this question.
12+
13+
14+
{% include toc.html %}
15+
16+
17+
## Getting Started
18+
19+
### Install Singularity
20+
The easiest thing to do is to install Singularity on your local workstation:
21+
22+
```bash
23+
sudo apt-get update
24+
sudo apt-get -y install build-essential curl git sudo man vim autoconf libtool
25+
git clone https://github.com/singularityware/singularity.git
26+
cd singularity
27+
./autogen.sh
28+
./configure --prefix=/usr/local
29+
make
30+
sudo make install
31+
```
32+
33+
If you have the unfortunate situation of using a Mac, or just need a virtual machine, then you will want to follow the instructions <a href="http://singularity.lbl.gov/install-mac" target="_blank">here</a>. Basically, you need to install vagrant, virtual box, and then do this:
34+
35+
```bash
36+
vagrant init ubuntu/trusty64
37+
vagrant up
38+
39+
vagrant ssh -c /bin/sh <<EOF
40+
sudo apt-get update
41+
sudo apt-get -y install build-essential curl git sudo man vim autoconf libtool
42+
git clone https://github.com/singularityware/singularity.git
43+
cd singularity
44+
./autogen.sh
45+
./configure --prefix=/usr/local
46+
make
47+
sudo make install
48+
EOF
49+
50+
vagrant ssh
51+
```
52+
53+
Once you are in your Virtual Machine, or have Singularity up and running? Well, it's time to go NUTS of course!
54+
55+
56+
### A little about Singularity Hub
57+
<a href="https://www.singularity-hub.org" target="_blank">Singularity Hub</a> is an online registry for images. This means that you can connect a Github repo containing a build specification file to this website, and the image is going to build for you automatically, and be available programatically! We can talk more about how that happens later. If you want some quick details, you should check out the <a href="https://www.singularity-hub.org/faq" target="_blank">Usage Docs</a> on Singularity Hub.
58+
59+
60+
## Make and run containers
61+
62+
### Run an image
63+
For this little preview, we are going to be first running an image, directly from Singularity Hub. This image is called <a href="https://singularity-hub.org/collections/24/" target="_blank">vsoch/singularity-images</a> and it's associated with <a href="https://www.github.com/vsoch/singularity-images" target="_blank">the equivalent Github repository.</a>
64+
65+
```bash
66+
singularity run shub://vsoch/singularity-images
67+
```
68+
69+
{% include asciicast-custom.html rows='41' cols='100' source='shub-pull.json' title='Pulling and running a Singularity Hub image' author='vsochat@stanford.edu' %}
70+
71+
In the above, we use the Singularity Hub "unique resource identifier," or `uri`, `shub://` which tells the software to run an image from Singularity Hub.
72+
73+
74+
### Create an image
75+
Running is great, but what if we want to mess around on the command line, using an image we've created ourselves? We can do that by creating an image:
76+
77+
```bash
78+
sudo singularity create analysis.img
79+
sudo singularity import analysis.img docker://ubuntu:latest
80+
singularity shell analysis.img
81+
```
82+
83+
{% include asciicast-custom.html rows='41' cols='100' source='singularity-interact.json' title='Create and shell into a Singularity image' author='vsochat@stanford.edu' %}
84+
85+
In the above, we use the docker "unique resource identifier," or `uri`, `docker://` which tells the software to import a docker image.
86+
87+
If we wanted to shell into the image and make it writable, meaning that we can write files and save changes, we would do this:
88+
89+
```bash
90+
sudo singularity shell --writable analysis.img
91+
```
92+
93+
Note that we need sudo, and also note that you wouldn't be able to do this on a research cluster, because you don't have sudo.
94+
95+
96+
### Create a reproducible image
97+
The problem with create an image, and then maybe writing stuff to it with `--writable` is that your work isn't properly saved anywhere. You COULD ship and share the entire image, but that still doesn't help to say what was done to it, and this is problematic. To help with this, we encourage you to create a build specification file, a file called `Singularity`. There are a few important sections you should know about. First, let's look at a very simple file:
98+
99+
```bash
100+
Bootstrap: docker
101+
From: ubuntu:latest
102+
103+
%runscript
104+
105+
echo "I can put here whatever I want to happen when the user runs my container!"
106+
exec echo "Hello Monsoir Meatball" "$@"
107+
108+
%post
109+
110+
echo "Here we are installing software and other dependencies for the container!"
111+
apt-get update
112+
apt-get install -y git
113+
114+
```
115+
116+
The important things to note. The header section says that we want to `Bootstrap` a docker image, specifically `From` ubuntu:latest. No, you don't actually need Docker installed to run this, because the layers are pulled from their API endpoint.
117+
118+
{% include asciicast-custom.html rows='41' cols='100' source='singularity-bootstrap.json' title='Bootstrapping an image' author='vsochat@stanford.edu' %}
119+
120+
Once you have your bootstrap file, and you know how to use Github, you are really good to go. You can add the file to repository, connect it to Singularity Hub, and it will build automatically and be available via the `shub://` endpoint. That's it!

0 commit comments

Comments
 (0)