oswitch 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 75af23e839e1c6933df699ecb6e14f5512ce863c
4
- data.tar.gz: 902745b152459f284ff363b6897efba8e2c341ab
3
+ metadata.gz: 9c4115b5b4f04909c25cb4dd04baa720e3a0384e
4
+ data.tar.gz: cd0859b22016d60e6d278d6b26ff24eb4643ffa3
5
5
  SHA512:
6
- metadata.gz: 9ee1019f702540123b5bcf4305059eb432d00946564f820770d2aeec4dbfc0d220cff2b927f16ab47eddeb9bbdcaf8c69a18c4fea659abaa230ff297dae153d2
7
- data.tar.gz: 6c08c54c9bc36fcaf58d2aab8814da44b6ef50b7b6dc41cee1dc6a21a0d22bf42dceb37c9af6540106bcc3c65fc06a28e5c605a275b4710cae7d7c510eacf12b
6
+ metadata.gz: 618de17e8315c607b14aa43bb804cbaae61bb8726ec9b3833fdaed0a134852d62bf19da2227e0015ae225d954333b296500c45ba6c32ccf68888b91c8c0ea4a0
7
+ data.tar.gz: 6e191e6ee60604e1b9111cc31b0fa93409fb52ba2f52077fb5a4d8b4b50a89243a349a3d147d5daa6caf95b6a03fa6e3e69e03493751cec20f0205394bcc5459
data/README.mkd CHANGED
@@ -1,18 +1,22 @@
1
- # OSwitch
1
+ # oswitch - virtual environments for flexible and reproducible bioinformatics analyses
2
2
 
3
- One-line access to other operating systems.
4
-
5
- Mini-example:
3
+ More and more bioinformatics software are being "containerised" with [docker](http://docker.io/), making them installable on personal computers and compute clusters alike with a single command in a reproducible manner. However, using containerised software can still be a challenge as the containers are effectively a different operating system altogether.
4
+ oswitch enhances usability of docker containers by a) automatically making available the local file-system and user profile inside the container, b) using the host user's login shell and current working directory as the entry point. The net effect is similar to entering "virtual environment" on the host system containing specific versions of software of interest.
6
5
 
7
6
  ```bash
8
- mymacbook:~/2015-02-01-myproject> abyss-pe
7
+ mymacbook:~/2015-02-01-myproject> abyss-pe k=25 reads.fastq.gz
9
8
  zsh: command not found: abyss-pe
9
+
10
+ # List available images.
10
11
  mymacbook:~/2015-02-01-myproject> oswitch -l
11
12
  yeban/biolinux:8
12
13
  ubuntu:14.04
13
14
  ontouchstart/texlive-full
14
15
  ipython/ipython
15
16
  hlapp/rpopgen
17
+ bioconductor/release_sequencing
18
+
19
+ # Enter the continaer and run commands interactively.
16
20
  mymacbook:~/2015-02-01-myproject> oswitch biolinux
17
21
  ###### You are now running: biolinux in container biolinux-7187. ######
18
22
  biolinux-7187:~/2015-02-01-myproject> abyss-pe k=25 reads.fastq.gz
@@ -20,258 +24,48 @@ biolinux-7187:~/2015-02-01-myproject> abyss-pe k=25 reads.fastq.gz
20
24
  biolinux-7187:~/2015-02-01-myproject> exit
21
25
  mymacbook:~/2015-02-01-myproject>
22
26
  [... output is where you expect it to be ...]
23
- ```
24
27
 
