Ruby on Rails
This Ruby on Rails config example starts with a Tugboat Debian image, installs Ruby, and uses a Tugboat PostgreSQL image, adding and then removing permissions to create a database Rails-style. You’ll need to do some customizing for your app, but this should get you started.
Configure Tugboat
The Tugboat configuration is managed by a YAML file at
.tugboat/config.yml in the git repository. Here’s a basic Ruby on Rails configuration you can use as a starting point,
with comments to explain what’s going on:
1services:
2 # What to call the service hosting the site.
3 rails:
4 # Use a Tugboat Debian image as a starting point because it contains tools
5 # and configurations to help them work well with Tugboat
6 image: tugboatqa/debian
7
8 # Set this as the default service. This does a few things
9 # 1. Clones the git repository into the service container
10 # 2. Exposes port 80 to the Tugboat HTTP proxy
11 # 3. Routes requests to the Preview URL to this service
12 default: true
13
14 # Don't build the Ruby service until the database service is started
15 depends: database
16
17 # A set of commands to run while building this service
18 commands:
19 # Commands that set up the basic preview infrastructure
20 init:
21 # Check for updates to apt-get, and then use it to install Ruby
22 - apt-get update
23 - apt-get install ruby ruby-dev
24
25 # Install a minimal set of PostgreSQL binaries and headers to interact with the database
26 - apt-get install libpq-dev
27
28 # Install the gems required for the project
29 - gem update --system
30 - gem install bundler
31 - bundle install
32
33 # Clean up apt artifacts to keep the Preview small
34 - apt-get clean
35 - rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
36
37 # Commands that import files, databases, or other assets. When an
38 # existing preview is refreshed, the build workflow starts here,
39 # skipping the init step, because the results of that step will
40 # already be present.
41 update:
42 # A common practice in many Rails projects is to run this command to
43 # set up a database. This step is why the 'database' service has an 'init'
44 # command to give the default Tugboat user permission to create the database.
45 # If you're not creating a database here, you don't need the 'init' and
46 # 'online' commands in the `database` service. If you're connecting to a remote
47 # database, you won't need this.
48 - bin/rails db:setup
49
50 # Commands that should happen every time the Preview starts.
51 start:
52 # Start the Rails server. The '&' trailing this statement puts the process
53 # in the background.
54 - bin/rails s -b 0.0.0.0 -p 80 &
55
56 # What to call the service hosting the database. This name also acts as the
57 # hostname to access the service by from the 'rails' service.
58 database:
59 # Use the latest available version of postgres by not specifying a
60 # version
61 image: tugboatqa/postgres
62
63 # A set of commands to run while building this service
64 commands:
65 # Commands that import files, databases, or other assets. When an
66 # existing preview is refreshed, the build workflow starts here,
67 # skipping the init step, because the results of that step will
68 # already be present.
69 init:
70 # Give the default Tugboat user the permission to create a database.
71 # This is only required if using 'rails db:setup'
72 - psql -U postgres -d tugboat -c "ALTER USER tugboat WITH CREATEDB;"Want to know more about something mentioned in the comments of this config file? Check out these topics:
- Name your Service
- Specify a Service image
- Leverage Service commands
- Define a default Service
- Preview build process phases (
init,update,build)
Start Building Previews!
Once this Tugboat configuration file is committed to your git repository, you can start building previews!