def puts_red(heredoc); puts set_color heredoc, :red; end def puts_green(heredoc); puts set_color heredoc, :green; end puts_red "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" puts_red "@@ @@@@@@@@ @@@@@@@@37@@@" puts_red "@ @@@@@ @@@@@@@@@@@@@" puts_red "@ @@@@@ @@@@ @@@@" puts_red "@ @@@@@ @@@@ @@" puts_red "@ @@@@ @@@@@@ @" puts_red "@ @@@@@@@ @@@@@@ @" puts_red "@ @@ @@@@@@ @@@@@@ @" puts_red "@ @@@@ @@@@ @@" puts_red "@@ @@@@@ @@@@@ @@@@" puts_red "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" puts_red "@@@@@@@@ https://www.rubidium.io @@@@@@@@@" puts_red "@@@@@@@@@@@@@@ 85.4678 @@@@@@@@@@@@@@@@@@" puts_red "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" puts "" puts "" # Checks for unstagged commits return_message = "There are unstaged commits. Do you want to continue?" return if !run("git diff --no-patch --exit-code") && no?(return_message) # TEMPLATE START def print_green(heredoc) puts set_color heredoc, :green end def ask_with_default(prompt, default) value = ask("#{prompt} [#{default}]") value.blank? ? default : value end create_file './.dockerignore', <<~EOF .git* db/*.sqlite3 db/*.sqlite3-journal log/* tmp/* tmp/pid/server.pid Dockerfile README.rdoc EOF create_file './docker-compose.yml' do ruby_verison = ask_with_default("What version of Ruby do you want to use?", '2.6.6') node_version = ask_with_default("What version of Node do you want to use?", '13') bundle_version = ask_with_default("What version of Bundle do you want to use?", '2.1.4') postgres_version = ask_with_default("What version of Postgres do you want to use?", '12') <<~EOF version: '2.4' services: base: &app build: context: . dockerfile: ./Dockerfile args: RUBY_VERSION: '#{ruby_verison}' NODE_MAJOR: '#{node_version}' BUNDLE_VERSION: '#{bundle_version}' PG_MAJOR: '#{postgres_version}' tmpfs: - /tmp backend: &backend <<: *app stdin_open: true tty: true volumes: - .:/app:cached - rails_cache:/app/tmp/cache - bundle:/usr/local/bundle - node_modules:/app/node_modules - packs:/app/public/packs environment: - PSQL_HISTFILE=/app/log/.psql_history - DATABASE_URL=postgres://postgres:postgres@postgres:5432 - BOOTSNAP_CACHE_DIR=/bundle/bootsnap - WEBPACKER_DEV_SERVER_HOST=webpacker depends_on: - postgres - redis app: <<: *backend command: bundle exec rails server -b 0.0.0.0 ports: - '3000:3000' webpacker: <<: *app command: ./bin/webpack-dev-server ports: - '3035:3035' volumes: - .:/app:cached - bundle:/usr/local/bundle - node_modules:/app/node_modules - packs:/app/public/packs environment: - NODE_ENV=${NODE_ENV:-development} - RAILS_ENV=${RAILS_ENV:-development} - WEBPACKER_DEV_SERVER_HOST=0.0.0.0 sidekiq: <<: *backend command: bundle exec sidekiq -C config/sidekiq.yml redis: image: redis:latest postgres: image: postgres:#{postgres_version} volumes: - .psqlrc:/root/.psqlrc:ro - postgres:/var/lib/postgresql/data - ./log:/root/log:cached environment: - PSQL_HISTFILE=/root/log/.psql_history ports: - 5432 healthcheck: test: pg_isready -U postgres -h 127.0.0.1 interval: 5s volumes: postgres: redis: bundle: node_modules: rails_cache: packs: EOF end create_file './Dockerfile', <<~EOF ARG RUBY_VERSION FROM ruby:$RUBY_VERSION LABEL MAINTAINER=dave@k-innovations.net ARG NODE_MAJOR ARG PG_MAJOR ARG BUNDLE_VERSION RUN apt-get update RUN apt-get install -y build-essential # Add PostgreSQL to sources list RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ && echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list RUN curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash - RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list RUN apt-get -y update RUN apt-get -y install nodejs RUN apt-get -y install yarn RUN yarn config set "strict-ssl" false RUN bundle config --global frozen 1 COPY Gemfile Gemfile.lock ./ RUN gem install bundler -v $BUNDLE_VERSION RUN bundle install -j $(nproc) RUN mkdir -p /app WORKDIR /app EOF print_green <<~EOF Your application is now configured with Docker. To start running docker, you will need Docker and Docker Compose (https://www.docker.com/get-started) The docker-compose.yml file has been created to house the various services that will be used. Feel free to comment out the services not needed by your application. - app <- the containers for the rails application - webpacker - sidekiq - redis - postgres To get started, type "docker-compose up" When finished, type "docker-compose down" If you need to run migrations, you can run "docker-compose run app rails db:migrate" You can also get into the rails console with "docker-compose run app rails console" EOF # TEMPLATE END puts "" puts "" puts_green "Template Name: Docker Development Environment" puts_green "By: Dave Kimura (https://www.rubidium.io/profiles/dave-kimura)" puts_green "https://www.rubidium.io/templates/docker-development-environment"