Skip to content

Commit

Permalink
Merge pull request #3 from JonathonReinhart/add-aliases
Browse files Browse the repository at this point in the history
Add support for aliases
  • Loading branch information
JonathonReinhart committed Dec 20, 2015
2 parents 4fac9b5 + eccc903 commit 41ce693
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ To uninstall:

Configuration is done using a [YAML](http://yaml.org/) file named `.scuba.yml` in the root
directory of your project. It is expected that `.scuba.yml` be checked in to version control.
`.scuba.yml` currently has one required node:

Required nodes:

- `image` - The Docker image to run

Optional nodes:

- `aliases` - A dictionary of bash-like aliases

A `.scuba.yml` file might look like this:
An example `.scuba.yml` file might look like this:

```yaml
image: gcc:5.1
aliases:
build: make -j4
```
This tells SCUBA:
- Use the `gcc:5.1` Docker image
- Run whatever is specified by the user on the command-line inside a container
- `build` is an alias for `make -j4`.
In this example, `scuba build foo` would execute `make -j4 foo` in a `gcc:5.1` container.

## License

Expand Down
2 changes: 2 additions & 0 deletions example/.scuba.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
image: busybox:latest
aliases:
build: ./do_build.sh arguments from "scuba 'build' alias"
13 changes: 12 additions & 1 deletion example/run_example.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#!/bin/bash

cd $(dirname $0)

export PATH="../src:$PATH"

scuba /bin/sh ./do_build.sh "here are args" from user "via scuba invocation"

# Run ./do_build.sh inside of a container,
# using the image specified in .scuba.yml
scuba ./do_build.sh "here are args" from user "via scuba invocation"

echo ""

# This invocation runs an alias named 'build'
scuba build "and more args" from "the command-line"

14 changes: 12 additions & 2 deletions src/scuba
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def load_config():
sys.exit(2)

required_nodes = ('image',)
optional_nodes = ()
optional_nodes = ('aliases',)

# Check for missing required nodes
missing = [n for n in required_nodes if not n in config]
Expand All @@ -50,6 +50,16 @@ def load_config():

return config

def process_command(config, command):
if command:
rep = config['aliases'].get(command[0])
if rep:
command.pop(0)
command = shlex.split(rep) + command

return command


def make_vol_opt(hostdir, contdir, options=None):
'''Generate a docker volume option'''
vol = '--volume={0}:{1}'.format(hostdir, contdir)
Expand Down Expand Up @@ -97,7 +107,7 @@ def main():
config['image'],
]

run_args += args.command
run_args += process_command(config, args.command)

#from pprint import pprint; pprint(run_args)
#return 42
Expand Down

0 comments on commit 41ce693

Please sign in to comment.