Deploying Hugo on Bluemix
Ryan Tiffany Jun 8 '17
In today's post we will be showing how to deploy a Hugo site to Bluemix using the Cloud Foundry command line and build tools. This guide assumes that you have Hugo installed already. If this is not the case please see the Hugo Documentation for installing and configuring Hugo.
You will want to pick a Hugo theme and run a build so that your static files are sent to the
public folder. I am using the heather-hugo theme on my example site so the command is:
$ hugo -t heather-hugo
Once you have generated your static files you can move on to installing and configuring the Cloud Foundry cli to push your app to Bluemix.
Install and configure Bluemix Cloud Foundry cli
The installation will depend on your specific OS but you can use this page to get the command line interface installed. Once the install has completed you will need to login using the
$ cf login API endpoint: https://api.ng.bluemix.net Email> email@example.com Password> Authenticating... OK Targeted org dev_test Select a space (or press enter to skip): 1. dev 2. testingground Space> 1 Targeted space dev API endpoint: https://api.ng.bluemix.net (API version: 2.40.0) User: firstname.lastname@example.org Org: dev_test Space: dev
Create your manifest file
One of the most important requirements for a Cloud Foundry app is the
manifest.yml file. This file defines metadata about your application. More information about manifest files can be found here: Deploying with Application Manifests.
Here is my hugo app
applications: - path: public/ memory: 1024M instances: 1 name: hugo host: hugo disk_quota: 1024M buildpack: https://github.com/cloudfoundry-incubator/staticfile-buildpack.git
Here is the breakdown of the file:
- path: Specify what folder gets pushed. If not defined, defaults to the current directory.
- memory: Specify how much memory your application needs.
- instances: Specify the number of app instances that you want to start upon push.
- name: Name of your application.
- host: This defines the name for the subdomain (yourhost.myBluemix.net).
- buildpack: Specify what kind of buildpack your application needs. More information here: Cloud Foundry stacks
Push application to Bluemix
Now that we have all our ducks in a row we can push our application to Bluemix using the Cloud Foundry cli:
$ cf push hugo Using manifest file /Users/ryan/bluemix/cf-apps/hugo/manifest.yml Updating app hugo in org email@example.com / space dev as firstname.lastname@example.org... OK Using route hugo.testingbig.blue Uploading hugo... Uploading app files from: /Users/ryan/bluemix/cf-apps/hugo/public Uploading 78.9K, 23 files Done uploading OK Stopping app hugo in org email@example.com / space tinylab as firstname.lastname@example.org... OK Starting app hugo in org email@example.com / space tinylab as firstname.lastname@example.org... -----> Downloaded app package (40K) -----> Downloaded app buildpack cache (4.0K) Cloning into '/tmp/buildpacks/staticfile-buildpack'... Submodule 'compile-extensions' (https://github.com/cloudfoundry/compile-extensions.git) registered for path 'compile-extensions' Cloning into 'compile-extensions'... Submodule path 'compile-extensions': checked out '26a578c06a62c763205833561fec1c5c6d34deb6' -------> Buildpack version 1.3.1 Downloaded [https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/nginx/nginx-1.9.10-linux-x64.tgz] grep: Staticfile: No such file or directory -----> Using root folder -----> Copying project files into public/ -----> Setting up nginx grep: Staticfile: No such file or directory -----> Uploading droplet (2.6M) 0 of 1 instances running, 1 starting 1 of 1 instances running App started OK App hugo was started using this command `sh boot.sh` Showing health and status for app hugo in org email@example.com / space dev as firstname.lastname@example.org... OK requested state: started instances: 1/1 usage: 1G x 1 instances urls: hugo.mybluemix.net last uploaded: Thu Feb 25 17:19:03 UTC 2016 stack: cflinuxfs2 buildpack: https://github.com/cloudfoundry-incubator/staticfile-buildpack.git state since cpu memory disk details #0 running 2016-02-25 11:19:36 AM 0.0% 2.6M of 1G 5.6M of 1G
Create custom domain in Bluemix
For simple testing and proof of concept you can certainly keep using the
mybluemix.net domain, but if you are wanting to use this as a full time site you can configure Bluemix to use a custom domain. The first step to using your custom domain is to create the domain in Bluemix and associate it with an organization. The syntax is
cf create-domain ORG DOMAIN_NAME. In my case the ORG is tinylab and my domain is testingbig.blue:
$ cf create-domain [ORG] testingbig.blue Creating domain testingbig.blue for org tinylab as email@example.com... OK
In order to use your custom domain you have to map the domain to your Bluemix application using the
$ cf map-route hugo testingbig.blue Creating route testingbig.blue for org tinylab / space Production_US as firstname.lastname@example.org... OK
Point your custom domain to Bluemix
My domain testingbig.blue is currently using the SoftLayer DNS service so I added a record to point my domain to the Bluemix DNS system using the awesome SoftLayer CLI. Disclaimer: I Work at SoftLayer
$ slcli dns record-add hugo.testingbig.blue @ A 18.104.22.168
Push to Bluemix to use the Custom domain
In order to see the site at the new custom domain we'll go ahead and push the app again.
$ cf push hugo