|
| 1 | +--- |
| 2 | +title: 'Singularity Compose: Orchestration for Singularity Instances' |
| 3 | +tags: |
| 4 | + - containers |
| 5 | + - singularity |
| 6 | + - linux |
| 7 | + - registry |
| 8 | +authors: |
| 9 | + - name: Vanessa Sochat |
| 10 | + orcid: 0000-0002-4387-3819 |
| 11 | + affiliation: 1 |
| 12 | +affiliations: |
| 13 | + - name: Stanford University Research Computing |
| 14 | + index: 1 |
| 15 | +date: 1 July 2019 |
| 16 | +bibliography: paper.bib |
| 17 | +--- |
| 18 | + |
| 19 | +# Summary |
| 20 | + |
| 21 | +Singularity Compose is an orchestration tool for management of Singularity containers. |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +The Singularity container technology started to become popular in 2016, |
| 26 | +as it offered a more secure option to run encapsulated environments [@Kurtzer2017-xj]. |
| 27 | +Traditionally, this meant that Singularity users could run an entrypoint built into the container |
| 28 | +(called a runscript), execute a custom command, or shell into a container. |
| 29 | +Unlike Docker, these basic interactions simply interacted with processes in the |
| 30 | +foreground (e.g., running a script and exiting) and were not appropriate to run |
| 31 | +background services. This was a task for container instances [@SingularityInstances] |
| 32 | +that were developed in the years to come. |
| 33 | + |
| 34 | +A container instance [@SingularityInstances] equates to running a container in a detached or |
| 35 | +daemon mode. It is a persistent version of the same container image that |
| 36 | +can also be isolated. Instances allow for running persistent services in the background, |
| 37 | +and then interaction with these services from the host and other containers. |
| 38 | +Examples of services include databases, web servers, and associated applications |
| 39 | +that interact with them. For sibling container technology Docker, an early solution, |
| 40 | +Docker Compose was developed to allow for simple orchestration |
| 41 | +on a host, meaning creation of a `docker-compose.yml` file to define services, |
| 42 | +volumes, ports exposed, and other customizations to networking and environment |
| 43 | +[@DockerCompose]. |
| 44 | + |
| 45 | +No equivalent orchestration tool has been created for Singularity container |
| 46 | +instances until now. While Singularity has empowered enterprise users to run |
| 47 | +services via platforms such as Kubernetes [@Meyer2019-sd], these platforms come |
| 48 | +with privilege. It is often the case that a production Kubernetes cluster is not |
| 49 | +readily available to a user via his or her institution, or that the user |
| 50 | +cannot pay a cloud provider to deploy one. However, this does not imply that |
| 51 | +a user that is not associated with an enterprise (e.g., an open source developer |
| 52 | +or academic) would not benefit from such an orchestration tool. This is a classic |
| 53 | +example of mismatched incentives. The company supporting Singularity is not |
| 54 | +incentivized to provide the tool, and so it is the responsibility of the open |
| 55 | +source community to step up. |
| 56 | + |
| 57 | + |
| 58 | +## Singularity Compose |
| 59 | + |
| 60 | +Singularity Compose [@SingularityCompose] is the solution for this niche group of non enterprise users |
| 61 | +that want to easily create a configuration file to control creation and interaction |
| 62 | +of services provided by Singularity container instances. It mirrors the format |
| 63 | +of the `docker-compose.yml` file with a `singularity-compose.yml`, and allows |
| 64 | +the user to define one or more container services, optionally with exposed ports |
| 65 | +to the host. Akin to docker-compose, the user can easily define volumes to be bound |
| 66 | +to each instance, along with ports to be exposed, and a container binary |
| 67 | +to build or pull from a remote resource. Custom scripts can also be defined to |
| 68 | +run after creation of the instances. Singularity Compose handles designation |
| 69 | +of addresses on a local bridge network for each container, and creation of |
| 70 | +resource files to bind to the container to "see" one another related to hostnames |
| 71 | +and networking. Importantly, by way of adding a Singularity Compose to a repository, |
| 72 | +a user is ensuring not just reproducibility of a container recipe, but also |
| 73 | +reproducibility of it's build and creation of services. For example, a |
| 74 | +sequence of steps for a single container to build it, assign an address, create networking |
| 75 | +files, and then start an instance might look like this: |
| 76 | + |
| 77 | +```bash |
| 78 | +$ sudo singularity build app/app.sif app/Singularity |
| 79 | +$ singularity instance start \ |
| 80 | + --bind etc.hosts:/etc/hosts \ |
| 81 | + --net --network-args "portmap=80:80/tcp" --network-args "IP=10.22.0.2" \ |
| 82 | + --hostname app \ |
| 83 | + --writable-tmpfs app.sif app |
| 84 | +``` |
| 85 | + |
| 86 | +In the above command, we've already generated the `etc.hosts` file that defines |
| 87 | +hostnames and addresses for other instances, along with a hostname `app` for |
| 88 | +the container we are starting. If we are running three services, we might need |
| 89 | +to do this three times, and be mindful of binds, ports, and additional arguments |
| 90 | +for each. With Singularity Compose, the user writes a `singularity-compose.yml` |
| 91 | +file once: |
| 92 | + |
| 93 | +```yaml |
| 94 | +version: "1.0" |
| 95 | +instances: |
| 96 | + |
| 97 | + nginx: |
| 98 | + build: |
| 99 | + context: ./nginx |
| 100 | + recipe: Singularity.nginx |
| 101 | + volumes: |
| 102 | + - ./nginx.conf:/etc/nginx/conf.d/default.conf |
| 103 | + - ./uwsgi_params.par:/etc/nginx/uwsgi_params.par |
| 104 | + - ./nginx/cache:/var/cache/nginx |
| 105 | + - ./nginx/run:/var/run |
| 106 | + ports: |
| 107 | + - 80:80 |
| 108 | + depends_on: |
| 109 | + - app |
| 110 | + volumes_from: |
| 111 | + - app |
| 112 | + |
| 113 | + app: |
| 114 | + build: |
| 115 | + context: ./app |
| 116 | + volumes: |
| 117 | + - ./app:/code |
| 118 | + - ./static:/var/www/static |
| 119 | + - ./images:/var/www/images |
| 120 | + ports: |
| 121 | + - 8000:8000 |
| 122 | +``` |
| 123 | +
|
| 124 | +And then can easily build all non-existing containers, and bring up all services |
| 125 | +with one command: |
| 126 | +
|
| 127 | +```bash |
| 128 | +$ singularity-compose up |
| 129 | +``` |
| 130 | + |
| 131 | +And then easily bring services down, restart, shell into a container, execute |
| 132 | +a command to a container, or run a container's internal runscript. |
| 133 | + |
| 134 | +```bash |
| 135 | +$ singularity-compose down # stop services |
| 136 | +$ singularity-compose restart # stop and start services |
| 137 | +$ singularity-compose shell app # shell into an instance |
| 138 | +$ singularity-compose exec app "Hello!" # execute a command |
| 139 | +$ singularity-compose run app # run internal runscript |
| 140 | +``` |
| 141 | + |
| 142 | +These interactions greatly improve both reproducibility and running of |
| 143 | +any development workflow that is not appropriate for an enterprise cluster but |
| 144 | +relies on orchestration of container instances. |
| 145 | + |
| 146 | +For the interested reader, the complete documentation for Singularity Compose [@SingularityCompose] |
| 147 | +is provided, along with the code on GitHub [@SingularityComposeGithub]. For |
| 148 | +additional walkthroughs and complete examples, we direct the reader to the examples |
| 149 | +repository, also on GitHub [@SingularityComposeExamples]. Contribution by way |
| 150 | +of additional examples, questions, or requests for development of a new example |
| 151 | +are appreciated and welcome. |
| 152 | + |
| 153 | + |
| 154 | +# References |
0 commit comments