= An Example cartage.yml
The best way to understand how to configure Cartage is to see an annotated
example of a +cartage.yml+ file.
== Secrets and cartage.yml
The items in the main part of the Cartage configuration are *not* generally
secret, but they are also not typically things that would be set in a static
configuration file. The main value that would probably be set under most
circumstances is the +name+ value.
Because Cartage reads its configuration through ERB, the following structure is
recommended for +config/cartage.yml+.
---
name: my-application
# This must not be indented for it to work.
<% if File.exist?('config/ansible/cartage.yml') %>
<%= File.read('config/ansible/cartage.yml') %>
<% end %>
<% if File.exist?('config/local/cartage.yml') %>
<%= File.read('config/local/cartage.yml') %>
<% end %>
== Main Cartage Configuration Options
=== +name+
The name of the application. Optional, defaults to the basename of the origin
Git URL. Overridden with cartage --name NAME.
name: my-application
=== +target+
The target path for the Cartage package. Optional and defaults to
./tmp. Overridden with cartage --target PATH.
target: tmp/cartage
=== +root_path+
The root path of the application. Optional, defaults to the top of the Git
repository (git rev-parse --show-cdup). Overridden with cartage
--root-path ROOT_PATH.
root_path: .
=== +timestamp+
The timestamp for the final package (which is
name-timestamp). Optional, defaults to the current
time in UTC. Overridden with cartage --timestamp TIMESTAMP. This
value is *not* validated to be a time value when supplied.
timestamp: not-a-timestamp
=== +bundle_cache+
The bundle cache path, where the package’s vendor-bundle.tar.bz2
will be stored between builds. Optional, defaults to ./tmp.
Overridden with cartage --bundle-cache BUNDLE_CACHE.
bundle_cache: tmp/cache
=== +without+
The groups to exclude from bundle install. Optional, defaults to [
"development", "test"]. Overridden with cartage --without
group1,group2.
without:
- development
- test
- other
=== +plugins+
A dictionary that contains all plug-in configuration, keyed by plug-in name.
== Cartage Plug-In Configuration Options
=== cartage-s3
Cartage-s3 needs to know where to put the completed package and how to log into
the selected storage provider.
==== +path+
The path to the cartage S3 bucket or directory (for another service that
Fog::Storage supports). This has no default and is overridden with cartage
s3 --path PATH.
plugins:
s3:
path: cartage-bucket
==== +credentials+
The credentials dictionary passed to Fog::Storage for uploads. Each provider
has different keys. If present, this will dictionary be used in preference to
cartage s3 flags --key-id, --secret-key, and
--region as those work *only* with Amazon AWS S3.
===== AWS
AWS S3 storage connections need +provider+, +aws_access_key_id+,
+aws_secret_access_key+, and +region+.
plugins:
s3:
credentials:
provider: AWS
aws_access_key_id: YOUR_AWS_ACCESS_KEY_ID
aws_secret_access_key: YOUR_AWS_SECRET_ACCESS_KEY
region: us-west-2
===== Rackspace
Rackspace storage connections need +provider+, +rackspace_username+,
+rackspace_api_key+, and optionally +rackspace_auth_url+.
plugins:
s3:
credentials:
provider: Rackspace
rackspace_username: RACKSPACE_USERNAME
rackspace_api_key: RACKSPACE_API_KEY
rackspace_auth_url: lon.auth.api.rackspacecloud.com
===== Google
Google storage connections need +provider+, +google_storage_access_key_id+, and
+google_storage_secret_access_key+.
plugins:
s3:
credentials:
provider: Google
google_storage_access_key_id: YOUR_SECRET_ACCESS_KEY_ID
google_storage_secret_access_key: YOUR_SECRET_ACCESS_KEY
=== cartage-remote
Cartage-remote needs to know where its remote build is going to run and how to
authenticate. It may also be told *what* to run. For cartage-remote 1.0, the
+remote+ configuration section is *required* (at least the +server+ key).
==== +server+
The name of the build server. This field is required and can show up in two
different formats. The first is as a string matching
[user@]host[:port].
plugins:
remote:
server: build@my-build-machine:2222
The second is as a dictionary with +user+, +host+, and +port+ keys.
plugins:
remote:
server:
user: build
host: my-build-machine
port: 2222
==== +keys+
The SSH key(s) used to connect to the server. Optional, and cartage-remote will
use ~/.ssh/*id_[rd]sa to find keys if this is not provided. The first
format is as a dictionary, embedding private keys directly in the configuration
file.
plugins:
remote:
keys:
custom: |
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
The second form is as an array of glob patterns to match key files.
plugins:
remote:
keys:
- "config/secrets/*id_[rd]sa"
- "~/.ssh/*id_[rd]sa"
The third form is as a single glob pattern to match key files or a specific key
file.
plugins:
remote:
keys: "config/secrets/*id_[rd]sa"
==== +build+
The build script that will be run on the remote server. This is optional with a
reasonable default, below.
#!/bin/bash
set -e
if [ -f Gemfile ]; then
bundle install --path %s
bundle exec cartage build \
--config-file %s \
--target %s
else
cartage build --config-file %s \
--target %s
fi
An example with an alternate build script that uses cartage-s3 to upload.
plugins:
remote:
build: |
#!/bin/bash
set -e
if [ -f Gemfile ]; then
bundle install --path %s
bundle exec cartage s3 \
--config-file %s \
--target %s \
--verbose
else
cartage build \
--config-file %s \
--target %s \
--verbose
fi
==== +prebuild+
The prebuild script that will be run on the local system. This is optional with
a reasonable default, below:
#!/bin/bash
ssh-keyscan -H %s >> ~/.ssh/known_hosts
An example with a slightly extended example is below. It is strongly
recommended that the ssh-keyscan step be run in all prebuild scripts
as cartage-remote runs SSH in a paranoid mode.
plugins:
remote:
prebuild: |
#!/bin/bash
ssh-keyscan -H %s >> ~/.ssh/known_hosts
echo 'Prebuild complete'
==== +postbuild+
The postbuild script that will be run on the local system. This is optional
with no default (no post-build actions).
The postbuild script will be passed the stage identifier as $1
(valid values are +config+, +ssh_config+, +prebuild+, +remote_clone+,
+remote_build+, +cleanup+, or +finished+). If the build was interrupted with
an error, the error message will be passed as $2.
An example that posts a message to Slack is below.
plugins:
remote:
postbuild: |
#!/bin/bash
case ${1:-undefined} in
finished)
t="token=SLACK_TOKEN"
c="channel=%23ci"
d=MYDOMAIN
u="https://${d}.slack.com/services/hooks/slackbot?${t}&${c}"
curl --data "Build %s-%s complete." ${u}
;;
*)
: # ${1} is the stage, ${2} is the error message
;;
esac