Amazon S3 testing in Travis CI

I recently started integrating Travis CI into some of my projects. Travis is a continuous integration service that will execute your test cases in multiple different environments. I've been putting off integrating Transit into Travis because of Amazon S3 testing, but I found the time to dig into it and implement it successfully.

Preparing S3

To integrate S3 into Travis, the AWS environment must be prepared. This section can get quite lengthy and complicated, but I will keep it brief and simply. The first step is to create a new bucket and apply a lifecycle rule of 1 day to the entire bucket. This rule will delete all files in the bucket every 24 hours, which in turn requires no maintenance, cleanup and low costs on our end.

The next step is to create a new IAM group and assign the "Amazon S3 Full Access" policy permission. Once created, we need to modify the policy and change the permissions. I used the following policy for testing, which allows full S3 access to the ci-testing bucket.

{
	"Statement": [
		{
			"Effect": "Allow",
			"Action": "s3:*",
			"Resource": "arn:aws:s3:::ci-testing/*"
		}
	]
}

After the group is setup, create a new user and assign it to the group. Be sure to save/store the credentials (access and secret key) of the user as we will need them later on. It's also a good idea to set/generate a password for this user.

Integrating Travis

To make use of S3 in Travis, the appropriate variables must be set in the environment. This can be accomplished using the env:global: setting in the .travis.yml file. The region and bucket can be set using plain text.

env:
  global:
    - AWS_S3_REGION="us-east-1"
    - AWS_S3_BUCKET="ci-testing"

Like any smart developer, the access and secret keys should not be set using plain text, as this would give S3 access to anyone viewing the Travis logs. However, we can still set the private keys using encryption keys. This process requires Ruby and RubyGems to be installed (either with Cygwin, Homebrew or another package manager).

Installing RubyGems on Cygwin is rather easy. Simply download the zip and extract it to the C:/cygwin/home/ directory. Once extracted, run the following command from within the extracted folder (this requires ruby to be installed via the Cygwin setup).

ruby setup.rb

Once installed, install Travis.

gem install travis

Then use the encrypt command coupled with the -r flag (repository) to generate a secure environment key. In the example, I will be using my Transit repository.

travis encrypt -r milesj/Transit AWS_S3_KEY="<access_key>"

Add the encrypted string to the .travis.yml file. Do the process again for the secret key.

travis encrypt -r milesj/Transit AWS_S3_SECRET="<secret_key>"

The file should now look like the following:

env:
  global:
    - AWS_S3_REGION="us-east-1"
    - AWS_S3_BUCKET="ci-testing"
    - secure: "<encrypted_access_key>"
    - secure: "<encrypted_secret_key>"

These environment variables can now be accessed from the $_SERVER global within the test cases. For a full implemented example, check out my Transit library.

Changelogs: Utility v1.4.0

A new version of Utility has been released, version 1.4.0. Please download the new tag or view the documentation. If you have any questions, be sure to send me an email or comment on this post. If you run into any problems, be sure to report an issue on the Github repository.

Version: 1.4.0
Tested On: PHP 5.3.13, CakePHP 2.3.1, Composer
Requires: PHP 5.3, CakePHP 2, Composer
Commit Hash: b109b71a2d05e7b044d702c124f9faa4c4bb5771
Changes:

  • Added a BaseInstallShell and BaseUpgradeShell to handle plugin installs/upgrades
  • Added the SluggableBehavior instance as a second argument to the beforeSlug() and afterSlug() callbacks
  • Added a unique option to SluggableBehavior
  • Added append() and prepend() to BreadcrumbHelper
  • Added getCount as primary caching method in CacheableBehavior
  • Added default rule messaging fallbacks to ValidateableBehavior
  • Added getAll(), getList(), getCount(), getById() and getBySlug() to CacheableBehavior which can be called from the Model layer
  • Added Decoda configuration to Configure via plugin bootstrap
  • Added UtilityHelper to handle all purpose view functionality
  • Fixed a bug with SluggableBehavior wildcard behaving incorrectly
  • Fixed a bug where HTML is not stripped from breadcrumbs
  • Updated AutoLoginComponent to use the referrer as the auth login redirect
  • Updated SluggableBehavior to not sluggify a record if the slug is manually set in the data
  • Updated ValidateableBehavior to grab $validate and use as the default validation set
  • Updated EnumerableBehavior format setting to be APPEND by default instead of REPLACE
  • Updated Decoda to v6.0.0

Changelogs: Decoda v6.0.0

A new version of Decoda has been released, version 6.0.0. Please download the new tag or view the documentation. If you have any questions, be sure to send me an email or comment on this post. If you run into any problems, be sure to report an issue on the Github repository.

Version: 6.0.0
Tested On: PHP 5.3.13, Composer
Requires: PHP 5.3, Composer
Commit Hash: 70a679488d2be76c8f997f7bdcc0555871e7bfe2
Changes:

  • Added a Component class which all Filters, Hooks, Engines and Loaders extend
  • Added a Loader class to handle resource file loading for configuration and messages
  • Added Hook::startup() to initialize data before callbacks are called
  • Added Decoda::addMessages() to add messages using a Loader
  • Added Decoda::getBlacklist() and getWhitelist()
  • Added a 2nd argument $key for Decoda::addFilter() and addHook()
  • Added a default attribute to ImageFilter (img="200x200")
  • Added a default attribute to ListFilter (list="upper-roman")
  • Added a new TableFilter
  • Added custom exceptions
  • Renamed all config methods to getConfig() and setConfig()
  • Renamed Filter::tag() to getTag()
  • Renamed Filter::tags() to getTags()
  • Renamed Engine::setPath() to addPath()
  • Renamed Engine::getPath() to getPaths()
  • Updated CensorHook to support blacklisting words using a Loader
  • Updated EmoticonHook to support adding emoticons using a Loader
  • Updated Decoda::setLocale() so that it no longer throws exceptions (can now support setting the default locale)
  • Updated Engines to support multiple template lookup paths
  • Updated with Travis CI and phpunit.xml integration