Skip to end of metadata
Go to start of metadata

Set up app for deployment

Deploy scripts

This assumes a Rails application using mina-deploy.

  1. choose a port number for your new application

  2. add the uniofbath_deploy gem to your Gemfile

  3. bundle install
  4. run bundle exec uniofbath_deploy init which will:
    1. create the mina config file: config/deploy.rb
    2. create a digilin-01 environment file: config/deployments/digilin01.rb

More detailed instructions in the README and the deploy project docs.

Environment files

Add to the Rails app's configs environment files for staging and trainingdevelopmenttest and production should already exist.

Generate secret key

Generate a secret key for staging, training and add to config/secrets.yml. For production follow Configure Rails app for production.

Bamboo and server setup

  • Ensure Ruby is installed
  • Install the Bamboo Ruby plugin (available through the Universal Plugin Manager - this will give you ruby tasks and enable the next step)
  • Ensure Ruby is detected in Bamboo
    • Admin -> Server Capabilities -> Detect (check it finds Ruby)
  • Set up SSH keys between unix user running Bamboo and github.bath project - remember to authorize the key by running ssh -T git@github.bath.ac.uk as the user on the server
  • Install bundler on the command line (this will need doing whenever bundler needs installing / upgrading): 

  • Add environment variables to /etc/init.d/bamboo

Icon

See Getting started with a new Rails app

It is pre-requisite to below - particularly installing gems

Add brakman rake task

Add this to your app

http://brakemanscanner.org/docs/rake/

Configure your Rails app to generate test reports

  1. Ensure you've installed required gems - see Getting started with a new Rails app

  2. Add report outputs to /test/test_helper.rb

    This will make minitest output results to file which can be parsed by a junit parser.

     

Commit and push to GitHub Enterprise and then...

Configure Bamboo Plan

Set up test database credentials

Add them to /etc/init.d/bamboo

Set up the job to run the tests

With the Bamboo Ruby Plugin already installed and bundler added as a capability:

  1. Create your build plan - Authentication to Github is via SSH key (shared credential)
  2. Make sure that the builder user has permissions to build
  3. If running tests against a database add db:reset Rake task:
    1. Set Task description to "DB Setup"
    2. Set Tasks to "db:reset"
    3. Check "Bundler Exec" checkbox
  4. Follow Set up code metrics in a Rails app
  5. Run plan!

Set up the trigger

On the Trigger screen:

  • Delete "Repository polling"
  • Add "Repository Triggered Build" (trigger IP address = IP of github.bath.ac.uk - 138.38.44.91)

In Github

Set the project to tell Bamboo to trigger a build:

  • Settings -> Webhooks & Services -> Add service -> Bamboo

    • Build plan - is the plan, not the containing project
    • Put in builder username and password
  • Settings -> Webhooks & Services -> Add service -> Pivotal
    • Grab your API key from your Pivotal profile page (this is how we'll do it for now but record it on your project's doc pages)

 

Add SSH keys to target server

If you want to run Mina commands to manage an application as a user on another machine, the application user must accept the deploying user's public SSH key.

Deploying from Bamboo is done by the user www on fondor, so you must use an SSH key from www for this to work.

Adding an SSH key from your VM will also let you run Mina commands locally – this useful if you want to test deployment before setting up Bamboo, or need to stop or start the application.

  1. Copy the public key for the user and machine you want to deploy from using Mina: cat ~/.ssh/id_rsa.pub
  2. ssh to the server you want to deploy to
  3. sudo su to the user for the application
  4. Edit the user's authorised ssh keys: vi ~/.ssh/authorized_keys
    • If this file doesn't exist, you can create it
  5. Paste in the copied key, then save and quit

If your Mina commands appear to time out the first time you try to run them from your VM:

  • ssh to the target server first as your username (eg ssh if243@digilin-02.bath.ac.uk)
  • exit the server
  • try running the Mina command again

Mina deploy using uniofbath-deploy gem

See Ruby deployment Gem

Once you've run 

update the /config/deploy.rb file with your repo and server details. Create a /config/deployments/staging.rb file.

Deploy to a server:

Icon

If you hit a Nokogiri problem, do

Also: 

Default "to" is set in deploy.rb:

Mina files are in a repository here. Usage is covered on the Ruby development page.

Restart Unicorn

We have seen applications not deploy changes. This can be because Unicorn has not restarted. Assuming you have ssh keys set up to the environment server, restart unicorn by running (in the root of the project):

  • No labels

1 Comment

  1. Unknown User (mnskchg)

    You've got comments of what mina -T and mina db_seed do but not what setup does