|
| 1 | +# Getting Started |
| 2 | +----------------- |
| 3 | + |
| 4 | +Devstep comes in two flavors, you can either use the provided CLI or you can build |
| 5 | +on top of the provided images from `Dockerfile`s. |
| 6 | + |
| 7 | +Regardless of the flavor you choose, it is a good idea to `docker pull fgrehm/devstep:v0.0.1` |
| 8 | +before creating your first container / image for a better "user experience". |
| 9 | +Docker will download that image as needed but by pulling it first you'll reduce |
| 10 | +the waiting time when interacting with Devstep for the first time. |
| 11 | + |
| 12 | +## Sanity check |
| 13 | +--------------- |
| 14 | + |
| 15 | +This project is being developed and tested on an Ubuntu 14.04 host with Docker |
| 16 | +1.0.0+, while it is likely to work on other distros / Docker versions / |
| 17 | +[boot2docker](http://boot2docker.io/), I'm not sure how it will behave on the wild. |
| 18 | + |
| 19 | +## Using the CLI |
| 20 | +---------------- |
| 21 | + |
| 22 | +Before you try out the CLI, make sure you have Docker installed and that your |
| 23 | +user is capable to run `docker` commands [without `sudo`](http://docs.docker.io/installation/ubuntulinux/#giving-non-root-access). |
| 24 | + |
| 25 | +> **IMPORTANT**: The `developer` user that is used by Devstep assumes your user |
| 26 | +and group ids are equal to `1000` when using the CLI or the container's init |
| 27 | +process will be aborted. This is to guarantee that files created within Docker |
| 28 | +containers have the appropriate permissions so that you can manipulate them |
| 29 | +on the host without the need to use `sudo`. This is currently a Devstep limitation |
| 30 | +that will be worked around in case there is enough demand or will be fixed once |
| 31 | +Docker adds support for user namespaces ([#6600](https://github.com/dotcloud/docker/pull/6600) |
| 32 | +/ [#6602](https://github.com/dotcloud/docker/pull/6602) / [#6603](https://github.com/dotcloud/docker/pull/6603) |
| 33 | +/ [#4572](https://github.com/dotcloud/docker/pull/4572)). |
| 34 | + |
| 35 | +> The `1000` id was chosen because it is the default uid / gid of Ubuntu Desktop users |
| 36 | +that are created during the installation process. To work around this limitation, |
| 37 | +please build your own image using the appropriate ids and add a `DEVSTEP_SOURCE_IMAGE=<YOUR-IMAGE>` |
| 38 | +line to your `~/.devsteprc`. |
| 39 | + |
| 40 | +To install the CLI, you can run the one liner below and read on for more: |
| 41 | + |
| 42 | +```sh |
| 43 | +L=$HOME/bin/devstep && curl -sL https://github.com/fgrehm/devstep/raw/master/devstep > $L && chmod +x $L |
| 44 | +``` |
| 45 | + |
| 46 | +_The snippet above assumes `$HOME/bin` is on your PATH, please change `$HOME/bin` |
| 47 | +to an appropriate path in case your system is not configured like that._ |
| 48 | + |
| 49 | +### `devstep hack` |
| 50 | + |
| 51 | +This is the easiest way to get started with Devstep. By running the command |
| 52 | +from your project's root, Devstep will: |
| 53 | + |
| 54 | +1. Create a Docker container based on `fgrehm/devstep` with project sources bind |
| 55 | + mounted at `/workspace`. |
| 56 | +2. Detect and install project's dependencies on the new container using the |
| 57 | + available buildpacks. |
| 58 | +3. Start a `bash` session with everything in place for you to do your work. |
| 59 | + |
| 60 | +Once you `exit` the `bash` session, the container will be garbage collected |
| 61 | +(aka `docker rm`ed). |
| 62 | + |
| 63 | +In case you need to provide additional parameters to the underlying `docker run` |
| 64 | +command you can use the `-r` flag. For example, `devstep hack -r "-p 80:8080"` will |
| 65 | +redirect the `8080` port on your host to the port `80` within the container. |
| 66 | + |
| 67 | +### `devstep build` |
| 68 | + |
| 69 | +By running the command from your project's root, Devstep will: |
| 70 | + |
| 71 | +1. Create a Docker container based on `fgrehm/devstep` with project sources bind |
| 72 | + mounted at `/workspace`. |
| 73 | +2. Detect and install project's dependencies on the new container using the |
| 74 | + available buildpacks. |
| 75 | +3. `docker commit` the container to a `devstep/<PROJECT>:<TIMESTAMP>` image. |
| 76 | +4. `docker tag` the new image as `devstep/<PROJECT>:latest`. |
| 77 | + |
| 78 | +The `devstep/<PROJECT>` images act like snapshots of your project dependencies |
| 79 | +and will be used as the source image for subsequent `devstep` commands instead |
| 80 | +of the `fgrehm/devstep` image. |
| 81 | + |
| 82 | +For example, running a `devstep hack` after building the image will use `devstep/<PROJECT>:latest` |
| 83 | +as the base container for new "hacking sessions" so that you don't have to build |
| 84 | +your project's environment from scratch. The same applies for a new `devstep build`, |
| 85 | +which will build on top of the latest image reducing the overall build time when |
| 86 | +compared to reconfiguring the environment from scratch using |
| 87 | +`Dockerfile`s. |
| 88 | + |
| 89 | +Because the `build` command bind mounts your project sources on the Docker container |
| 90 | +during the configuration process, you'll have to provide the full path to sources |
| 91 | +on the host machine as a Docker volume in order to work on the project. |
| 92 | +`devstep hack` can take care of that for you or you can manually: |
| 93 | + |
| 94 | +```sh |
| 95 | +docker run -ti -v `pwd`:/workspace devstep/<PROJECT> |
| 96 | +``` |
| 97 | + |
| 98 | +### Bootstrapping a new project (AKA solving the chicken or the egg problem) |
| 99 | + |
| 100 | +Assuming you are willing to use Docker / Devstep to avoid cluttering your machine |
| 101 | +with development tools, there's no point on installing Ruby / Python / ... on your |
| 102 | +computer in order to scaffold a new project. To make that process easier, you can |
| 103 | +use the `devstep bootstrap` command. |
| 104 | + |
| 105 | +That command will start an interactive `bash` session with the current directory |
| 106 | +bind mounted as `/workspace` on the container and you'll be able to manually |
| 107 | +install packages / tools required to scaffold your new project. You can even |
| 108 | +force a specific buildpack to run from there. |
| 109 | + |
| 110 | +For example, scaffolding a new Rails project means: |
| 111 | + |
| 112 | +```sh |
| 113 | +cd $HOME/projects # or whatever directory you keep your projects |
| 114 | +devstep bootstrap -w my_app |
| 115 | + |
| 116 | +build-project -b ruby |
| 117 | +source $HOME/load-env.sh |
| 118 | +gem install rails |
| 119 | +rails new my_app |
| 120 | + |
| 121 | +exit # Or do some extra setup before exiting |
| 122 | +``` |
| 123 | + |
| 124 | +Once you `exit` the container, you should end up with a `devstep/my_app` image |
| 125 | +and a brand new Rails app under `$HOME/projects/my_app` on your machine. To |
| 126 | +abort the bootstrap process, just `exit 1` from within the container and answer |
| 127 | +'No' when asked for confirmation for commiting the image. |
| 128 | + |
| 129 | +As with `devstep build`, subsequent `devstep` commands like `build` and `hack` |
| 130 | +will use `devstep/my_app:latest` as the source image. Project sources |
| 131 | +also won't get stored inside the Docker image and you'll need to provide the |
| 132 | +full path to its sources on the host machine as a Docker volume in order to |
| 133 | +work on the project. `devstep hack` can take care of that for you or you can |
| 134 | +manually: |
| 135 | + |
| 136 | +```sh |
| 137 | +docker run -ti -v `pwd`:/workspace devstep/<PROJECT> |
| 138 | +``` |
| 139 | + |
| 140 | +To bootstrap projects for other platforms and frameworks you can follow a similar |
| 141 | +approach, replacing the Ruby / Rails specifics with the platform / framework |
| 142 | +of choice. |
| 143 | + |
| 144 | +### Caching project's dependencies packages on the host |
| 145 | + |
| 146 | +As mentioned on the [introduction](introduction) section, Devstep is also capable |
| 147 | +of reducing disk space and initial configuration times by caching packages on the |
| 148 | +host using a strategy similar to [vagrant-cachier's cache buckets](http://fgrehm.viewdocs.io/vagrant-cachier/how-does-it-work). |
| 149 | +This behavior is enabled by default and will be further documented on the future. |
| 150 | +For now you need to know that the `/tmp/devstep/cache` dir on the host will be bind |
| 151 | +mounted to containers created by the CLI under `/.devstep/cache` and most of your |
| 152 | +project's dependencies packages will be downloaded to there. Note that the dependencies |
| 153 | +themselves are extracted and kept inside the images built by the CLI and you can |
| 154 | +safely clean things up or disable the caching behavior at will. |
| 155 | + |
| 156 | +To disable the caching functionality you can add the `DEVSTEP_CACHE_PATH=""` |
| 157 | +line to your `~/.devsteprc`. |
| 158 | + |
| 159 | +### Other commands |
| 160 | + |
| 161 | +* `clean` -> Remove all images built for the current project |
| 162 | +* `pristine` -> Rebuild current project associated Docker image from scratch |
| 163 | +* `run` -> Run a one off command against the current source image |
| 164 | +* `images` -> Display images available for the current project |
| 165 | +* `ps` -> List all containers associated with the current project |
| 166 | +* `info` -> Show some information about the current project |
| 167 | + |
| 168 | +For the most up-to-date list of supported commands, run `devstep --help`. |
| 169 | + |
| 170 | + |
| 171 | +## Building images using `Dockerfiles` |
| 172 | +-------------------------------------- |
| 173 | + |
| 174 | +In case your project require additional stuff to work you can use the provided |
| 175 | +`fgrehm/devstep`, `fgrehm/devstep-ab` or `fgrehm/devstep-sa` images as a starting |
| 176 | +point for your `Dockerfile`s. |
| 177 | + |
| 178 | +The `fgrehm/devstep` image is the base image used for Devstep environments and |
| 179 | +requires you to manually trigger the build: |
| 180 | + |
| 181 | +```Dockerfile |
| 182 | +FROM fgrehm/devstep:v0.0.1 |
| 183 | + |
| 184 | +# Add project to the image and build it |
| 185 | +ADD . /workspace |
| 186 | +WORKDIR /workspace |
| 187 | +RUN CLEANUP=1 /.devstep/bin/build-project /workspace |
| 188 | +``` |
| 189 | + |
| 190 | +To make things easier, there's also a `fgrehm/devstep-ab:v0.0.1` image that |
| 191 | +does the same steps as outlined above automatically for you by leveraging `ONBUILD` |
| 192 | +instructions, trimming down your `Dockerfile` to a single line: |
| 193 | + |
| 194 | +```Dockerfile |
| 195 | +FROM fgrehm/devstep-ab:v0.0.1 |
| 196 | +``` |
| 197 | + |
| 198 | +And in case you want to run extra services (like a DB) within the same container |
| 199 | +of your project, you can use the `fgrehm/devstep-sa` image: |
| 200 | + |
| 201 | +```Dockerfile |
| 202 | +FROM fgrehm/devstep-sa:v0.0.1 |
| 203 | + |
| 204 | +# Add project to the image and build it |
| 205 | +ADD . /workspace |
| 206 | +WORKDIR /workspace |
| 207 | +RUN CLEANUP=1 /.devstep/bin/build-project /workspace |
| 208 | + |
| 209 | +# Configure PostgreSQL and Redis to run on the project's container |
| 210 | +RUN /.devstep/bin/configure-addons postgresql redis |
| 211 | +``` |
| 212 | + |
| 213 | +By using a `Dockerfile` to build your images (instead of using `devstep build`) |
| 214 | +you'll be able to skip mounting project's sources on the container when running |
| 215 | +it and a simple `docker run -it <IMAGE-NAME>` should do the trick. **_Keep in mind |
| 216 | +that changes made to project sources will be kept inside the container and |
| 217 | +you'll lose them when you `docker rm` it._** |
| 218 | + |
| 219 | + |
| 220 | +## Available buildpacks |
| 221 | +----------------------- |
| 222 | + |
| 223 | +* [Bats](https://github.com/fgrehm/devstep/tree/master/buildpacks/bats) |
| 224 | +* [Golang](https://github.com/fgrehm/devstep/tree/master/buildpacks/golang) |
| 225 | +* [Inline](https://github.com/fgrehm/devstep/tree/master/buildpacks/inline) |
| 226 | +* [NodeJS](https://github.com/fgrehm/devstep/tree/master/buildpacks/nodejs) |
| 227 | +* [PHP](https://github.com/fgrehm/devstep/tree/master/buildpacks/php) |
| 228 | +* [Python](https://github.com/fgrehm/devstep/tree/master/buildpacks/python) |
| 229 | +* [Ruby](https://github.com/fgrehm/devstep/tree/master/buildpacks/ruby) |
| 230 | + |
| 231 | + |
| 232 | +## More information |
| 233 | +------------------- |
| 234 | + |
| 235 | +If you reached this point it means you should have a good understanding of how |
| 236 | +Devstep works and what you can do with it. If you are still wondering how you can |
| 237 | +use the tool and / or benefit from it, please create a [new issue](https://github.com/fgrehm/devstep/issues/new) |
| 238 | +so that we can discuss how can we improve the docs :) |
0 commit comments