Some time ago I’ve started migration from Heroku based project to Digital Ocean droplets with separate services based on Amazon EC2.
One thing what I wanted to do was automatically deployment configuration based on Bitbucket Pipeline.
Here you can find working config for Rails 5 based project with Redis/PostgreSQL/Webpack/YARN, currently deploy works through Capistrano.
Nothing special here, but deployment script for two different branches (one for production, one for staging or uat) can be a little bit tricky.
In this case you can use another section for different branch, under branches
section.
After installing basic environment we start to prepare test db and install google-chrome-stable_current
for integration tests.
Last step - deploy with capistrano
with simple bundle exec cap staging deploy
.
image: ruby:2.5.1
pipelines:
branches:
master:
- step:
caches:
- bundler
- yarn
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt-get update && apt-get install -y nodejs apt-transport-https gcc g++ make yarn gdebi
- curl -O https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
- gdebi -n -q google-chrome-stable_current_amd64.deb
- cp config/database.yml.ci config/database.yml
- cp config/credentials.yml.enc.ci config/credentials.yml.enc
- bundle install --path vendor
- export RACK_ENV=test
- yarn install
- RAILS_ENV=test bundle exec rake db:setup
- RAILS_ENV=test bundle exec rake db:test:prepare
- RAILS_ENV=test bundle exec bin/rails t -f -v test/integration/new/*.rb
services:
- redis
- postgres
- step:
name: Deploy to staging
deployment: staging
script:
- gem install bundler
- bundle install
- bundle exec cap staging deploy
definitions:
caches:
bundler: ./vendor
yarn: ./node_modules
services:
redis:
image: redis
postgres:
image: postgres
environment:
POSTGRES_DB: db_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres