Skip to content

Commit

Permalink
Merge b7c3da7 into 5efa9fe
Browse files Browse the repository at this point in the history
  • Loading branch information
cavis committed May 20, 2016
2 parents 5efa9fe + b7c3da7 commit 2690f2d
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 74 deletions.
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Rails Project
#
tmp/*
log/*
*.log
build/
coverage/
.git
.gitignore
.bundle
.powder
build.sh
docker-compose.yml
Dockerfile
env-example

#
# OS X
#
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
41 changes: 41 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM alpine:3.3

MAINTAINER PRX <sysadmin@prx.org>

RUN echo "http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
apk update && apk --update add ca-certificates ruby ruby-irb ruby-json ruby-rake \
ruby-bigdecimal ruby-io-console libstdc++ tzdata mysql-dev autossh \
linux-headers libc-dev zlib libxml2 libxslt libffi

ENV TINI_VERSION v0.9.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini-static /tini
RUN chmod +x /tini

ENV RAILS_ENV production
ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME
ADD Gemfile ./
ADD Gemfile.lock ./

RUN apk --update add --virtual build-dependencies build-base ruby-dev openssl-dev \
zlib-dev libxml2-dev libxslt-dev libffi-dev && \
gem install -N bundler && \
cd $APP_HOME ; \
bundle config --global build.nokogiri "--use-system-libraries" && \
bundle config --global build.nokogumbo "--use-system-libraries" && \
bundle config --global build.ffi "--use-system-libraries" && \
bundle install --jobs 10 --retry 10 && \
apk del build-dependencies && \
(find / -type f -iname \*.apk-new -delete || true) && \
rm -rf /var/cache/apk/* && \
rm -rf /usr/lib/ruby/gems/*/cache/* && \
rm -rf /tmp/* /var/tmp/* && \
rm -rf ~/.gem

ADD . ./
RUN chown -R nobody:nogroup /app
USER nobody

ENTRYPOINT ["/tini", "--", "./bin/application"]
CMD ["web"]
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ end
group :doc do
gem 'sdoc', require: false
end

group :production, :staging do
gem 'rails_12factor'
gem 'puma'
end
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ GEM
slop (~> 3.4)
pry-rails (0.3.4)
pry (>= 0.9.10)
puma (3.4.0)
pundit (1.0.1)
activesupport (>= 3.0.0)
quiet_assets (1.1.0)
Expand Down Expand Up @@ -325,6 +326,11 @@ GEM
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (4.2.6)
actionpack (= 4.2.6)
activesupport (= 4.2.6)
Expand Down Expand Up @@ -442,11 +448,13 @@ DEPENDENCIES
paranoia (~> 2.0)
prx_auth-rails (~> 0.0.4)
pry-rails
puma
pundit
quiet_assets
rack-cors
rack-prx_auth (~> 0.0.8)
rails (~> 4.2.1)
rails_12factor
rake
responders (~> 2.0)
roar
Expand All @@ -458,3 +466,6 @@ DEPENDENCIES
spring
unf
web-console (~> 2.0)

BUNDLED WITH
1.10.6
74 changes: 26 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,52 @@ Integrations & Dependencies

Installation
------------
These instructions are written assuming Mac OS X install.
CMS now works in Docker. You should use Docker.

### Basics
```
# Homebrew - http://brew.sh/
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
brew update
# Git - http://git-scm.com/
brew install git
# Mysql (and run the server somehow) - https://www.mysql.com/
brew install mysql
mysql.server start
# Pow to serve the app - http://pow.cx/
curl get.pow.cx | sh
```

### Ruby & Related Projects
# Get the code
git clone git@github.com:PRX/cms.prx.org.git
cd cms.prx.org
```
# rbenv and ruby-build - https://github.com/sstephenson/rbenv
brew install rbenv ruby-build
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
source ~/.bash_profile

# ruby (.ruby-version default)
rbenv install 2.1.2
### Environment
You'll need to `cp env-example .env` and include your credentials.

# bundler gem - http://bundler.io/
gem install bundler
### Docker Development
Currently on OSX, [Dinghy](https://github.com/codekitchen/dinghy) is probably
the best way to set up your dev environment. Using VirtualBox is recommended.
Also be sure to install `docker-compose` along with the toolbox.

# powder gem - https://github.com/Rodreegez/powder
gem install powder
```
# Build the `web` container, it will also be used for `worker`
docker-compose build
### Rails Project
Consider forking the repo if you plan to make changes, otherwise you can clone it:
```
# ssh repo syntax (or https `git clone https://github.com/PRX/cms.prx.org.git cms.prx.org`)
git clone git@github.com:PRX/cms.prx.org.git cms.prx.org
cd cms.prx.org
# Start the postgres `db`
docker-compose start db
# ... and run migrations against it
docker-compose up db # the database has to be running
docker-compose run app setup
docker-compose stop
# bundle to install gems dependencies
bundle install
# Test
docker-compose run app test
# copy the env-example, fill out the values
cp env-example .env
vi .env
# Guard
docker-compose run app guard
# Run the web, worker, and db
docker-compose up
```

### Database bootstrapping

This project uses the [prx.org](https://github.com/PRX/prx.org) database. So you'll need to get a backup of it to restore to your local development/test databases. (See the instructions at the end of the prx.org README).

```
Expand All @@ -99,24 +91,10 @@ gunzip < 20150101_mediajoint_production_structure.gz | mysql -u root cms_prx_org
gunzip < 20150101_mediajoint_production_data.gz | mysql -u root cms_prx_org_development
```

### Testing

After bootstrapping the prx.org schema into the test database, just run `bundle exec rake`. Bingo!

### Development server

The dev server runs through powder - see a [full list of commands](https://github.com/Rodreegez/powder#working-with-pow) over there.

```
powder link
open http://cms.prx.dev
```

License
-------
[AGPL License](https://www.gnu.org/licenses/agpl-3.0.html)


Contributing
------------
Completing a Contributor License Agreement (CLA) is required for PRs to be accepted.
64 changes: 64 additions & 0 deletions bin/application
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh

PROCESS=
CMD_ARGS=

CmsUsage () {
echo "usage: application [ help | web | migrate | test | -- ]"
}

CmsParseOpts () {
PROCESS=$1
shift
CMD_ARGS=$*
}

CmsTunnelMysql () {
if [[ -n "$SSH_MYSQL_KEY" && -n "$SSH_MYSQL_DEST" ]] ; then
TMPFILE=$(mktemp)
echo -e "$SSH_MYSQL_KEY" > $TMPFILE
autossh -M 0 -f -N -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \
-o ExitOnForwardFailure=yes -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no \
-i $TMPFILE -L 3306:localhost:3306 $SSH_MYSQL_DEST
if [ $? -eq 0 ] ; then
sleep 2
if nc -z 127.0.0.1 3306 ; then
echo "Tunneling mysql from $SSH_MYSQL_DEST"
else
echo "Unable to establish mysql tunnel!"
exit 1
fi
else
echo "Mysql tunneling failed"
exit 1
fi
fi
}

CmsRun () {
CMD=
if [ "$PROCESS" = "help" ] ; then
CmsUsage
exit
elif [ "$PROCESS" = "web" ] ; then
CmsTunnelMysql
CMD="bundle exec puma -C config/puma.rb"
elif [ "$PROCESS" = "test" ] ; then
CMD="bundle exec rake db:create test:run RAILS_ENV=test"
elif [ "$PROCESS" = "guard" ] ; then
CMD="bundle exec guard"
elif [ "$PROCESS" = "setup" ] ; then
CMD="bundle exec rake -vt db:setup"
elif [ "$PROCESS" = "--" ] ; then
CMD=
else
echo "ERROR: $PROCESS is not a valid command."
CmsUsage
exit
fi

$CMD $CMD_ARGS
}

CmsParseOpts $*
CmsRun
36 changes: 20 additions & 16 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
<%= ENV['RAILS_ENV'] || 'development' %>:
default: &default
adapter: mysql2
encoding: utf8
database: <%= ENV['DATABASE'] %>
pool: 5
username: <%= ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: <%= ENV['DATABASE_HOST'] %>
pool: <%= ENV['DATABASE_POOL_SIZE'] %>
username: <%= ENV['DB_ENV_MYSQL_USER'] %>
password: <%= ENV['DB_ENV_MYSQL_PASSWORD'] %>
host: <%= ENV['DB_PORT_3306_TCP_ADDR'] %>
port: <%= ENV['DB_PORT_3306_TCP_PORT'] %>
database: <%= ENV['DB_ENV_MYSQL_DATABASE'] %>
reconnect: true

development:
<<: *default
database: cms_development

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
database: <%= ENV['TEST_DATABASE'] %>
pool: 5
username: <%= ENV['TRAVIS'] ? 'travis' : ENV['DATABASE_USERNAME'] %>
password: <%= ENV['DATABASE_PASSWORD'] %>
host: 127.0.0.1
<<: *default
database: cms_test

staging:
<<: *default

production:
<<: *default

0 comments on commit 2690f2d

Please sign in to comment.