Skip to content

Instantly share code, notes, and snippets.

@fancyremarker
Last active December 20, 2016 01:23
Show Gist options
  • Save fancyremarker/9652688 to your computer and use it in GitHub Desktop.
Save fancyremarker/9652688 to your computer and use it in GitHub Desktop.
[:octopus:] Files required to Aptible-ize a Heroku-conformant Rails app
before_release:
- bundle exec rake db:migrate
# The following snippet can go beneath your :development and :test declarations
<% if Rails.env.production? && ENV['DATABASE_URL'] %>
<%
require 'cgi'
require 'uri'
# Parse parameters out of ENV['DATABASE_URL']
uri = URI.parse(ENV['DATABASE_URL'])
database = (uri.path || '').split('/')[1]
username = uri.user
password = uri.password
host = uri.host
port = uri.port
%>
<% end %>
production:
adapter: postgresql
database: <%= database %>
username: <%= username %>
password: "<%= password %>"
host: <%= host %>
port: <%= port %>
FROM quay.io/aptible/nodejs:v0.12.x
ADD . /app
WORKDIR /app
RUN npm install
RUN bower install
ENV PORT 3000
EXPOSE 3000
CMD node server.js -p $PORT
# Standard Rails Dockerfile, used for production deployments
# It lives in `Dockerfile` at the root of your Rails repository
FROM quay.io/aptible/ruby:ruby-2.0.0
# System prerequisites
RUN apt-get update && apt-get -y install libpq-dev nodejs
ADD . /opt/rails
WORKDIR /opt/rails
RUN bundle install --without development test
RUN cp config/database.yml.example config/database.yml
RUN bundle exec rake assets:precompile
ENV PORT 3000
EXPOSE 3000
CMD bundle exec rails s -p $PORT
# This is a non-standard Dockerfile, which packages a PostgreSQL database in
# the same container as the Rails app. It could be used to simplify staging
# deployments, or to test a production-like environment in a local Docker
# environment
FROM quay.io/aptible/ruby:ruby-2.0.0
# Install PostgreSQL 9.3.x from official Debian sources
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> \
/etc/apt/sources.list.d/pgdg.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys \
B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
apt-get update && \
apt-get -y install python-software-properties software-properties-common \
postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
ENV DATABASE_URL postgres://aptible:password@localhost:5432/db
# System prerequisites
RUN apt-get update && apt-get -y install libpq-dev
ADD . /opt/rails
WORKDIR /opt/rails
RUN bundle install --without development test
# Force a production environment here for testing purposes, but this may also
# be set via external environment (aptible config)
ENV RAILS_ENV production
ENV PORT 3000
EXPOSE 3000
# We need to:
# * Start PostgreSQL
# * Create the database and run migrations
# * Start the Rails server
CMD service postgresql start && sudo -u postgres psql --command \
"CREATE USER aptible WITH SUPERUSER PASSWORD 'password';" && \
sudo -u postgres psql --command "CREATE DATABASE db;" && \
bundle exec rake db:migrate; bundle exec rails s -p $PORT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment