github.com/dahs81/otto@v0.2.1-0.20160126165905-6400716cf085/website/source/intro/getting-started/dev.html.md (about)

     1  ---
     2  layout: "intro"
     3  page_title: "Develop"
     4  sidebar_current: "gettingstarted-dev"
     5  description: |-
     6    Create a development environment with Otto in the Otto getting started guide.
     7  ---
     8  
     9  # Develop
    10  
    11  Let's start a development environment for our example application.
    12  Run the following commands in your terminal:
    13  
    14  ```
    15  $ git clone https://github.com/hashicorp/otto-getting-started.git
    16  $ cd otto-getting-started
    17  $ otto compile
    18  $ otto dev
    19  ```
    20  
    21  Now imagine every project being this easy to get started with.
    22  
    23  If this is your first time running this command, Otto may have asked for
    24  permission to install [Vagrant](https://www.vagrantup.com), which it uses
    25  under the covers. In this case, it may have also installed
    26  [VirtualBox](http://www.virtualbox.org) as well as a fairly
    27  large (~350 MB) base image for your environment. This is a one time cost.
    28  
    29  ## Layers
    30  
    31  The whole process to go from nothing to development environment probably
    32  took about 5 minutes. In the output, you may have noticed messages about
    33  creating "layers." Otto uses layered development environments and caches
    34  the layers to make future `otto dev` calls fast.
    35  
    36  If you `otto dev` another Ruby environment or destroy this environment and
    37  bring it back up, it'll only take about 30 seconds. This is because it is
    38  re-using the layers it already created.
    39  
    40  You'll only periodically run this command to start an environment, so performance
    41  here isn't critically important, but you can still tear down and bring up
    42  a new environment in less than a minute.
    43  
    44  ## Verifying It Worked
    45  
    46  If you inspect the repository you cloned, you'll notice that there
    47  isn't any configuration for Otto. For simple cases, Otto doesn't need
    48  any configuration. Otto detected the application is a Ruby application
    49  and automatically built us an environment tailored to Ruby development.
    50  
    51  Before we explain in more detail what happened, let's start the application.
    52  
    53  ```
    54  $ otto dev ssh
    55  > bundle && rackup --host 0.0.0.0
    56  ...
    57  ```
    58  
    59  Then, in another terminal, run `otto dev address` to get the address
    60  of your development environment. Visit port 9292 of that address in your
    61  browser. At the time of writing this, mine is "172.16.1.137:9292".
    62  You should see the application running!
    63  
    64  <center>
    65  <img src="/assets/images/getting-started/dev-screenshot.png">
    66  </center>
    67  
    68  Let's go over what just happened, step-by-step.
    69  
    70  ## Compilation
    71  
    72  The first thing we ran was `otto compile`. This is the key magical step
    73  of Otto. Otto inspects your environment and your configuration (if you
    74  have one), and compiles this data into dozens of output files that
    75  are used to develop and deploy your application.
    76  
    77  For our example, `otto compile` detected our application is Ruby and used
    78  opinionated defaults for the rest. In a future step, we'll write an
    79  [Appfile](/docs/appfile/index.html) to more precisely configure Otto.
    80  
    81  You can see the result of the compilation in the ".otto" directory, which
    82  probably looks something like this:
    83  
    84  ```
    85  $ tree .otto
    86  .otto
    87  ├── appfile
    88  │   ├── Appfile.compiled
    89  │   └── version
    90  ├── compiled
    91  │   ├── app
    92  │   │   ├── build
    93  │   │   │   ├── build-ruby.sh
    94  │   │   │   └── template.json
    95  │   │   ├── deploy
    96  │   │   │   └── main.tf
    97  │   │   ├── dev
    98  │   │   │   └── Vagrantfile
    99  ...
   100  
   101  24 directories, 41 files
   102  ```
   103  
   104  With zero configuration, Otto generated dozens of configurations for
   105  other battle-hardened software that will build development environments,
   106  start servers, deploy the application, and more. Otto automatically manages
   107  and orchestrates all of this software, so you don't have to.
   108  
   109  This is the beauty of Otto: with a simple input and workflow, Otto manages
   110  tried and true software under the covers to develop and deploy your
   111  application using industry best practices. You only need to learn how to
   112  use Otto, then Otto does the rest.
   113  
   114  For more information, see the [compilation concepts page](/docs/concepts/compile.html).
   115  
   116  -> **NOTE:** You never need to use the ".otto" directory manually. It is an
   117  internal directory that Otto uses. However, you can always inspect the
   118  compilation output to see how Otto will develop and deploy your application.
   119  
   120  ## Building the Development Environment
   121  
   122  Once compiled, we used `otto dev` to start a development environment.
   123  
   124  This built a local virtualized development environment, shared our application
   125  into that environment, and configured it with an address we can use to
   126  reach it from our machine.
   127  
   128  Because Otto detected our application is Ruby, Otto also automatically
   129  installed Ruby and Bundler, since those are usually required for every
   130  Ruby development environment. In a future step we'll see how to configure
   131  things such as the version of Ruby installed.
   132  
   133  At the end of the `otto dev` command, Otto outputs instructions for
   134  working with the development environment in green. These are also tailored
   135  specifically to your application type. These instructions change for PHP,
   136  Node, etc.
   137  
   138  As a reminder, Otto has done all of this _without any configuration_
   139  and in only a few commands. Otto just works.
   140  
   141  ## SSH and Shared Files
   142  
   143  While the development environment is assigned a unique address that we
   144  can use to reach it from your own machine, Otto has a shortcut for quickly
   145  opening an SSH terminal: `otto dev ssh`.
   146  
   147  This command automatically drops you into an SSH terminal within the
   148  local development environment, and also puts you in the working directory
   149  with your files. If you run `ls`, you'll see the repository contents:
   150  
   151  ```
   152  $ ls
   153  Gemfile		Gemfile.lock	README.md	app.rb		config.ru	views
   154  ```
   155  
   156  Otto also automatically sets up synced folders between the development
   157  environment and your machine. This allows you to edit files locally on
   158  your own machine with your own editor, and the changes quickly transfer
   159  into the development environment.
   160  
   161  Otto places you into this synced directory by default when you
   162  `otto dev ssh`.
   163  
   164  ## Application-Specific Software
   165  
   166  As mentioned earlier, Otto automatically installed Ruby and Bundler
   167  since it detected that this is a Ruby application. As next steps, we
   168  downloaded the dependencies for our application (using `bundle`)
   169  and started the application (with `rackup`):
   170  
   171  ```
   172  $ bundle && rackup --host 0.0.0.0
   173  Using rack 1.6.4
   174  Using rack-protection 1.5.3
   175  Using tilt 2.0.1
   176  Using sinatra 1.4.6
   177  Using bundler 1.7.6
   178  Your bundle is complete!
   179  Use `bundle show [gemname]` to see where a bundled gem is installed.
   180  [2042-01-01 12:55:28] INFO  WEBrick 1.3.1
   181  [2042-01-01 12:55:28] INFO  WEBrick::HTTPServer#start: pid=12965 port=9292
   182  ```
   183  
   184  If this environment were a PHP environment, we'd have PHP installed,
   185  if it were Node, we'd have Node and NPM installed, and so on. Otto
   186  automatically builds a development environment for your application.
   187  
   188  ## Development Environment Address
   189  
   190  Every development environment created by Otto is assigned a unique
   191  address so that you can access it from your own machine. You can retrieve
   192  this address easily with `otto dev address`:
   193  
   194  ```
   195  $ otto dev address
   196  172.16.1.137
   197  ```
   198  
   199  Your address output will likely be different.
   200  
   201  With the web server running from the previous step, you can use this
   202  address and port 9292 (the default listening port for this application)
   203  and view the running application.
   204  
   205  <center>
   206  <img src="/assets/images/getting-started/dev-screenshot.png">
   207  </center>
   208  
   209  ## Other Commands
   210  
   211  `otto dev` accepts a variety of subcommands. You can view them all by
   212  running `otto dev help`.
   213  
   214  Note that these commands can also change per application type. There aren't
   215  any right now for Ruby, but in the future you can imagine special commands
   216  that would open a Ruby console for us, automatically start our application,
   217  etc. Otto will add these over time.
   218  
   219  ## Next
   220  
   221  In this step, you learned how easy it is to use Otto. You experienced
   222  Otto compilation for the first time and also saw how Otto works with
   223  _zero configuration_. You hopefully are beginning to sense the power of
   224  Otto, even if we've only covered development so far.
   225  
   226  Next, we'll start the process of deploying this application by
   227  first [building an infrastructure](/intro/getting-started/infra.html)