25
- Detailed information:
26
- * [Features](#features)
27
- * [Usage](#example-usage)
28
- * [Installation](#installation)
29
- * [FAQ](#faq)
30
- * [Roadmap](#roadmap)
31
- * [Contributors & Funding](#contributors-&-funding)
32
-
33
- ## Background
34
-
35
- Genomic analyses require jumping back and forth between many bioinformatics tools.
36
- The data types are young, thus so are the tools. This leads to frequent
37
- updates of tools that are often challenging to install. Furthermore, it is
38
- challenging to keep different versions of software for different projects, yet
39
- changing versions can make analyses difficult to reproduce. To make matters worse,
40
- genomicists often lack the skills necessary to setup complex bioinformatics software,
41
- and systems administrators can be overwhelmed by large numbers of software
42
- installation requests.
43
-
44
- ## Aim
45
-
46
- We are developing `oswitch` to enable **seamless switching
47
- from one operating system to another** - providing access to diverse
48
- ranges of tools. This project grew from our own need to rapidly access
49
- diverse pieces of specific versions of software including those distributed as part of
50
- [BioLinux](http://environmentalomics.org/bio-linux/) on our MacBooks
51
- and our university HPC system. This was previously too difficult, but is
52
- important for [reproducible research](http://www.software.ac.uk) and agility.
53
- @bmpvieira made it clear early on that the [docker](http://docker.io/) could
54
- help make something happen. We first shared the resulting concept during a
55
- [Balti & Bioinformatics](http://nickloman.github.io/balti/2014/05/01/balti-and-bioinformatics-27th-may-2014/)
56
- presentation in the form of this (now out of date!) slide:
57
-
58
- [![Slide from Balti](http://i.imgur.com/exfDi6a.png)](http://www.slideshare.net/yannickwurm/2014-0527-opinion-computing-for-genomics-sucks)
59
-
60
- Docker images feel similar to using virtual machine images - but are much more
61
- [flexible and light-weight](http://stackoverflow.com/questions/16047306/how-is-docker-io-different-from-a-normal-virtual-machine).
62
- They are thus easily [shared or published](https://hub.docker.com/). We are extremely lucky to
63
- be able to build upon this amazing technology.
64
-
65
- ## Features
66
-
67
- **`oswitch` is a wrapper facilitating access to docker images**. Importantly, when switching
68
- operating systems inside a shell, most things remain unchanged:
69
-
70
- * Current working directory is maintained
71
- * User name, uid and gid are maintained
72
- * Login shell (bash/zsh/fish) is maintained
73
- * Home directory is maintained (thus all .dotfiles and config files
74
- are maintained).
75
- * read/write permissions are maintained
76
- * Paths are maintained whenever possible. Thus volumes (external drives,
77
- NAS, USB) mounted on the host are available in the container at the same
78
- path.
79
-
80
- ## Example Usage
81
-
82
- There are two broad usage scenarios: interactive use & non-interactive
83
- use.
84
-
85
- ##### Use a package interactively in a normal command-line
86
-
87
- Minimalist example:
88
-
89
- ```shell
90
- Yannick@n56-169 ~/myproject> uname -a
91
- Darwin n56-169.sbcs.qmul.ac.uk 14.0.0 Darwin Kernel Version 14.0.0: Fri Sep 19 00:26:44 PDT 2014; root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
92
- Yannick@n56-169 ~/myproject> oswitch yeban/biolinux
93
- ### You are now running: biolinux_8, in container: biolinux_8-27182. ###
94
- Yannick@biolinux_8-27182 ~/myproject> uname -a
95
- Linux biolinux_8-27182 3.16.4-tinycore64 #1 SMP Thu Oct 23 16:14:24 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
96
- ```
97
28
 
98
- Biologically relevant example:
99
-
100
- ```shell
101
- # Trying to run blast.
102
- pixel:~/test/ $ ls
103
- mygene.fasta
104
- pixel:~/test/ $ cat mygene.fa
105
- >myfavoritegene isthisone
106
- MNTLWLSLWDYPGKLPLNFMVFDTKDDLQAAYWRDPYSIPLAVIFEDPQPISQRLIYEIR
107
- TNPSYTLPPPPTKLYSAPISCRKNKTGHWMDDILSIKTGESCPVNNYLHSGFLALQMITD
108
- ITKIKLENSDVTIPDIKLIMFPKEPYTADWMLAFRVVIPLYMVLALSQFITYLLILIVGE
109
- KENKIKEGMKMMGLNDSVF
110
- pixel:~/test/ $ blastp -query mygene.fa -remote -db nr -outfmt 7 > mygene_blastp_nr.tab
111
- zsh: command not found: blastp
112
- # Indeed... blastp is missing from my MacBook.
113
-
114
- # Switch to BioLinux and run blastp.
115
- pixel:~/test/ $ oswitch yeban/biolinux
116
- ###### You are now running: biolinux in container biolinux-7187. ######
117
- biolinux-7187:~/test/ $ blastp -query mygene.fa -remote -db nr -outfmt 7 > mygene_blastp_nr.tab
118
- # BioLinux includes blastp, thus the command ran smoothly.
119
-
120
- # View the result.
121
- biolinux-7187:~/test/ $ head mygene_blastp_nr.tab
122
- # BLASTP 2.2.28+
123
- # Query: myfavoritegene isthisone
124
- # RID: BJAHAHU9015
125
- # Database: nr
126
- # Fields: query id, subject id, % identity, alignment length, mismatches, gap opens, q. start, q. end, s. start, s. end, evalue, bit score
127
- # 501 hits found
128
- myfavoritegene gi|322796550|gb|EFZ19024.1| 100.00 199 0 0 1 199 1 199 2e-142 407
129
- myfavoritegene gi|307183032|gb|EFN69988.1| 86.07 201 25 2 1 199 80 279 6e-115 361
130
- myfavoritegene gi|572260155|ref|XP_006608402.1| 80.60 201 36 2 1 199 95 294 4e-108 350
131
- myfavoritegene gi|328778864|ref|XP_397465.4| 80.60 201 36 2 1 199 95 294 5e-108 350
132
-
133
-
134
- # [... potentially run other analyses that require biolinux things...]
135
-
136
- # Return to normal operating system
137
- biolinux-7187:~/test/ $ exit
138
- pixel:~/test/ $ ls
139
- mygene.fasta mygene_blastp_nr.txt
140
- # our newly generated file is where we'd expect it to be.
141
- ```
142
-
143
- ##### Use a package non-interactively
144
-
145
- Alternatively, single commands can be run directly in a container
146
- (e.g. BioLinux) without entering it interactively. This can
147
- be useful to test new tools, or to run a single piece of
148
- not-locally-installed software as part of a single command. The
149
- container terminates automatically once the command has been
150
- executed, output is printed to the terminal and can be redirected, and
151
- the exit status of the command run within container is returned.
152
-
153
- ```shell
154
- # Run command directly in BioLinux and view results if success.
29
+ # Use a container non-interactively.
155
30
  pixel:~/test/ $ oswitch yeban/biolinux blastp -remote -query mygene.fa -db nr > mygene_blastp_nr.txt
156
31
  ```
157
32
 
158
- ##### Listing available operating system containers
159
-
160
- OSwitch can pull any image from docker hub. You can see the images you pulled
161
- from docker hub using oswitch as:
162
-
163
- ```shell
164
- pixel:~ $ oswitch -l
165
- yeban/biolinux:8
166
- ubuntu:14.04
167
- ontouchstart/texlive-full
168
- ipython/ipython
169
- hlapp/rpopgen
170
- ```
171
-
172
- ##### Availability
173
-
174
- We have tested OSwitch on:
175
-
176
- * Mac OS X Yosemite
177
- * Ubuntu 14.04.1
178
- * CentOS 7
179
-
180
- ##### Caveats
181
-
182
- * Some features work only for Debian, Ubuntu, CentOS based docker images.
183
- * Host directories/volumes with paths conflicting with container paths are
184
- skipped.
185
- * SELinux must be disabled on CentOS for mounting volumes to work.
186
- * [Volume mounting on Mac OS hosts is imperfect](#q-directories-mounted-within-container-on-mac-host-are-empty).
187
-
188
33
  ## Installation
189
34
 
190
- OSwitch first requires a [working docker install](#Install and setup docker).
191
-
192
- #### Install oswitch
193
-
194
- ##### Mac
195
-
196
- Using [homebrew](http://brew.sh/).
197
-
198
- $ brew install https://raw.githubusercontent.com/yeban/oswitch/master/homebrew/oswitch.rb
199
-
200
- Depending on whether Homebrew is installed systemwide or only for your user,
201
- this will install `oswitch` systemwide or only for your user.
202
-
203
- ##### Linux
204
-
205
- ###### Debian / Ubuntu
35
+ oswitch first requires a [working docker install](https://github.com/wurmlab/Dockerfiles).
206
36
 
37
+ #### On Ubuntu
207
38
  A `deb` package of `oswitch` is available in BioLinux repository for Trusty,
208
- Vivid and Jessie.
39
+ Vivid and Jessie. This will install oswitch systemwide:
209
40
 
210
- $ sudo add-apt-repository ppa:nebc/biolinux
41
+ $ sudo add-apt-repository ppa:nebc/bio-linux
211
42
  $ sudo apt-get update
212
43
  $ sudo apt-get install oswitch
213
44
 
214
- ###### Others
215
-
216
- Requirements: Ruby 2.0 or higher.
217
-
218
- $ gem install oswitch
219
-
220
- Depending on whether Ruby is installed systemwide (via your package-manager) or
221
- only for your user, this will install `oswitch` systemwide or only for your
222
- user.
45
+ #### Using [homebrew](http://brew.sh/) (on Mac)
46
+ Depending on whether homebrew is installed systemwide or only for your user,
47
+ this will install oswitch systemwide or only for your user:
223
48
 
224
- #### Test oswitch
49
+ brew tap homebrew/science
50
+ brew install oswitch
225
51
 
226
- $ oswitch ubuntu:14.04
52
+ #### Using RubyGems (on Linux & Mac)
227
53
 
228
- ## Install and setup docker
54
+ Requirements: Ruby 2.0 or higher (available by default on Mac and through
55
+ package managers on Linux). This will install oswitch systemwide:
229
56
 
230
- ##### Mac OS X
57
+ $ sudo gem install oswitch
231
58
 
232
- Installing docker is much easier than before - https://docs.docker.com/installation/mac/
233
-
234
- ##### Ubuntu
235
-
236
- Installing docker - https://docs.docker.com/installation/ubuntulinux/
237
-
238
- Add yourself to docker group so you can run docker client without sudo:
239
-
240
- ```shell
241
- $ sudo usermod -aG docker `whoami`
242
-
243
- # then logout and login again for the above command to take effect
244
- ```
245
-
246
- ##### CentOS
59
+ ## Usage note
247
60
 
248
- Installing docker - https://docs.docker.com/installation/centos/
249
-
250
- Add yourself to docker group so you can run docker client without sudo:
251
-
252
- ```shell
253
- $ sudo usermod -aG docker `whoami`
254
-
255
- # then logout and login again for the above command to take effect
256
- ```
257
-
258
- Disable SELinux as it gets in the way of mounting volumes within the container:
259
-
260
- ```shell
261
- $ sed -i .bak 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
262
-
263
- # then reboot your system
264
- ```
265
-
266
- The above command backs up the original file to `/etc/selinux/config.bak`. If
267
- you are concerned about disabling SELinux, do note that we are trying to work
268
- out a better solution.
269
-
270
- #### Test that docker is correctly installed
271
-
272
- The following should give an encouraging message:
273
-
274
- $ docker run hello-world
61
+ * [Volume mounting on Mac OS hosts is imperfect](#q-directories-mounted-within-container-on-mac-host-are-empty).
62
+ * SELinux must be disabled on CentOS hosts for mounting volumes to work (check
63
+ the SELinux documentation to see the implications of doing this).
64
+ * We have tested oswitch on Debian, Ubuntu, CentOS based docker images on the
65
+ following hosts:
66
+ * Mac OS X Yosemite, El Captain
67
+ * Ubuntu 14.04.1
68
+ * CentOS 7
275
69
 
276
70
  ## FAQ
277
71
 
@@ -316,19 +110,8 @@ We create a new image on the fly that inherits from the given image. While creat
316
110
  the new image we execute a shell script that installs packages required for
317
111
  oswitch to work and creates a user in the image (almost) identical to that on the host.
318
112
 
319
- ## Roadmap
320
-
321
- 1. ~~make it possible to use docker containers without inheriting our
322
- current baseimage~~
323
- 2. ~~gem distribution for easier installation~~
324
- 3. ~~brew recipe for Mac~~
325
- 4. ~~deb package~~
326
- 5. test on QMUL's compute cluster
327
- 6. make available images for common bioinformatics software
328
- 7. deploy at [RAL/JASMIN](http://www.jasmin.ac.uk)
329
- 8. create an SELinux policy to run oswitch on CentOS without having to disable
330
- SELinux entirely
331
- 9. rpm package
113
+ ##### Q. How can I connect to an existing container?
114
+ In another shell, use `docker ps` to see which containers are already running. Copy the identifier from the `CONTAINER ID` (column this looks something like `37e4e6ada6a4`), and use it to run `docker attach 37e4e6ada6a4` (replace with your container's id). This will create a new ssh connection to your existing container.
332
115
 
333
116
  ## Contribute
334
117
 
@@ -47,6 +47,13 @@ if options[:list]
47
47
  exit
48
48
  end
49
49
 
50
- package = ARGV[0]
51
- command = ARGV[1..-1]
52
- OSwitch.to(package, command)
50
+ pattern = ARGV[0].strip
51
+ command = ARGV[1..-1].join(' ')
52
+ matches = OSwitch.packages.grep(/#{pattern}/)
53
+
54
+ if matches.length > 1
55
+ puts "Which one of the following did you mean?"
56
+ puts matches.join(', ')
57
+ else
58
+ OSwitch.to(matches.first || pattern, command)
59
+ end
@@ -40,8 +40,8 @@ class OSwitch
40
40
  end
41
41
 
42
42
  def initialize(package, command = [])
43
- @package = package.strip
44
- @command = command.join(' ')
43
+ @package = package
44
+ @command = command
45
45
  @imgname = "oswitch_#{@package}"
46
46
  @cntname = "#{@package.gsub(%r{/|:}, '_')}-#{Process.pid}"
47
47
  exec
@@ -51,9 +51,19 @@ class OSwitch
51
51
 
52
52
  def exec
53
53
  ping and build and switch
54
- rescue ENODKR, ENOPKG => e
54
+ rescue ENODKR => e
55
55
  puts e
56
56
  exit
57
+ rescue => e
58
+ puts <<MSG
59
+
60
+ Ouch! Looks like you have hit a bug. Please could you post the error report
61
+ below to our issue tracker (https://github.com/wurmlab/oswitch/issues):
62
+
63
+ #{e}\n#{e.backtrace.join("\n")}
64
+
65
+ MSG
66
+ exit
57
67
  end
58
68
 
59
69
  private
@@ -1,14 +1,4 @@
1
1
  class OSwitch
2
- class ENOPKG < StandardError
3
- def initialize(name)
4
- @name = name
5
- end
6
-
7
- def to_s
8
- "Recipe to run #@name not available."
9
- end
10
- end
11
-
12
2
  class ENODKR < StandardError
13
3
  def to_s
14
4
  "***** Docker not installed / correctly setup / running.
@@ -1,10 +1,23 @@
1
+ require 'English'
2
+
1
3
  class OSwitch
2
4
  # Get OS specific info. Like, what directories to mount in the container,
3
- # current user, home directory.
5
+ # current user, home directory, etc.
4
6
  #
5
7
  # This module first defines methods common to Linux and Darwin, then does
6
8
  # OS detection and loads OS specific code.
7
9
  module OS
10
+ # Return `true` if the given command exists and is executable.
11
+ def self.command?(command)
12
+ system("which #{command} > /dev/null 2>&1")
13
+ end
14
+
15
+ def self.outputof(command)
16
+ output = `#{command} 2> /dev/null`.chomp
17
+ raise unless $CHILD_STATUS.success?
18
+ output
19
+ end
20
+
8
21
  def username
9
22
  ENV['USER']
10
23
  end
@@ -21,13 +34,13 @@ class OSwitch
21
34
  Dir.pwd
22
35
  end
23
36
 
24
- # Detect Linux or Darwin and load OS specific code. Following methods are
25
- # added:
37
+ # Detect Linux or Darwin and load OS specific code. Following
38
+ # methods are added:
26
39
  #
27
40
  # uid, gid, mountpoints
28
41
  #
29
42
  # NOTE:
30
- # This won't work on JRuby, as it sets RUBY_PLATFORM to 'java'.
43
+ # This won't work on JRuby as it sets RUBY_PLATFORM to 'java'.
31
44
  case RUBY_PLATFORM
32
45
  when /linux/
33
46
  require_relative 'os/linux'
@@ -11,20 +11,34 @@ class OSwitch
11
11
  usr|var|Volumes$)
12
12
  }x
13
13
 
14
- def uid
15
- `boot2docker ssh id -u`.chomp
16
- end
17
-
18
- def gid
19
- `boot2docker ssh id -g`.chomp
20
- end
21
-
22
14
  def mountpoints
23
15
  volumes = Dir['/Volumes/*'].map {|v| File.symlink?(v) ? File.readlink(v) : v}
24
16
  volumes = volumes | Dir['/*']
25
17
  volumes.reject! { |mount| mount =~ BLACKLIST }
26
18
  volumes << home
27
19
  end
20
+
21
+ if OS.command?('docker-machine')
22
+ def uid
23
+ OS.outputof('docker-machine ssh default id -u')
24
+ end
25
+
26
+ def gid
27
+ OS.outputof('docker-machine ssh default id -g')
28
+ end
29
+ else
30
+ def uid
31
+ puts <<WARN
32
+ 'boot2docker' has been deprecated in favour of 'docker-machine'. Please upgrade
33
+ via the Docker Toolbox (https://docker.com/toolbox).
34
+ WARN
35
+ OS.outputof('boot2docker ssh id -u')
36
+ end
37
+
38
+ def gid
39
+ OS.outputof('boot2docker ssh id -g')
40
+ end
41
+ end
28
42
  end
29
43
  end
30
44
  end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  # meta
3
3
  s.name = 'oswitch'
4
- s.version = '0.2.6'
4
+ s.version = '0.2.7'
5
5
  s.authors = ['Anurag Priyam', 'Bruno Vieira', 'Yannick Wurm']
6
6
  s.email = ['anurag08priyam@gmail.com']
7
7
  s.homepage = 'https://github.com/yeban/oswitch'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oswitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anurag Priyam
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-09-15 00:00:00.000000000 Z
13
+ date: 2017-06-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: colorize
@@ -70,10 +70,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
70
  version: '0'
71
71
  requirements: []
72
72
  rubyforge_project:
73
- rubygems_version: 2.4.2
73
+ rubygems_version: 2.5.2
74
74
  signing_key:
75
75
  specification_version: 4
76
76
  summary: Use docker image as the host operating system's user and access host operating
77
77
  system's filesystem.
78
78
  test_files: []
79
- has_rdoc: