Skip to content

Commit cc339d8

Browse files
author
Matthew Fisher
committed
chore(builder): import deis/slugrunner
1 parent 30228c9 commit cc339d8

8 files changed

Lines changed: 195 additions & 0 deletions

File tree

builder/slugrunner/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

builder/slugrunner/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See the [Flynn contributing guide](https://flynn.io/docs/contributing)

builder/slugrunner/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM progrium/cedarish
2+
MAINTAINER Jonathan Rudenberg <jonathan@titanous.com>
3+
4+
ADD ./runner /runner
5+
ENTRYPOINT ["/runner/init"]
6+
7+
# add default port to expose (can be overridden)
8+
ENV PORT 5000
9+
EXPOSE 5000

builder/slugrunner/LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
Flynn is a trademark of Apollic Software, LLC.
2+
3+
Copyright (c) 2013-2014 Apollic Software, LLC. All rights reserved.
4+
5+
Redistribution and use in source and binary forms, with or without
6+
modification, are permitted provided that the following conditions are
7+
met:
8+
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above
12+
copyright notice, this list of conditions and the following disclaimer
13+
in the documentation and/or other materials provided with the
14+
distribution.
15+
* Neither the name of Apollic Software, LLC nor the names of its
16+
contributors may be used to endorse or promote products derived from
17+
this software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

builder/slugrunner/MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Jonathan Rudenberg <jonathan@titanous.com> (github: titanous)

builder/slugrunner/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
build/container: build/sdutil Dockerfile runner/*
2+
docker build -t flynn/slugrunner .
3+
touch build/container
4+
5+
build/sdutil:
6+
mkdir -p tmp
7+
cd tmp && git clone https://github.com/flynn/sdutil.git
8+
GOPATH=. cd tmp/sdutil && godep go build -o ../../build/sdutil
9+
rm -rf tmp
10+
11+
.PHONY: clean
12+
clean:
13+
rm -rf tmp build

builder/slugrunner/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# (Heroku-ish) Slug Runner
2+
A [Docker](http://docker.io) container that runs Heroku-like [slugs](https://devcenter.heroku.com/articles/slug-compiler) produced by [slugbuilder](https://github.com/flynn/slugbuilder).
3+
4+
## What does it do exactly?
5+
6+
It takes a gzipped tarball of a "compiled" application via stdin or from a URL, letting you run a command in that application environment, or start a process defined in the application Procfile.
7+
8+
## Using Slug Runner
9+
10+
First, you need Docker. Then you can either pull the image from the public index:
11+
12+
$ docker pull flynn/slugrunner
13+
14+
Or you can build from this source:
15+
16+
$ cd slugrunner
17+
$ make
18+
19+
When you run the container, it always expects an app slug to be passed via stdin or by giving it a URL using the SLUG_URL environment variable. Lets run a Rake task that our app uses, attaching to stdout:
20+
21+
$ cat myslug.tgz | docker run -i -a stdin -a stdout flynn/slugrunner rake mytask
22+
23+
We can also load slugs using the SLUG_URL environment variable. This is currently the only way to run interactively, for example running Bash:
24+
25+
$ docker run -e SLUG_URL=http://example.com/slug.tgz -i -t flynn/slugrunner /bin/bash
26+
27+
Commands are run in the application environment, in the root directory of the application, with any default environment variables, and scripts sourced from .profile.d of the application.
28+
29+
Lastly there is a `start` command that will run any of the process types defined in the Procfile of the app, or of the default process types defined by the buildpack that built the app. For example, here we can start the `web` process:
30+
31+
$ cat myslug.tgz | docker run -i -a stdin -a stdout -a stderr flynn/slugrunner start web
32+
33+
## Service Discovery
34+
35+
The runner can also register with [go-discover](https://github.com/flynn/go-discover) based service discovery using [sdutil](https://github.com/flynn/sdutil). If `$SD_NAME` and `$PORT` environment variables are set, the command is run with `sdutil exec $SD_NAME:$PORT`. `$SD_NAME` is unset before the command is run, but `$PORT` is left set since it is often used without service discovery.
36+
37+
It is also possible to fully customize the command line for `sdutil` tool using `$SD_ARGS`.
38+
39+
## Base Environment
40+
41+
The Docker image here is based on [cedarish](https://github.com/progrium/cedarish), an image that emulates the Heroku Cedar stack environment. App slugs should include everything they need to run, but if something is missing it should be added upstream to cedarish.
42+
43+
## License
44+
45+
BSD
46+
47+
## Flynn
48+
49+
[Flynn](https://flynn.io) is a modular, open source Platform as a Service (PaaS).
50+
51+
If you're new to Flynn, start [here](https://github.com/flynn/flynn).
52+
53+
### Status
54+
55+
Flynn is in active development and **currently unsuitable for production** use.
56+
57+
Users are encouraged to experiment with Flynn but should assume there are stability, security, and performance weaknesses throughout the project. This warning will be removed when Flynn is ready for production use.
58+
59+
Please report bugs as issues on the appropriate repository. If you have a general question or don't know which repo to use, report them [here](https://github.com/flynn/flynn/issues).
60+
61+
## Contributing
62+
63+
We welcome and encourage community contributions to Flynn.
64+
65+
Since the project is still unstable, there are specific priorities for development. Pull requests that do not address these priorities will not be accepted until Flynn is production ready.
66+
67+
Please familiarize yourself with the [Contribution Guidelines](https://flynn.io/docs/contributing) and [Project Roadmap](https://flynn.io/docs/roadmap) before contributing.
68+
69+
There are many ways to help Flynn besides contributing code:
70+
71+
- Fix bugs or file issues
72+
- Improve the [documentation](https://github.com/flynn/flynn.io) including this website
73+
- [Contribute](https://flynn.io/#sponsor) financially to support core development
74+
75+
Flynn is a [trademark](https://flynn.io/docs/trademark-guidelines) of Apollic Software, LLC.

builder/slugrunner/runner/init

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
## Load slug from Bind Mount, URL or STDIN
5+
6+
export HOME=/app
7+
mkdir -p $HOME
8+
9+
if [[ $(ls -A $HOME) ]]; then
10+
true
11+
elif [[ $SLUG_URL ]]; then
12+
curl -s "$SLUG_URL" | tar -xzC $HOME
13+
unset SLUG_URL
14+
else
15+
cat | tar -xzC $HOME
16+
fi
17+
cd $HOME
18+
19+
## Load profile.d and release config
20+
21+
shopt -s nullglob
22+
mkdir -p .profile.d
23+
if [[ -s .release ]]; then
24+
ruby -e "require 'yaml';(YAML.load_file('.release')['config_vars'] || {}).each{|k,v| puts \"#{k}='#{v}'\"}" > .profile.d/config_vars
25+
fi
26+
for file in .profile.d/*; do
27+
source $file
28+
done
29+
hash -r
30+
31+
## Inject "start" command to run processes defined in Procfile
32+
33+
case "$1" in
34+
start)
35+
if [[ -f Procfile ]]; then
36+
command="$(ruby -e "require 'yaml';puts YAML.load_file('Procfile')['$2']")"
37+
else
38+
command="$(ruby -e "require 'yaml';puts (YAML.load_file('.release')['default_process_types'] || {})['$2']")"
39+
fi
40+
;;
41+
42+
*)
43+
command="$@"
44+
;;
45+
esac
46+
47+
## Use sdutil to register with service discovery
48+
49+
if [[ $SD_NAME && $PORT ]]; then
50+
if [[ $SD_HOST ]]; then
51+
runner="sdutil exec -h $SD_HOST -s $SD_NAME:$PORT bash -c"
52+
unset SD_HOST
53+
else
54+
runner="sdutil exec -s $SD_NAME:$PORT bash -c"
55+
fi
56+
unset SD_NAME
57+
elif [[ $SD_ARGS ]]; then
58+
runner="sdutil $SD_ARGS bash -c"
59+
unset SD_ARGS
60+
else
61+
runner="bash -c"
62+
fi
63+
64+
## Run!
65+
66+
$runner "$command"

0 commit comments

Comments
 (0)