github.com/jbramsden/hugo@v0.47.1/docs/content/en/hosting-and-deployment/deployment-with-nanobox.md (about)

     1  ---
     2  title: Host-Agnostic Deploys with Nanobox
     3  linktitle: Host-Agnostic Deploys with Nanobox
     4  description: Easily deploy Hugo to AWS, DigitalOcean, Google, Azure, and more...
     5  date: 2017-08-24
     6  publishdate: 2017-08-24
     7  lastmod: 2017-08-24
     8  categories: [hosting and deployment]
     9  keywords: [nanobox,deployment,hosting,aws,digitalocean,azure,google,linode]
    10  authors: [Steve Domino]
    11  menu:
    12    docs:
    13      parent: "hosting-and-deployment"
    14      weight: 05
    15  weight: 05
    16  sections_weight: 05
    17  draft: false
    18  aliases: [/tutorials/deployment-with-nanobox/]
    19  toc: true
    20  ---
    21  
    22  ![hugo with nanobox](/images/hosting-and-deployment/deployment-with-nanobox/hugo-with-nanobox.png)
    23  
    24  Nanobox provides an entire end-to-end workflow for developing and deploying applications. Using Nanobox to deploy also means you'll use it to develop your application.
    25  
    26  {{% note %}}
    27  If you're already using Nanobox and just need deployment instructions, you can skip to [Deploying Hugo with Nanobox](#deploying-hugo-with-nanobox)
    28  {{% /note %}}
    29  
    30  
    31  ## What You'll Need
    32  
    33  With Nanobox you don't need to worry about having Go or Hugo installed. They'll be installed as part of the development environment created for you.
    34  
    35  To get started you'll just need the following three items:
    36  
    37  * [A Nanobox Account](https://nanobox.io) - Signup is free
    38  * [Nanobox Desktop](https://dashboard.nanobox.io/download) - The free desktop development tool
    39  * An account with a hosting provider such as:
    40    - [AWS](https://docs.nanobox.io/providers/hosting-accounts/aws/)
    41    - [Google](https://docs.nanobox.io/providers/hosting-accounts/gcp/)
    42    - [Azure](https://docs.nanobox.io/providers/hosting-accounts/azure/)
    43    - [DigitalOcean](https://docs.nanobox.io/providers/hosting-accounts/digitalocean/)
    44    - [Linode](https://docs.nanobox.io/providers/hosting-accounts/linode/)
    45    - [More...](https://docs.nanobox.io/providers/hosting-accounts/)
    46    - [Roll Your Own](https://docs.nanobox.io/providers/create/)
    47  
    48  ### Before You Begin
    49  
    50  There are a few things to get out of the way before diving into the guide. To deploy, you'll need to make sure you have connected a host account to your Nanobox account, and launched a new application.
    51  
    52  #### Connect a Host Account
    53  
    54  Nanobox lets you choose where to host your application (AWS, DigitalOcean, Google, Azure, etc.). In the [Hosting Accounts](https://dashboard.nanobox.io/provider_accounts) section of your Nanobox dashboard [link your Nanobox account with your host](https://docs.nanobox.io/providers/hosting-accounts/).
    55  
    56  #### Launch a New Application on Nanobox
    57  
    58  [Launching a new app on Nanobox](https://docs.nanobox.io/workflow/launch-app/) is very simple. Navigate to [Launch New App](https://dashboard.nanobox.io/apps/new) in the dashboard, and follow the steps there. You'll be asked to name your app, and to select a host and region.
    59  
    60  With those out of the way you're ready to get started!
    61  
    62  
    63  ## Getting Started
    64  
    65  {{% note %}}
    66  If you already have a functioning Hugo app, you can skip to [Configure Hugo to run with Nanobox](#configure-hugo-to-run-with-nanobox)
    67  {{% /note %}}
    68  
    69  To get started, all you'll need is an empty project directory. Create a directory wherever you want your application to live and `cd` into it:
    70  
    71  `mkdir path/to/project && cd path/to/project`
    72  
    73  ### Configure Hugo to run with Nanobox
    74  
    75  Nanobox uses a simple config file known as a [boxfile.yml](https://docs.nanobox.io/boxfile/) to describe your application's infrastructure. In the root of your project add the following `boxfile.yml`:
    76  
    77  {{< code file="boxfile.yml" >}}
    78  run.config:
    79  
    80    # use the static engine
    81    engine: static
    82    engine.config:
    83  
    84      # tell the engine where to serve static assets from
    85      rel_dir: public
    86  
    87    # enable file watching for live reload
    88    fs_watch: true
    89  
    90    # install hugo
    91    extra_steps:
    92      - bash ./install.sh
    93  
    94  deploy.config:
    95  
    96    # generate site on deploy
    97    extra_steps:
    98      - hugo
    99  
   100  {{< /code >}}
   101  
   102  {{% note %}}
   103  If you already have a functioning Hugo app, after adding the boxfile, you can skip to [Deploying Hugo with Nanobox](#deploying-hugo-with-nanobox).
   104  {{% /note %}}
   105  
   106  ### Installing Hugo
   107  
   108  Nanobox uses Docker to create instant, isolated, development environments. Because of this, you'll need to make sure that during development you have Hugo available.
   109  
   110  Do this by adding a custom install script at the root of your project that will install Hugo automatically for you:
   111  
   112  {{< code file="install.sh" >}}
   113  
   114  #!/bin/bash
   115  
   116  if [[ ! -f /data/bin/hugo ]]; then
   117    cd /tmp
   118    wget https://github.com/gohugoio/hugo/releases/download/v0.31.1/hugo_0.31.1_Linux-64bit.tar.gz
   119    tar -xzf hugo_0.31.1_Linux-64bit.tar.gz
   120    mv hugo /data/bin/hugo
   121    cd -
   122    rm -rf /tmp/*
   123  fi
   124  
   125  {{< /code >}}
   126  
   127  {{% note %}}
   128  If the install script fails during `nanobox run` you may need to make it executable with `chmod +x install.sh`
   129  {{% /note %}}
   130  {{% note %}}
   131  Make sure to check the version of Hugo you have installed and update the install script to match.
   132  {{% /note %}}
   133  
   134  ### Generating a New Hugo App
   135  
   136  You'll generate your new application from inside the Nanobox VM (this is why you don't need to worry about having Go or Hugo installed).
   137  
   138  Run the following command to drop into a Nanobox console (inside the VM) where your codebase is mounted:
   139  
   140  ```
   141  nanobox run
   142  ```
   143  
   144  ![nanobox run](/images/hosting-and-deployment/deployment-with-nanobox/nanobox-run.png)
   145  
   146  Once inside the console use the following steps to create a new Hugo application:
   147  
   148  ```
   149  # cd into the /tmp dir to create an app
   150  cd /tmp
   151  
   152  # generate the hugo app
   153  hugo new site app
   154  
   155  # cd back into the /app dir
   156  cd -
   157  
   158  # copy the generated app into the project
   159  shopt -s dotglob
   160  cp -a /tmp/app/* .
   161  ```
   162  
   163  ### Install a theme
   164  
   165  `cd` into the `themes` directory and clone the `nanobox-hugo-theme` repo:
   166  
   167  ```
   168  cd themes
   169  git clone https://github.com/sdomino/nanobox-hugo-theme
   170  ```
   171  
   172  To use the theme *either* copy the entire `config.toml` that comes with the theme, or just add the theme to your existing `config.toml`
   173  
   174  ```
   175  # copy the config.toml that comes with the theme
   176  cp ./themes/nanobox-hugo-theme/config.toml config.toml
   177  
   178  # or, add it to your existing config.toml
   179  theme = "nanobox-hugo-theme"
   180  ```
   181  
   182  {{% note %}}
   183  It is not intended that you use the `nanobox-hugo-theme` as your actual theme. It's simply a theme to start with and should be replaced.
   184  {{% /note %}}
   185  
   186  ### View Your App
   187  
   188  To view your application simply run the following command from a Nanobox console:
   189  
   190  ```
   191  hugo server --bind="0.0.0.0" --baseUrl=$APP_IP
   192  ```
   193  
   194  ![hugo server](/images/hosting-and-deployment/deployment-with-nanobox/hugo-server.png)
   195  
   196  With that you should be able to visit your app at the given IP:1313 address
   197  
   198  {{% note %}}
   199  You can [add a custom DNS alias](https://docs.nanobox.io/cli/dns/#add) to make it easier to access your app. Run `nanobox dns add local hugo.dev`. After starting your server, visit your app at [hugo.dev:1313](http://hugo.dev:1313)
   200  {{% /note %}}
   201  
   202  ### Develop, Develop, Develop
   203  
   204  {{% note %}}
   205  IMPORTANT: One issue we are aware of, and actively investigating, is livereload. Currently, livereload does not work when developing Hugo applications with Nanobox.
   206  {{% /note %}}
   207  
   208  With Hugo installed you're ready to go. Develop Hugo like you would normally (using all the generators, etc.). Once your app is ready to deploy, run `hugo` to generate your static assets and get ready to deploy!
   209  
   210  
   211  ## Deploying Hugo with Nanobox
   212  
   213  {{% note %}}
   214  If you haven't already, make sure to [connect a hosting account](#connect-a-host-account) to your Nanobox account, and [launch a new application](#launch-a-new-application-on-nanobox) in the Dashboard.
   215  {{% /note %}}
   216  
   217  To deploy your application to Nanobox you simply need to [link your local codebase](https://docs.nanobox.io/workflow/deploy-code/#add-your-live-app-as-a-remote) to an application you've created on Nanobox. That is done with the following command:
   218  
   219  ```
   220  nanobox remote add <your-app-name>
   221  ```
   222  
   223  {{% note %}}
   224  You may be prompted to login using your ***Nanobox credentials*** at this time
   225  {{% /note %}}
   226  
   227  ### Stage Your Application (optional)
   228  
   229  Nanobox gives you the ability to [simulate your production environment locally](https://docs.nanobox.io/workflow/deploy-code/#preview-locally). While staging is optional it's always recommended, so there's no reason not to!
   230  
   231  To stage your app simply run:
   232  
   233  ```
   234  nanobox deploy dry-run
   235  ```
   236  
   237  Now visit your application with the IP address provided.
   238  
   239  ![nanobox deploy dry-run](/images/hosting-and-deployment/deployment-with-nanobox/nanobox-deploy-dry-run.png)
   240  
   241  ### Deploy Your Application
   242  
   243  Once everything checks out and you're [ready to deploy](https://docs.nanobox.io/workflow/deploy-code/#deploy-to-production), simply run:
   244  
   245  ```
   246  nanobox deploy
   247  ```
   248  
   249  Within minutes you're Hugo app will be deployed to your host and humming along smoothly. That's it!