Skip to content

Commit

Permalink
Docker support for the future version
Browse files Browse the repository at this point in the history
  • Loading branch information
MiLk committed Oct 11, 2015
1 parent 9557792 commit ae5f4a5
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 31 deletions.
2 changes: 0 additions & 2 deletions .dockerenv
@@ -1,2 +0,0 @@
REDIS_HOST=${REDIS_PORT_6379_TCP_ADDR}
REDIS_URL=redis://${REDIS_PORT_6379_TCP_ADDR}:${REDIS_PORT_6379_TCP_PORT}/0
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -27,4 +27,5 @@ connect.lock
sftp-config.json
.ruby-version
jsconfig.json
.vscode/
.vscode/
github_key
47 changes: 47 additions & 0 deletions Dockerfile
@@ -0,0 +1,47 @@
FROM phusion/baseimage
MAINTAINER Hummingbird Media, Inc.

# Dependencies: PG client
RUN apt-get update && \
apt-get install -y curl git postgresql-contrib libpq-dev && \
rm -rf /var/lib/apt/lists/*

# RVM
RUN command curl -sSL https://rvm.io/mpapis.asc | gpg --import - && \
curl -L https://get.rvm.io | bash -s stable --ruby=2.2.3

# NVM
RUN curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash && \
bash -c "source ~/.nvm/nvm.sh && \
nvm install v0.12 && \
nvm alias default v0.12 && \
npm install -g bower"

# Dependencies
RUN apt-get update && \
apt-get install -y python libgmp3-dev && \
rm -rf /var/lib/apt/lists/*

# Hummingbird
RUN mkdir -p /opt/hummingbird/server
WORKDIR /opt/hummingbird/server

COPY server/Gemfile /opt/hummingbird/server/
COPY server/Gemfile.lock /opt/hummingbird/server/

RUN bash -c "source /usr/local/rvm/scripts/rvm && \
gem install bundler && \
bundle install"

WORKDIR /opt/hummingbird
RUN bash -c "source /usr/local/rvm/scripts/rvm && \
gem install bundler && \
gem install foreman"

COPY . /opt/hummingbird
COPY github_key /root/.ssh/id_rsa
RUN chmod 0600 /root/.ssh/id_rsa

EXPOSE 3000
ENTRYPOINT ["/opt/hummingbird/entrypoint.sh"]
CMD ["foreman", "start", "--env=.dockerenv"]
2 changes: 1 addition & 1 deletion Procfile
@@ -1,3 +1,3 @@
server: cd server && bin/bundle exec puma --port 3000 --environment development
worker: cd server && bin/bundle exec sidekiq -q default -q mailer -q paperclip
client: cd client && ember server --port 4200 --environment development
client: cd client && ./node_modules/.bin/ember server --port 4200 --environment development
21 changes: 21 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,21 @@
postgres:
image: postgres:9.3
environment:
POSTGRES_PASSWORD: mysecretpassword
POSTGRES_USER: postgres
redis:
image: redis
web:
build: .
volumes:
- ./:/opt/hummingbird/
ports:
- 3000
- 4200
- 49152:49152
links:
- postgres
- redis
environment:
RAILS_ENV: development

59 changes: 59 additions & 0 deletions entrypoint.sh
@@ -0,0 +1,59 @@
#!/bin/bash

root_path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

source ${root_path}/server/.env

export REDIS_HOST=${REDIS_PORT_6379_TCP_ADDR}
export REDIS_URL=redis://${REDIS_PORT_6379_TCP_ADDR}:${REDIS_PORT_6379_TCP_PORT}/0

[ -e /usr/local/rvm/scripts/rvm ] && \
source /usr/local/rvm/scripts/rvm

ruby --version

[ -e ~/.nvm/nvm.sh ] && \
source ~/.nvm/nvm.sh

node --version

ssh-keyscan github.com >> ~/.ssh/known_hosts

pushd ${root_path}/client

bower install --allow-root
npm install

popd

export POSTGRES_HOST=${POSTGRES_PORT_5432_TCP_ADDR}
export POSTGRES_PORT=${POSTGRES_PORT_5432_TCP_PORT}
export POSTGRES_DATABASE=postgres
export POSTGRES_USERNAME=${POSTGRES_ENV_POSTGRES_USER}
export POSTGRES_PASSWORD=${POSTGRES_ENV_POSTGRES_PASSWORD}
export DATABASE_URL=postgresql://${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE}

echo "Saving database credentials..."
echo "${POSTGRES_HOST}:${POSTGRES_PORT}:${POSTGRES_DATABASE}:${POSTGRES_USERNAME}:${POSTGRES_PASSWORD}" > \
~/.pgpass
chmod 0600 ~/.pgpass

count=$(echo "SELECT COUNT(version) FROM schema_migrations;" | \
psql -q -d ${POSTGRES_DATABASE} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -U ${POSTGRES_USERNAME} -w | \
tail -n 3 | head -n 1)
status=${PIPESTATUS[0]}

[ ${status} -ne 0 ] && exit ${status}

pushd ${root_path}/server
if [ -z "${count}" ]; then
echo "Initializing database..."
bundle exec rake db:create db:schema:load
else
echo "Migrating database..."
bundle exec rake db:migrate
fi
popd

exec "$@"

27 changes: 0 additions & 27 deletions server/Dockerfile

This file was deleted.

0 comments on commit ae5f4a5

Please sign in to comment.