├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── postgres ├── Dockerfile └── init-user-db.sh └── workspace ├── Dockerfile ├── docker-entrypoint.sh └── scripts ├── start └── test /.gitignore: -------------------------------------------------------------------------------- 1 | /data -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Diogo Scudelletti 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RubyDevDock - Ruby Development Environment on Docker heavily inspired by [LaraDock](https://github.com/LaraDock/laradock) 2 | 3 | RubyDevDock aims to avoid having to install ruby, postgres in your host machine. This is for development environment only. 4 | 5 | ## Installation 6 | 7 | Clone the repo 8 | 9 | git clone https://github.com/scudelletti/rubydev-dock.git 10 | 11 | Go to repo's folder 12 | 13 | cd rubydev-dock 14 | 15 | ### Change docker-compose.yml 16 | 17 | * Edit volumes_source container to point the volume to your app's directory, please check [docker-compose documentation](https://docs.docker.com/compose/compose-file/#/volumes-volumedriver). 18 | * Adjust and customize database environment variables or other containers information to your taste. 19 | 20 | ## Usage examples: 21 | 22 | * Start all containers defined in the docker-compose.yml 23 | 24 | `docker-compose up -d` 25 | 26 | Then you just have to access it, probably will be something like `http://localhost:3000` for app and `http://localhost:5050` for pgAdmin. You can see the ports running `docker-compose ps`. 27 | 28 | * Visualize logs from all containers 29 | 30 | `docker-compose logs -f` 31 | 32 | * Use current running container to run command 33 | 34 | `docker-compose exec workspace bash` 35 | 36 | * Create a new container to run command 37 | 38 | `docker-compose run workspace bash` 39 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | 3 | services: 4 | workspace: 5 | build: ./workspace 6 | environment: 7 | DATABASE_DEV_NAME: awesome_database_name_development 8 | DATABASE_TEST_NAME: awesome_database_name_test 9 | DATABASE_USERNAME: awesome_database_username 10 | DATABASE_PASSWORD: awesome_database_password 11 | DATABASE_HOST: postgres 12 | volumes_from: 13 | - volumes_source 14 | ports: 15 | - '3000:3000' 16 | tty: true 17 | command: dev 18 | links: 19 | - postgres 20 | 21 | volumes_source: 22 | image: tianon/true 23 | volumes: 24 | - ../awesome_app:/app 25 | - /bundler 26 | - ./workspace:/docker 27 | 28 | postgres: 29 | build: ./postgres 30 | volumes_from: 31 | - volumes_data 32 | environment: 33 | POSTGRES_DB: awesome_database_username 34 | POSTGRES_TEST_DB: awesome_database_password 35 | POSTGRES_USER: awesome_database_username 36 | POSTGRES_PASSWORD: awesome_database_username 37 | 38 | pgadmin: 39 | image: fenglc/pgadmin4 40 | ports: 41 | - '5050:5050' 42 | links: 43 | - postgres 44 | 45 | volumes_data: 46 | image: tianon/true 47 | volumes: 48 | - ./data/postgres:/var/lib/postgresql/data 49 | -------------------------------------------------------------------------------- /postgres/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM postgres:latest 2 | 3 | MAINTAINER Diogo Scudelletti 4 | 5 | COPY init-user-db.sh /docker-entrypoint-initdb.d/init-user-db.sh 6 | 7 | CMD ["postgres"] 8 | 9 | EXPOSE 5432 -------------------------------------------------------------------------------- /postgres/init-user-db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" "$POSTGRES_DB" <<-EOSQL 5 | CREATE DATABASE "$POSTGRES_TEST_DB"; 6 | EOSQL 7 | -------------------------------------------------------------------------------- /workspace/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.3.1 2 | 3 | MAINTAINER Diogo Scudelletti 4 | 5 | RUN mkdir /bundler 6 | WORKDIR /app 7 | 8 | USER root 9 | ENV BUNDLE_PATH /bundler 10 | 11 | ENTRYPOINT ["/docker/docker-entrypoint.sh"] 12 | -------------------------------------------------------------------------------- /workspace/docker-entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | case "$1" in 5 | 'test') 6 | exec /docker/scripts/test 7 | ;; 8 | 'dev') 9 | exec /docker/scripts/start 10 | ;; 11 | *) 12 | exec "$@" 13 | ;; 14 | esac 15 | -------------------------------------------------------------------------------- /workspace/scripts/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | echo "Setting up Bundler" 5 | bundle config build.nokogiri --use-system-libraries 6 | 7 | echo "Installing gems" 8 | bundle check || bundle install 9 | 10 | echo "Running Migrations" 11 | bundle exec rake db:migrate 12 | 13 | echo "Starting server" 14 | bundle exec rails s -p 3000 -b '0.0.0.0' 15 | -------------------------------------------------------------------------------- /workspace/scripts/test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | echo "Setting up Bundler" 5 | bundle config build.nokogiri --use-system-libraries 6 | 7 | echo "Installing gems" 8 | bundle check || bundle install 9 | 10 | echo "Running db:test:prepare" 11 | bundle exec rake db:test:prepare 12 | 13 | echo "Running tests" 14 | bundle exec rspec 15 | --------------------------------------------------------------------------------