diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 00000000..5a1f55f4 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,69 @@ +FROM ubuntu:14.04 + +ENV DEBIAN_FRONTEND noninteractive +RUN apt-get update &&\ + apt-get -y install \ + wget &&\ + wget --quiet -O - https://deb.nodesource.com/setup_4.x | /bin/bash &&\ + apt-get update &&\ + apt-get -y install \ + build-essential \ + git-core \ + imagemagick \ + imagemagick-common \ + libcurl4-openssl-dev \ + libffi-dev \ + libmagickcore-dev \ + libmagickwand-dev \ + libpq-dev \ + libreadline-dev \ + libsqlite3-dev \ + libssl-dev \ + libxml2-dev \ + libxslt1-dev \ + libyaml-dev \ + nodejs \ + postgresql-client \ + python-dev \ + python-pip \ + python-software-properties \ + rlwrap \ + sqlite3 \ + supervisor \ + zlib1g-dev &&\ + pip install bandit + +RUN apt-get clean &&\ + rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + +ADD docker-entrypoint.sh /docker-entrypoint.sh +ADD docker-entrypoint-init.d /docker-entrypoint-init.d + +RUN useradd -c 'scumblr' -m -d /home/scumblr -s /bin/bash scumblr +USER scumblr +ENV RBENV_ROOT /home/scumblr/usr/local/rbenv +ENV PATH $RBENV_ROOT/bin:$RBENV_ROOT/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV BUNDLE_GEMFILE /home/scumblr/Scumblr/Gemfile + +RUN git clone https://github.com/sstephenson/rbenv.git /home/scumblr/usr/local/rbenv &&\ + git clone https://github.com/sstephenson/ruby-build.git /home/scumblr/usr/local/rbenv/plugins/ruby-build &&\ + rbenv install 2.3.1 &&\ + rbenv global 2.3.1 &&\ + gem install bundler --no-ri --no-rdoc &&\ + gem install sidekiq --no-ri --no-rdoc &&\ + gem install rails -v 4.2.6 --no-ri --no-rdoc &&\ + rbenv rehash + +RUN git clone https://github.com/Netflix/Scumblr.git /home/scumblr/Scumblr &&\ + bundle install --gemfile=/home/scumblr/Scumblr/Gemfile --no-cache + +RUN sed -i '0,/localhost/{s/localhost/postgres/}' /home/scumblr/Scumblr/config/database.yml +RUN cp /home/scumblr/Scumblr/config/initializers/scumblr.rb.sample /home/scumblr/Scumblr/config/initializers/scumblr.rb +ADD supervisord.conf /home/scumblr/supervisord.conf + +WORKDIR /home/scumblr/Scumblr +EXPOSE 3000 +ENTRYPOINT ["/docker-entrypoint.sh"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 00000000..e1fea6ae --- /dev/null +++ b/docker/README.md @@ -0,0 +1,15 @@ +# Docker environment for Scumblr 2.0 + +This is a docker configuration for Scumblr 2.0 suitable for non-production use + +## Quick start + +1. Add API keys and configure the admin user account name and password in `scumblr-vars.env` +2. Run `docker-compose up` from the directory of `Dockerfile` +3. After rails and sidekiq are started on the scumblr container visit `http://localhost:3000` + +## Advanced + +The default docker compose configuration passes the `init` argument to the Scumblr container's entrypoint. This will cause the scumblr container to attempt initializion of the scumblr database on the postgres container. If the postgres container's volumes are to be persisted consider removing this argument after a successful initialization. + +Bash or ruby scripts added to the `/docker-init.d` folder will be run at the start of the scumblr container when `init` is passed to the entrypoint. If they are dependent on each other ensure they execute in the correct order. diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 00000000..bbbb560a --- /dev/null +++ b/docker/docker-compose.yml @@ -0,0 +1,26 @@ +version: "2" +services: + scumblr: + build: . + ports: + - "3000:3000" + depends_on: + - "postgres" + - "redis" + links: + - "postgres" + - "redis" + environment: + - REDIS_URL=redis://redis:6379 + env_file: + - scumblr-vars.env + entrypoint: + - /docker-entrypoint.sh + - init + postgres: + image: postgres:9.5 + environment: + - POSTGRES_USER=scumblr + - POSTGRES_PASSWORD=scumblr + redis: + image: redis:latest diff --git a/docker/docker-entrypoint-init.d/configure.rb b/docker/docker-entrypoint-init.d/configure.rb new file mode 100644 index 00000000..34ef02e7 --- /dev/null +++ b/docker/docker-entrypoint-init.d/configure.rb @@ -0,0 +1,6 @@ +user = User.new +user.email = ENV["admin_user_name"] +user.password = ENV["admin_user_pass"] +user.password_confirmation = ENV["admin_user_pass"] +user.admin = true +user.save diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 00000000..1fd9bf2e --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +if [ $1 == "init" ]; then + + rake db:create + rake db:structure:load + + for f in /docker-entrypoint-init.d/*; do + case "$f" in + *.sh) echo "$0: running $f"; . "$f" ;; + *.rb) echo "$0: running $f"; rails r "$f"; echo ;; + *) echo "$0: ignoring $f" ;; + esac + echo + done + +fi + +exec /usr/bin/supervisord -c /home/scumblr/supervisord.conf diff --git a/docker/scumblr-vars.env b/docker/scumblr-vars.env new file mode 100644 index 00000000..4f0de155 --- /dev/null +++ b/docker/scumblr-vars.env @@ -0,0 +1,41 @@ +db_user_name=scumblr +db_user_pass=scumblr +admin_user_name= +admin_user_pass= + +# Sketchy +#sketchy_url= +#sketchy_use_ssl= +#sketchy_verify_ssl= +#sketchy_tag_status_code= +#sketchy_access_token= + +# Google +#google_application_name= +#google_application_version= +#google_developer_key= +#google_cx= + +# YouTube +#youtube_application_name= +#youtube_application_version= +#youtube_developer_key= + +# eBay +#ebay_access_key= + +# Facebook +#facebook_app_id= +#facebook_app_secret= + +# Twitter +#twitter_consumer_key= +#twitter_consumer_secret= +#twitter_access_token= +#twitter_access_token_secret= + +# Github +#github_oauth_token= + +#OpenGrok +#opengrok_url= diff --git a/docker/supervisord.conf b/docker/supervisord.conf new file mode 100644 index 00000000..f9948ed0 --- /dev/null +++ b/docker/supervisord.conf @@ -0,0 +1,13 @@ +[supervisord] +user=scumblr +loglevel=info +logfile=/home/scumblr/supervisor.log +nodaemon=true + +[program:sidekiq] +user=scumblr +command=/bin/bash -c "/home/scumblr/usr/local/rbenv/shims/bundle exec sidekiq -l /home/scumblr/sidekiq.log" + +[program:rails] +user=scumblr +command=/bin/bash -c "/home/scumblr/usr/local/rbenv/shims/bundle exec rails s -b 0.0.0.0"