2 posts

AWS Elastic Beanstalk - No carriage returns in Dockerfile

AWS Elastic Beanstalk has a very good Docker support. But for Dockerfile, you need to make sure no carriage return (CR) is in the Dockerfile, only line feed (LF) should be used. Otherwise, you may find weird issues.

For example, a simple Dockerfile as below,

FROM ubuntu:14.04  

If a CR is the last character in first line, Beanstalk will have error like repository not found ubuntu:14.04. This is because Beanstalk uses ubuntu:14.04<CR> as the repository name. So CR cannot be used in Dockerfile.

On Windows platform, Notepad++ can be used to find CR and remove them.

Deploy Static Website Using Capistrano

Capistrano is a good tool for deploying applications. It can deploy Ruby on Rails applications and other applications. This article is to show you how to use Capistrano to deploy a static website. The deployment process is very simple, just check out the code from Git and put into a directory hosted by Apache.

Prepare your local environment

On your local development environment, install Capistrano using gem install capistrano.

Prepare your remote environment

Remote environment is where the application is deployed to. Add user deploy to your remote environment. This user deploy is the user Capistrano runs.

adduser deploy  
passwd -l deploy  

Make sure Git is installed on the server. Create a SSH key for user deploy and add the public key as the deployment key of your Git repository (GitHub or Bitbucket). This allows user deploy to check out code.

Create the directory for the static website, e.g. /var/www/myapplication and make sure user deploy has write permission to this directory. Then update Apache config to add a virtual host for the website. Make sure /var/www/myapplication/current is used as the DocumentRoot. The current sub-directory contains current version of code.

<VirtualHost *:80>  

  ServerAdmin webmaster@localhost
  DocumentRoot /var/www/myapplication/current

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

Get SSH public key of your local environment and add this key to ~/.ssh/authorized_keys of user deploy. By doing this, you can run command on your local environment to trigger operations on the remote server.

Prepare the application

Run cap install on your application directory to create sample config files. This will create deploy directory in your application. By default, there are two environments, staging and production. Modify config/deploy/staging.rb or config/deploy/production.rb to update environment config.

Below is a sample of config/deploy/staging.rb file for a static website.

role :app, %w{}  
role :web, %w{}  
role :db,  %w{}  

Update config/deploy.rb to add the deployment logic.

lock '3.2.1'

set :application, 'myapplication'  
set :repo_url, ''

set :deploy_to, '/var/www/myapplication'

set :scm, :git  


Run cap staging deploy or cap production deploy to deploy to staging or production environment.