-
-
Save romdim/0fe67845943125eea35fce5dfdc8390e to your computer and use it in GitHub Desktop.
Files for dockerizing and .env new Rails App
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Rails secret | |
| SECRET_KEY_BASE=NEW_SECRET | |
| DB_POOL=10 | |
| DATABASE_URL=postgres://CHANGE_ME:CHANGE_ME123@db/CHANGE_ME_dev | |
| # Puma port | |
| PORT=3000 | |
| # Rails outputs to console if this env exists | |
| RAILS_LOG_TO_STDOUT=true-if-you-want-logs-to-stdout-instead-of-a-file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defaults: &defaults | |
| adapter: postgresql | |
| encoding: unicode | |
| pool: <%= ENV["DB_POOL"] || ENV['RAILS_MAX_THREADS'] || 5 %> | |
| reconnect: true | |
| development: &development | |
| <<: *defaults | |
| # These are defined in docker-compose.yml | |
| host: db | |
| username: CHANGE_ME | |
| password: CHANGE_ME123 | |
| database: <%= ENV['DATABASE_NAME'] || 'CHANGE_ME_dev' %> | |
| test: | |
| <<: *development | |
| database: <%= ENV['TEST_DATABASE_NAME'] || 'CHANGE_ME_test' %> | |
| production: | |
| <<: *defaults | |
| url: <%= ENV['DATABASE_URL'] %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: '2' | |
| services: | |
| db: | |
| container_name: CHANGE_ME-db | |
| restart: always | |
| image: postgres:9.6.4-alpine | |
| environment: | |
| POSTGRES_MULTIPLE_DATABASES: CHANGE_ME_dev,CHANGE_ME_test | |
| POSTGRES_USER: CHANGE_ME | |
| POSTGRES_PASSWORD: CHANGE_ME123 | |
| ports: | |
| - 5432:5432 | |
| volumes: | |
| - CHANGE_ME_pg_data:/var/lib/postgresql/data | |
| CHANGE_ME: | |
| container_name: CHANGE_ME | |
| restart: always | |
| build: . | |
| env_file: .env | |
| command: sh -c "bundle exec puma -C config/puma.rb" | |
| volumes: | |
| - .:/CHANGE_ME | |
| ports: | |
| - 3000:3000 | |
| links: | |
| - db | |
| depends_on: | |
| - db | |
| volumes: | |
| CHANGE_ME_pg_data: | |
| driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM ruby:2.5.0 | |
| # Get required packages | |
| RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs | |
| # Set up working directory | |
| ENV DIR CHANGE_ME | |
| RUN mkdir /$DIR | |
| WORKDIR /$DIR | |
| # Set up gems | |
| ADD Gemfile ./Gemfile | |
| ADD Gemfile.lock ./Gemfile.lock | |
| RUN gem install bundler | |
| RUN bundle install --jobs 20 --retry 5 | |
| # Finally, add the rest of our app's code | |
| ADD ./ ./ | |
| EXPOSE 3000 | |
| CMD bundle exec puma -C config/puma.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Only this needs to be changed | |
| NAME=sth | |
| # Create a new secret | |
| SECRET=$(rails secret) | |
| # Create a new Rails app with postgres and cd into its folder | |
| rails new $NAME -B --database=postgresql | |
| cd $NAME | |
| # Download from gist the needed files | |
| files=( .env Dockerfile docker-compose.yaml ) | |
| for i in "${files[@]}" | |
| do | |
| curl -O https://gist.githubusercontent.com/romdim/0fe67845943125eea35fce5dfdc8390e/raw/$i | |
| done | |
| curl -L https://gist.githubusercontent.com/romdim/0fe67845943125eea35fce5dfdc8390e/raw/database.yml > ./config/database.yml | |
| # Change needed strings | |
| sed -i "" "s/CHANGE_ME/$NAME/g" .env ./config/database.yml Dockerfile docker-compose.yaml | |
| sed -i "" "s/NEW_SECRET/$SECRET/g" .env | |
| touch Gemfile.lock | |
| docker-compose build | |
| docker-compose run --rm $NAME rails db:create | |
| docker-compose run --rm $NAME rails db:migrate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment