-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Charles Pritchard edited this page Apr 28, 2014
·
1 revision
$ ssh root@do2 root@do2:~# cd ~/service/nginx
The interactive shell script is meant as a last resort/last place of tweaking when working with an installation. The command it spits to stdout runs a docker container with no networking. We may want to have "socat" and dnsmasq as standard components in the base image, in the future.
root@do2:~/service/nginx# ./cli/sh nginx
docker run -v /root:/riplet:ro -e RIPLET_HOME=/riplet -n=false -dns 0.0.0.0 -t -i foldersio-dev /bin/bash -c "/riplet/service/nginx/cli/ubuntu/deps && /riplet/service/nginx/make && exec /bin/bash"
### Breaking it down
"-v /root:/riplet:ro -e RIPLET_HOME=/riplet"
mount host "/root" to container "/riplet" read only, set an environment variable in the container.
"-n=false -dns 0.0.0.0"
disable network mapping, set dns resolution to the loopback device.
"-t -i foldersio-dev"
create an interactive terminal using foldersio-dev as the base image.
" /bin/bash -c "/riplet/service/nginx/cli/ubuntu/deps && /riplet/service/nginx/make && exec /bin/bash" "
run bash in the container, running our standard ubuntu scripts, then the make command for nginx and return to us an interactive bash terminal.
~~~~ running an instance:
The docker script is intended as a production-capable command. We do not have the concept of start/stop, merely "create" and "kill". Docker creates a running container. Once running this command the instance will be visible via "docker ps".
root@do2:~/service/nginx# ./cli/docker nginx
docker run -n=false -dns 0.0.0.0 -cidfile /tmp/tmp.0KJxtkw1QJ/nginx.docker -v /tmp/tmp.0KJxtkw1QJ:/data/instance:rw -v /root:/riplet:ro -e RIPLET_HOME=/riplet -e RIPLET_INSTANCE=/data/instance -d foldersio-dev /riplet/service/nginx/init
### Breaking it down
## See the command on interactive shell, mounting the /riplet directory read only and disabling networking.
"-cidfile /tmp/tmp.0KJxtkw1QJ/nginx.docker"
Create a pid file on our host system for this running container.
"-v /tmp/tmp.0KJxtkw1QJ:/data/instance:rw -e RIPLET_INSTANCE=/data/instance"
Mount host "/tmp" directory as "/data/instance" read-write and set an environment variable in the instance.
"-d foldersio-dev /riplet/service/nginx/init"
Using foldersio-dev as a base image, run the init command. This command will run daemontools svscanboot as its final state.
~~~~ building an instance:
Before you run an instance, you're going to want to build it. This is handled in three build steps.
root@do2:~/service/nginx# ./cli/annex
/tmp/tmp.Ig3bNWp39M/nginx.sh
/tmp/tmp.mwBJd7ReEo/nginx.sh
/tmp/tmp.W7ic5pojUg/nginx.sh
### Step #1: Run image-dependent package commands. With ubuntu this means running "apt-get" on any dependencies listed.
"-v /root:/riplet:rw -e RIPLET_HOME=/riplet -e RIPLET_ANNEX_APT=/riplet/annex/ubuntu"
Note that our "/riplet" directory is mounted read-write.
"-e APT_DEPS="/riplet/service/nginx/ubuntu/make.apt"
At the end of step #1, any dependencies in "make.apt" are available in our "annex/ubuntu" directory.
### Step #2: Run standard fetch commands for "git clone" and "curl -O".
"-e RIPLET_ANNEX_GITHUB=/riplet/annex/github -e GITHUB_DEPS=/riplet/service/nginx/ubuntu/build.github"
We hard-code support for https://github.com
"-e RIPLET_ANNEX_URI=/riplet/annex/uri -e URI_DEPS=/riplet/service/nginx/ubuntu/build.uri"
http(s) uris are supported through the uri annex.
### Step #3: Run build and package to annex generated files.
"-e RIPLET_HOME=/riplet -v /root:/riplet:ro"
Note that our "/riplet" directory is mounted read-only -- not read-write.
"-n=false -dns 0.0.0.0"
Disable networking, we use our github, uri and ubuntu annex folders from here.
"-v /tmp/tmp.W7ic5pojUg:/data/instance:rw -e RIPLET_INSTANCE=/data/instance"
Mount our annex folder as we typically do.
"git bundle create /tmp/tmp.W7ic5pojUg/nginx.git --branches > /dev/null 2>&1;"
Once the command has run, we save a copy of the git repo we used to build it.
"mkdir -p /root/annex/nginx; mv /tmp/tmp.W7ic5pojUg/nginx /root/annex/nginx/ubuntu;"
We move our generated /data/instance folder into the annex.
Some of these steps have if statements to allow them to skip over commands if the resulting files already exist in the annex.
~~~~ wrap-up
With the three annex commands you are able to cache all needed packages and resources in order to build and deploy the service.
With the docker command you can deploy the service and with the sh command you can simply test the service -- you will likely want to cut out the commands which disable networking and add on the ubuntu deps redirection items, when running ./sh as you will want tools at your disposal.
The goal of these scripts is to build a sustainable, traceable annex folder and to run services in isolated containers.
-Charles