Last active
March 30, 2016 13:19
-
-
Save emilsoman/b71e6e5d92ca42b6d46543c7a6fe5045 to your computer and use it in GitHub Desktop.
chatops_deployer setup for a simple Rails app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Which ports if which service need to be exposed as | |
# haikunated URLs | |
expose: | |
app: [3000] | |
# These commands will be run in the specified order in each of the containers | |
# Note: Only DB changes are persisted, no other effects are persisted since | |
# only the DB data directory is inside a docker volume. | |
commands: | |
- [app, "bin/setup"] | |
copy: | |
- "./config/secrets.docker.yml.erb:config/secrets.yml" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/database.docker.yml | |
development: | |
adapter: mysql2 | |
encoding: utf8 | |
collation: utf8_general_ci | |
reconnect: true | |
database: appname | |
host: db | |
port: 3306 | |
pool: 5 | |
username: root | |
password: secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db: | |
image: <private_docker_registry>:5000/mysql:5.6 | |
environment: | |
- MYSQL_ROOT_PASSWORD=secret | |
- MYSQL_DATABASE=appname | |
app: | |
build: . | |
command: bin/rails s -p 3000 -b '0.0.0.0' | |
ports: | |
- "3000" | |
environment: | |
- BUNDLE_PATH=/cache/tmp/bundler | |
- DB_USER=root | |
- DB_PASSWORD=secret | |
- DB_HOST=db | |
- DB_NAME=appname | |
volumes_from: | |
- cache | |
links: | |
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use ruby:2.2 as the base image since this is a Rails app | |
FROM <private_docker_registry>/ruby:2.2 | |
# Install necessary packages for running rails and connecting to DB | |
RUN apt-get update -qq && apt-get install -y build-essential nodejs mysql-client | |
RUN mkdir /web | |
WORKDIR /web | |
# Copy the project | |
ADD . /web/ | |
COPY config/database.docker.yml /web/config/database.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/secrets.docker.yml.erb | |
# If these are sensitive data, check out vault integration: | |
# https://github.com/code-mancers/chatops_deployer/blob/master/doc/using_vault.md | |
development: | |
secret_key_base: db1fbe125905dd3cbab174f48e59daacb70fa674143d9d8118709074ca3b6f2647f0c475c93faae40684e022df51d771658041b23 | |
other_key: <VALUE> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# File: bin/setup | |
require 'pathname' | |
# path to your application root. | |
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) | |
def mysql_running | |
system "mysql -h #{ENV['DB_HOST']} -u#{ENV['DB_USER']} -p#{ENV['DB_PASSWORD']} --batch --skip-column-names -e \"SHOW DATABASES LIKE '#{ENV['DB_NAME']}';\" | grep #{ENV['DB_NAME']}" | |
end | |
Dir.chdir APP_ROOT do | |
# This script is a starting point to setup your application. | |
# Add necessary setup steps to this file: | |
puts "== Installing dependencies ==" | |
system "gem install bundler --conservative" | |
system "bundle check || bundle install" | |
puts "\n== Waiting until database is ready ==" | |
MAX_RETRY_COUNT = 30 | |
(1..MAX_RETRY_COUNT).each do |i| | |
break if mysql_running | |
if i == MAX_RETRY_COUNT | |
fail "Reached max retry count of #{MAX_RETRY_COUNT}" | |
end | |
"Mysql server not up. Retrying" | |
sleep 1 | |
end | |
puts "\n== Preparing database ==" | |
system "bin/rake db:setup" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment