├── .github ├── dependabot.yml └── workflows │ ├── changelog.yml │ ├── test-template-repo.yml │ └── update-template-repo.yml ├── .gitignore ├── App-Template ├── .dockerignore ├── .env.example ├── .github │ ├── dependabot.yml.sample │ └── workflows │ │ ├── linters.yml │ │ ├── standard.yml │ │ └── tests.yml ├── .gitignore.append ├── .rspec ├── .rubocop.yml ├── Dockerfile ├── Gemfile.append ├── Procfile ├── README.md ├── app.json ├── app │ ├── jobs │ │ └── sentry_job.rb │ └── models │ │ └── application_record.rb ├── bin │ ├── docker │ │ ├── bash │ │ ├── bundle │ │ ├── entrypoints │ │ │ ├── wait-for-postgres.sh │ │ │ └── wait-for-web.sh │ │ ├── prepare-to-start-rails │ │ ├── setup │ │ ├── start │ │ └── yarn │ ├── heroku │ │ └── release-tasks.sh │ └── setup ├── config │ ├── cable.yml │ ├── database.yml │ ├── initializers │ │ └── opinionated_defaults │ │ │ ├── action_mailer.rb │ │ │ ├── assets.rb │ │ │ ├── default_url_options.rb │ │ │ ├── generators.rb │ │ │ ├── locale.rb │ │ │ ├── logger.rb │ │ │ ├── lograge.rb │ │ │ ├── sentry_raven.rb │ │ │ ├── sidekiq.rb │ │ │ └── web_console.rb │ ├── routes.rb │ ├── schedule.yml │ └── sidekiq.yml ├── db │ └── schema.rb ├── docker-compose.ci.yml ├── docker-compose.yml └── spec │ ├── factory_bot_spec.rb │ ├── rails_helper.rb │ ├── spec_helper.rb │ └── support │ ├── active_job.rb │ └── factory_bot.rb ├── CHANGELOG.md ├── LICENSE ├── README.md ├── bin ├── build-environment-for-building-app ├── build-latest-version └── test-latest-version └── template.rb /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | open-pull-requests-limit: 10 8 | -------------------------------------------------------------------------------- /.github/workflows/changelog.yml: -------------------------------------------------------------------------------- 1 | # From: https://github.com/hopsoft/stimulus_reflex/blob/master/.github/workflows/changelog.yml 2 | name: Changelog 3 | 4 | on: 5 | workflow_dispatch: 6 | release: 7 | types: [created] 8 | push: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 4 16 | if: "!contains(github.event.head_commit.message, '[nodoc]')" 17 | steps: 18 | - uses: actions/checkout@master 19 | - name: Set up Ruby 3.0 20 | uses: ruby/setup-ruby@v1 21 | with: 22 | ruby-version: 3.0 23 | - uses: actions/cache@v2 24 | with: 25 | path: vendor/bundle 26 | key: ${{ runner.os }}-changelog-gem-${{ hashFiles('**/Gemfile.lock') }} 27 | restore-keys: | 28 | ${{ runner.os }}-changelog-gem- 29 | - name: Create local changes 30 | run: | 31 | gem install github_changelog_generator -v "1.15.2" 32 | github_changelog_generator -u ${{ github.repository_owner }} -p ${{ github.event.repository.name }} --token ${{ secrets.GITHUB_TOKEN }} --exclude-labels duplicate,question,invalid,wontfix,nodoc 33 | - name: Commit files 34 | run: | 35 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 36 | git config --local user.name "github-actions[bot]" 37 | git commit -am "[nodoc] Update Changelog" || echo "No changes to commit" 38 | - name: Push changes 39 | uses: ad-m/github-push-action@master 40 | with: 41 | github_token: ${{ secrets.GITHUB_TOKEN }} 42 | branch: ${{ github.ref }} 43 | -------------------------------------------------------------------------------- /.github/workflows/test-template-repo.yml: -------------------------------------------------------------------------------- 1 | name: Test New Template 2 | 3 | on: 4 | pull_request: 5 | 6 | jobs: 7 | test: 8 | runs-on: ubuntu-latest 9 | timeout-minutes: 15 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | repository: "Ruby-Starter-Kits/Docker-Rails-Template" 14 | path: App 15 | persist-credentials: false 16 | - uses: actions/checkout@v2 17 | with: 18 | repository: 'Ruby-Starter-Kits/Docker-Rails-Generator' 19 | path: Docker-Rails-Generator 20 | persist-credentials: false 21 | - name: Set up Ruby 3.0 22 | uses: ruby/setup-ruby@v1 23 | with: 24 | ruby-version: 3.0.1 25 | bundler: none 26 | - name: Build Environment for building app 27 | run: | 28 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 29 | ./bin/build-environment-for-building-app 30 | - uses: actions/cache@v2 31 | with: 32 | path: ${{ github.workspace }}/vendor/bundle 33 | key: ${{ runner.os }}-gem-${{ hashFiles('**/*/Gemfile.lock') }} 34 | - uses: actions/cache@v2 35 | with: 36 | path: ${{ github.workspace }}/App/node_modules 37 | key: ${{ runner.os }}-node_modules-${{ hashFiles('**/*/package.json') }} 38 | - name: Build latest version of app 39 | run: | 40 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 41 | ./bin/build-latest-version 42 | - name: Pull docker image 43 | run: | 44 | cd $GITHUB_WORKSPACE/App 45 | docker pull ruby:3.0.1-alpine --quiet 46 | docker-compose pull --quiet 47 | - uses: satackey/action-docker-layer-caching@v0 48 | with: 49 | key: ${{ runner.os }}-docker-${{ hashFiles('**/*/Dockerfile') }} 50 | restore-keys: | 51 | ${{ runner.os }}-docker- 52 | - name: Cache Assets 53 | uses: actions/cache@v2 54 | with: 55 | path: | 56 | ${{ github.workspace }}/App/public/assets 57 | ${{ github.workspace }}/App/public/packs-test 58 | key: ${{ runner.os }}-assets-${{ hashFiles('**/*/yarn.lock') }} 59 | - name: Cache gems 60 | uses: actions/cache@v2 61 | with: 62 | path: | 63 | ${{ github.workspace }}/App/vendor/bundle 64 | key: ${{ runner.os }}-bundle-${{ hashFiles('**/*/Gemfile.lock') }} 65 | - name: Do the test still pass in our new template? 66 | run: | 67 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 68 | ./bin/test-latest-version 69 | - name: What would we be committing? 70 | run: | 71 | cd $GITHUB_WORKSPACE/App 72 | git status 73 | -------------------------------------------------------------------------------- /.github/workflows/update-template-repo.yml: -------------------------------------------------------------------------------- 1 | name: Update Template Repo 2 | 3 | on: 4 | workflow_dispatch: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: '0 5 1 * *' 10 | 11 | jobs: 12 | build: 13 | runs-on: ubuntu-latest 14 | timeout-minutes: 15 15 | if: "!contains(github.event.head_commit.message, '[nodoc]')" 16 | steps: 17 | - uses: actions/checkout@v2 18 | with: 19 | repository: "Ruby-Starter-Kits/Docker-Rails-Template" 20 | path: App 21 | persist-credentials: false 22 | - uses: actions/checkout@v2 23 | with: 24 | repository: 'Ruby-Starter-Kits/Docker-Rails-Generator' 25 | path: Docker-Rails-Generator 26 | persist-credentials: false 27 | - name: Set up Ruby 3.0 28 | uses: ruby/setup-ruby@v1 29 | with: 30 | ruby-version: 3.0.1 31 | bundler: none 32 | - name: Build Environment for building app 33 | run: | 34 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 35 | ./bin/build-environment-for-building-app 36 | - uses: actions/cache@v2 37 | with: 38 | path: ${{ github.workspace }}/vendor/bundle 39 | key: ${{ runner.os }}-gem-${{ hashFiles('**/*/Gemfile.lock') }} 40 | - uses: actions/cache@v2 41 | with: 42 | path: ${{ github.workspace }}/App/node_modules 43 | key: ${{ runner.os }}-node_modules-${{ hashFiles('**/*/package.json') }} 44 | - name: Build latest version of app 45 | run: | 46 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 47 | ./bin/build-latest-version 48 | - name: Pull docker image 49 | run: | 50 | cd $GITHUB_WORKSPACE/App 51 | docker pull ruby:3.0.1-alpine --quiet 52 | docker-compose pull --quiet 53 | - uses: satackey/action-docker-layer-caching@v0 54 | with: 55 | key: ${{ runner.os }}-docker-${{ hashFiles('**/*/Dockerfile') }} 56 | restore-keys: | 57 | ${{ runner.os }}-docker- 58 | - name: Cache Assets 59 | uses: actions/cache@v2 60 | with: 61 | path: | 62 | ${{ github.workspace }}/App/public/assets 63 | ${{ github.workspace }}/App/public/packs-test 64 | key: ${{ runner.os }}-assets-${{ hashFiles('**/*/yarn.lock') }} 65 | - name: Cache gems 66 | uses: actions/cache@v2 67 | with: 68 | path: | 69 | ${{ github.workspace }}/App/vendor/bundle 70 | key: ${{ runner.os }}-bundle-${{ hashFiles('**/*/Gemfile.lock') }} 71 | - name: Test we can build the docker image & the test still pass 72 | run: | 73 | cd $GITHUB_WORKSPACE/Docker-Rails-Generator 74 | ./bin/test-latest-version 75 | - name: Commit any new files 76 | run: | 77 | cd $GITHUB_WORKSPACE/App 78 | DOCKER_RAILS_INSTALLER_VERSION="Installer 1.0.0" 79 | RAILS_VERSION=`rails -v` 80 | 81 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 82 | git config --local user.name "github-actions[bot]" 83 | git add . 84 | git commit -am "$RAILS_VERSION | $DOCKER_RAILS_INSTALLER_VERSION" || echo "No changes to commit" 85 | - name: Push changes 86 | uses: ad-m/github-push-action@master 87 | with: 88 | github_token: ${{ secrets.LOCAL_GIT_TOKEN }} 89 | repository: 'Ruby-Starter-Kits/Docker-Rails-Template' 90 | directory: App 91 | branch: ${{ github.ref }} 92 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /App 2 | -------------------------------------------------------------------------------- /App-Template/.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | 4 | # 5 | # OS X 6 | # 7 | .DS_Store 8 | .AppleDouble 9 | .LSOverride 10 | # Icon must end with two \r 11 | Icon 12 | # Thumbnails 13 | ._* 14 | # Files that might appear on external disk 15 | .Spotlight-V100 16 | .Trashes 17 | # Directories potentially created on remote AFP share 18 | .AppleDB 19 | .AppleDesktop 20 | Network Trash Folder 21 | Temporary Items 22 | .apdisk 23 | 24 | # 25 | # Rails 26 | # 27 | *.rbc 28 | capybara-*.html 29 | log 30 | db/*.sqlite3 31 | db/*.sqlite3-journal 32 | public/system 33 | yarn-error.log 34 | yarn-debug.log* 35 | .yarn-integrity 36 | external_dns.log 37 | 38 | coverage/ 39 | spec/tmp 40 | **.orig 41 | 42 | .bundle 43 | 44 | .ruby-gemset 45 | 46 | .rvmrc 47 | 48 | # if using bower-rails ignore default bower_components path bower.json files 49 | vendor/assets/bower_components 50 | *.bowerrc 51 | bower.json 52 | -------------------------------------------------------------------------------- /App-Template/.env.example: -------------------------------------------------------------------------------- 1 | # If you want, you can run: 2 | # $ docker-compose up redis postgres 3 | # $ bundle exec rails s 4 | # I know for some people it's a little more performant :) 5 | REDIS_URL=redis://@127.0.0.1:6379/1 6 | DATABASE_URL=postgres://postgres:postgres@127.0.0.1:5432/ 7 | 8 | # Set a default host value - Useful for mailers & _url routes. 9 | URL=127.0.0.1:3000 10 | URL_PROTOCOL=http 11 | 12 | # Set a rails master key 13 | # RAILS_MASTER_KEY="bundle exec rake secret | cut -c -32" 14 | -------------------------------------------------------------------------------- /App-Template/.github/dependabot.yml.sample: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | # Dependabot: Disabled by default as it can be scary to see a bunch of Pull Requests open on a new template. 4 | # 5 | # Plus, I'm also worried about Dependabot as an vector for stealing test API data (e.g someone pushing a compromised 6 | # version of a library). 7 | 8 | updates: 9 | 10 | # Maintain dependencies for GitHub Actions 11 | - package-ecosystem: "github-actions" 12 | directory: "/" 13 | schedule: 14 | interval: "daily" 15 | 16 | # Maintain dependencies for npm 17 | - package-ecosystem: "npm" 18 | directory: "/" 19 | schedule: 20 | interval: "daily" 21 | 22 | # Maintain dependencies for Bundler 23 | - package-ecosystem: "bundler" 24 | directory: "/" 25 | schedule: 26 | interval: "daily" 27 | 28 | # Maintain dependencies for Docker 29 | - package-ecosystem: "docker" 30 | directory: "/" 31 | schedule: 32 | interval: "daily" 33 | -------------------------------------------------------------------------------- /App-Template/.github/workflows/linters.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Linters 3 | 4 | on: 5 | push: 6 | branches-ignore: 7 | - master 8 | 9 | jobs: 10 | # https://github.com/github/super-linter 11 | super_linter: 12 | if: false 13 | runs-on: ubuntu-latest 14 | steps: 15 | - name: Checkout Code 16 | uses: actions/checkout@v2 17 | - name: Lint Code Base 18 | uses: docker://github/super-linter:v2.1.0 19 | 20 | # https://github.com/devmasx/brakeman-linter-action 21 | brakeman: 22 | runs-on: ubuntu-latest 23 | steps: 24 | - uses: actions/checkout@v1 25 | - name: Brakeman 26 | uses: devmasx/brakeman-linter-action@v1.0.0 27 | env: 28 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 29 | -------------------------------------------------------------------------------- /App-Template/.github/workflows/standard.yml: -------------------------------------------------------------------------------- 1 | name: Standard 2 | 3 | on: 4 | push: 5 | branches-ignore: 6 | - master 7 | jobs: 8 | standard: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Set up Ruby 14 | uses: ruby/setup-ruby@v1 15 | with: 16 | bundler-cache: true 17 | - name: Run Standard 18 | run: bundle exec standardrb 19 | -------------------------------------------------------------------------------- /App-Template/.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Tests 3 | 4 | on: 5 | push: 6 | 7 | jobs: 8 | test: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v1 13 | - name: Pull docker images 14 | run: | 15 | docker pull ruby:3.0.1-alpine --quiet 16 | docker-compose -f docker-compose.ci.yml pull --quiet 17 | 18 | # Cache the docker layers to help speed up the Docker build times. 19 | - uses: satackey/action-docker-layer-caching@v0 20 | with: 21 | key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }} 22 | restore-keys: | 23 | ${{ runner.os }}-docker- 24 | 25 | # We as store the node_modules & gems outside of the build, we can use actions/cache to persist them between 26 | # runs of this action. 27 | - name: Cache Assets 28 | uses: actions/cache@v2 29 | with: 30 | path: | 31 | **/node_modules 32 | public/assets 33 | public/packs-test 34 | key: ${{ runner.os }}-assets-${{ hashFiles('**/yarn.lock') }} 35 | - name: Cache gems 36 | uses: actions/cache@v2 37 | with: 38 | path: | 39 | vendor/bundle 40 | key: ${{ runner.os }}-bundle-${{ hashFiles('**/Gemfile.lock') }} 41 | 42 | # Build the Docker image we're testing our app on. 43 | - name: Build Latest 44 | run: | 45 | docker-compose -f docker-compose.ci.yml build --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -u)" test 46 | # Download the node_modules & gems, along with setting up a clean database. 47 | - name: Setup Environment 48 | run: | 49 | docker-compose -f docker-compose.ci.yml run --rm --user="$(id -u):$(id -g)" test ./bin/setup 50 | # Finally run the tests :D 51 | - name: Run tests 52 | run: | 53 | docker-compose -f docker-compose.ci.yml run --rm --user="$(id -u):$(id -g)" test 54 | 55 | # This will remove any dangling docker data & stop our cache from ballooning out of control. 56 | - name: Clean Up After Tests 57 | run: | 58 | docker image prune -f 59 | docker volume prune -f 60 | -------------------------------------------------------------------------------- /App-Template/.gitignore.append: -------------------------------------------------------------------------------- 1 | 2 | # Ignore .envs - They store environmental variables 3 | .env 4 | 5 | # Ignore the vendor bundle 6 | vendor/bundle/ 7 | -------------------------------------------------------------------------------- /App-Template/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /App-Template/.rubocop.yml: -------------------------------------------------------------------------------- 1 | # This reformats the Rails to follow the Rubocop cop basic standard, it's there because StandardRB 2 | # still isn't perfect. 3 | 4 | AllCops: 5 | TargetRubyVersion: 3.0 6 | NewCops: disable 7 | Exclude: 8 | - 'db/schema.rb' 9 | - 'node_modules/**/*' 10 | - 'vendor/**/*' 11 | - '.git/**/*' 12 | - 'bin/*' 13 | - 'tmp/**/*' 14 | 15 | Style/FrozenStringLiteralComment: 16 | Enabled: false 17 | -------------------------------------------------------------------------------- /App-Template/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.0.1-alpine AS builder 2 | LABEL maintainer="Mike Rogers " 3 | 4 | RUN apk --no-cache add --virtual build-dependencies \ 5 | build-base \ 6 | openssl \ 7 | # Nokogiri Libraries 8 | zlib-dev \ 9 | libxml2-dev \ 10 | libxslt-dev \ 11 | # Postgres 12 | postgresql-dev \ 13 | # JavaScript 14 | nodejs \ 15 | yarn \ 16 | # FFI Bindings in ruby (Run C Commands) 17 | libffi-dev \ 18 | # Fixes watch file issues with things like HMR 19 | libnotify-dev 20 | 21 | # Dockerize allows us to wait for other containers to be ready before we run our own code. 22 | ENV DOCKERIZE_VERSION v0.6.1 23 | RUN wget -nv https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ 24 | && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ 25 | && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz 26 | 27 | # Rails Specific libraries 28 | RUN apk --no-cache add \ 29 | # ActiveStorage file inspection 30 | file \ 31 | # Time zone data 32 | tzdata \ 33 | # HTML to PDF conversion 34 | # ttf-ubuntu-font-family \ 35 | # wkhtmltopdf \ 36 | # Image Resizing 37 | imagemagick \ 38 | vips \ 39 | # Nice to have 40 | bash \ 41 | git \ 42 | # VIM is a handy editor for editing credentials 43 | vim \ 44 | # Allows for mimemagic gem to be installed 45 | shared-mime-info 46 | 47 | # Install any extra dependencies via Aptfile - These are installed on Heroku 48 | # COPY Aptfile /usr/src/app/Aptfile 49 | # RUN apk add --update $(cat /usr/src/app/Aptfile | xargs) 50 | 51 | FROM builder AS development 52 | 53 | # Set common ENVs 54 | ENV BOOTSNAP_CACHE_DIR /usr/src/bootsnap 55 | ENV YARN_CACHE_FOLDER /usr/src/yarn 56 | ENV EDITOR vim 57 | ENV LANG en_US.UTF-8 58 | ENV BUNDLE_PATH /usr/local/bundle 59 | ENV RAILS_LOG_TO_STDOUT enabled 60 | ENV HISTFILE /usr/src/app/log/.bash_history 61 | 62 | # Set build args. These let linux users not run into file permission problems 63 | ARG USER_ID=${USER_ID:-1000} 64 | ARG GROUP_ID=${GROUP_ID:-1000} 65 | 66 | # Add non-root user and group with alpine first available uid, 1000 67 | RUN addgroup -g $USER_ID -S appgroup \ 68 | && adduser -u $GROUP_ID -S appuser -G appgroup 69 | 70 | # Install multiple gems at the same time 71 | RUN bundle config set jobs $(nproc) 72 | 73 | # Create app directory in the conventional /usr/src/app 74 | RUN mkdir -p /usr/src/app \ 75 | && mkdir -p /usr/src/app/node_modules \ 76 | && mkdir -p /usr/src/app/public/packs \ 77 | && mkdir -p /usr/src/app/tmp/cache \ 78 | && mkdir -p $YARN_CACHE_FOLDER \ 79 | && mkdir -p $BOOTSNAP_CACHE_DIR \ 80 | && chown -R appuser:appgroup /usr/src/app \ 81 | && chown -R appuser:appgroup $BUNDLE_PATH \ 82 | && chown -R appuser:appgroup $BOOTSNAP_CACHE_DIR \ 83 | && chown -R appuser:appgroup $YARN_CACHE_FOLDER 84 | WORKDIR /usr/src/app 85 | 86 | ENV PATH /usr/src/app/bin:$PATH 87 | 88 | # Add a script to be executed every time the container starts. 89 | COPY bin/docker/entrypoints/* /usr/bin/ 90 | RUN chmod +x /usr/bin/wait-for-postgres.sh 91 | RUN chmod +x /usr/bin/wait-for-web.sh 92 | ENTRYPOINT ["/usr/bin/wait-for-postgres.sh"] 93 | 94 | # Define the user running the container 95 | USER appuser 96 | 97 | EXPOSE 3000 98 | CMD ["./bin/rails", "server", "-b", "0.0.0.0", "-p", "3000"] 99 | 100 | FROM development AS production 101 | 102 | ENV RAILS_ENV production 103 | ENV RACK_ENV production 104 | ENV NODE_ENV production 105 | 106 | COPY Gemfile /usr/src/app 107 | COPY .ruby-version /usr/src/app 108 | COPY Gemfile.lock /usr/src/app 109 | 110 | # Install Ruby Gems 111 | RUN bundle config set deployment 'true' \ 112 | && bundle config set without 'development:test' \ 113 | && bundle check || bundle install --jobs=$(nproc) 114 | 115 | COPY package.json /usr/src/app 116 | COPY yarn.lock /usr/src/app 117 | 118 | # Install Yarn Libraries 119 | RUN yarn install --frozen-lockfile --check-files 120 | 121 | # Chown files so non are root. 122 | COPY --chown=appuser:appgroup . /usr/src/app 123 | 124 | # Precompile the assets, yarn relay & bootsnap 125 | RUN RAILS_SERVE_STATIC_FILES=enabled \ 126 | SECRET_KEY_BASE=secret-key-base \ 127 | bundle exec rake assets:precompile \ 128 | && bundle exec bootsnap precompile --gemfile app/ lib/ 129 | -------------------------------------------------------------------------------- /App-Template/Gemfile.append: -------------------------------------------------------------------------------- 1 | gem "barnes", "~> 0.0.8" 2 | gem "image_processing", "~> 1.12" 3 | gem "lograge", "~> 0.11.2" 4 | gem "redis", "~> 4.2" 5 | gem "sentry-raven", "~> 3.1" 6 | gem "sidekiq", "~> 6.1" 7 | gem "sidekiq-cron", "~> 1.2" 8 | gem "premailer-rails", "~> 1.11" 9 | 10 | group :development, :test do 11 | gem "dotenv-rails", "~> 2.7" 12 | gem "factory_bot_rails" 13 | gem "rspec-rails", "~> 4.0" 14 | end 15 | 16 | group :development do 17 | gem "letter_opener", "~> 1.7" 18 | gem "letter_opener_web", "~> 1.4" 19 | gem "standardrb", "~> 1.0", require: false 20 | end 21 | -------------------------------------------------------------------------------- /App-Template/Procfile: -------------------------------------------------------------------------------- 1 | # The Procfile is used by Heroku to define which services you'd like to run. 2 | ## Release tasks are used to automated running migrations on deploy. 3 | release: ./bin/heroku/release-tasks.sh 4 | 5 | ## Web Instance, this'll serve TCP requests 6 | web: ./bin/rails server -p ${PORT:-5000} 7 | 8 | ## Sidekiq is the de-facto standard choice for running Background tasks 9 | # worker: ./bin/bundle exec sidekiq -C config/sidekiq.yml 10 | -------------------------------------------------------------------------------- /App-Template/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | [![Use this template](https://img.shields.io/badge/Use_this_template-2ea44f?style=for-the-badge&logo=github)](https://github.com/Ruby-Starter-Kits/Docker-Rails-Template/generate) 4 | 5 |

6 | 7 | # Rails App 8 | 9 | Welcome to your [Ruby On Rails](https://rubyonrails.org/) app. 10 | 11 | ## Setup & Running Locally 12 | 13 | Clone down the repo, install [Docker](https://hub.docker.com/editions/community/docker-ce-desktop-mac/) & run: 14 | 15 | ```bash 16 | $ ./bin/docker/setup 17 | $ ./bin/docker/start 18 | ``` 19 | 20 | This will build the docker image, then setup the `bin/setup` file which will run `bundle`, `yarn` & create the database. 21 | 22 | Then navigate your browser to https://127.0.0.1:3000/ to see your site. 23 | 24 | ### Running one of commands 25 | 26 | To run a one off command, run it within the web service, e.g: 27 | 28 | ```bash 29 | $ ./bin/docker/bundle exec rails db:migrate 30 | $ ./bin/docker/bundle 31 | $ ./bin/docker/yarn 32 | ``` 33 | 34 | ### Restoring a database 35 | 36 | If you have an existing database dump in a file called `latest.dump`, you can restore it by turning on just the postgres service in one terminal tab, and running `pg_restore` in a secondary tab: 37 | 38 | ```bash 39 | $ docker-compose up postgres 40 | $ pg_restore --verbose --clean --no-acl --no-owner -j 2 -h localhost -d App_development --username postgres latest.dump 41 | ``` 42 | 43 | ## Tests 44 | 45 | The template comes preconfigured with [RSpec](https://rspec.info/) for tests, and comes with a [GitHub Action](https://github.com/Ruby-Starter-Kits/Docker-Rails-Template/blob/master/.github/workflows/tests.yml) to run them when you push to GitHub. 46 | 47 | You can run RSpec locally by running: 48 | 49 | ```bash 50 | $ docker-compose -f docker-compose.ci.yml run --rm test 51 | ``` 52 | 53 | ## Linting 54 | 55 | This app uses [Standard](https://github.com/testdouble/standard) for Ruby and includes a [GitHub Action](https://github.com/Ruby-Starter-Kits/Docker-Rails-Template/blob/master/.github/workflows/standard.yml) to check future commits are up to standard. 56 | 57 | ## Contributing 58 | 59 | This was generated by [Ruby-Starter-Kits/Docker-Rails-Generator](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator), if you have any ideas please report them there :) 60 | 61 | ## Usage 62 | 63 | Feel free to use these as a starting point for your own Ruby on Rails project! 64 | 65 | ## Resources 66 | 67 | * [Ruby on Rails Guides](https://guides.rubyonrails.org/) 68 | * [Ruby on Rails API Documentation](https://api.rubyonrails.org/) 69 | * [Heroku](https://www.heroku.com/) 70 | * [Docker-Rails-Generator](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator) 71 | 72 | ## License 73 | 74 | [MIT](https://opensource.org/licenses/MIT) 75 | 76 | Copyright (c) 2020-present, [Mike Rogers](https://mikerogers.io/) 77 | -------------------------------------------------------------------------------- /App-Template/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Docker-Rails-Template", 3 | "description": "A starting point I use for my Ruby on Rails apps", 4 | "env": { 5 | "DURING_RELEASE_RUN_MIGRATIONS": { 6 | "required": true, 7 | "value": "enabled" 8 | }, 9 | "DURING_RELEASE_SEED_DB": { 10 | "required": false, 11 | "value": "enabled" 12 | }, 13 | "LANG": { 14 | "required": true, 15 | "value": "en_US.UTF-8" 16 | }, 17 | "RACK_ENV": { 18 | "required": true, 19 | "value": "production" 20 | }, 21 | "RAILS_ENV": { 22 | "required": true, 23 | "value": "production" 24 | }, 25 | "RAILS_LOG_TO_STDOUT": { 26 | "required": true, 27 | "value": "enabled" 28 | }, 29 | "RAILS_MAX_THREADS": { 30 | "required": true, 31 | "value": "18" 32 | }, 33 | "RAILS_SERVE_STATIC_FILES": { 34 | "required": true, 35 | "value": "enabled" 36 | }, 37 | "SECRET_KEY_BASE": { 38 | "required": false 39 | }, 40 | "SIDEKIQ_PASSWORD": { 41 | "required": false 42 | }, 43 | "SIDEKIQ_USERNAME": { 44 | "required": false 45 | }, 46 | "URL": { 47 | "required": false 48 | } 49 | }, 50 | "buildpacks": [ 51 | { 52 | "url": "heroku/metrics" 53 | }, 54 | { 55 | "url": "https://github.com/heroku/heroku-buildpack-activestorage-preview" 56 | }, 57 | { 58 | "url": "heroku/ruby" 59 | } 60 | ], 61 | "environments": { 62 | "production": { 63 | "addons": [ 64 | "heroku-redis:hobby-dev", 65 | "heroku-postgresql:hobby-dev", 66 | "sendgrid", 67 | "papertrail", 68 | "sentry" 69 | ], 70 | "formation": {} 71 | }, 72 | "review": { 73 | "addons": [ 74 | "heroku-redis:hobby-dev", 75 | "heroku-postgresql:hobby-dev", 76 | "mailtrap", 77 | "papertrail" 78 | ], 79 | "formation": {} 80 | }, 81 | "test": {} 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /App-Template/app/jobs/sentry_job.rb: -------------------------------------------------------------------------------- 1 | class SentryJob < ApplicationJob 2 | queue_as :sentry 3 | 4 | def perform(event) 5 | Raven.send_event(event) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /App-Template/app/models/application_record.rb: -------------------------------------------------------------------------------- 1 | class ApplicationRecord < ActiveRecord::Base 2 | self.abstract_class = true 3 | 4 | scope :newest, -> { order(created_at: :desc) } 5 | scope :oldest, -> { order(created_at: :asc) } 6 | scope :freshest, -> { order(updated_at: :desc) } 7 | scope :stalest, -> { order(updated_at: :asc) } 8 | end 9 | -------------------------------------------------------------------------------- /App-Template/bin/docker/bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | docker-compose run --rm web bash 5 | -------------------------------------------------------------------------------- /App-Template/bin/docker/bundle: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | exec docker-compose --rm web bundle "$@" 5 | -------------------------------------------------------------------------------- /App-Template/bin/docker/entrypoints/wait-for-postgres.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Wait for Postgres to start before doing anything 5 | echo "" 6 | echo "== ⏱ Waiting for Postgres before running: $@ ==" 7 | dockerize -wait tcp://postgres:5432 -timeout 60s -wait-retry-interval 5s 8 | 9 | # Then exec the container's main process (what's set as CMD in the Dockerfile). 10 | echo "" 11 | echo "== 🏎 Running: $@ ==" 12 | exec "$@" 13 | -------------------------------------------------------------------------------- /App-Template/bin/docker/entrypoints/wait-for-web.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | # Wait for Web to start before doing anything 5 | echo "" 6 | echo "== ⏱ Waiting for Postgres & Web to start before running: $@ ==" 7 | dockerize -wait tcp://postgres:5432 -wait tcp://web:3000 -timeout 60s -wait-retry-interval 5s 8 | 9 | # Then exec the container's main process (what's set as CMD in the Dockerfile). 10 | echo "" 11 | echo "== 🏎 Running: $@ ==" 12 | exec "$@" 13 | -------------------------------------------------------------------------------- /App-Template/bin/docker/prepare-to-start-rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "fileutils" 5 | 6 | # path to your application root. 7 | APP_ROOT = File.expand_path("../../", __dir__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | FileUtils.chdir APP_ROOT do 14 | # This script is a way to prepare your environment for when Docker is about to start Rails. 15 | # This script is idempotent, so that you can run it at anytime and get an expectable outcome. 16 | # Add necessary setup steps to this file. 17 | 18 | puts "\n== Clearing up any previous Rails Instances ==" 19 | system "rm -rf tmp/pids/server.pid" 20 | 21 | puts "== Checking dependencies ==" 22 | system! "gem install bundler --conservative" 23 | system("bundle check") || system!("bundle install") 24 | 25 | # Install JavaScript dependencies 26 | system("bin/yarn") 27 | end 28 | -------------------------------------------------------------------------------- /App-Template/bin/docker/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path("../../", __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This turns sets up up the docker image 13 | puts "\n== Copying sample files ==" 14 | unless File.exist?(".env") 15 | FileUtils.cp ".env.template", ".env" 16 | end 17 | 18 | puts "== Pulling Images ==" 19 | system! "docker-compose pull" 20 | 21 | puts "== Building Container ==" 22 | system! "docker-compose build" 23 | 24 | puts "== Installing Libraries ==" 25 | system! "docker-compose run --rm web ./bin/setup" 26 | 27 | puts "== 🎉 Success, now you can run ./bin/docker/start" 28 | end 29 | -------------------------------------------------------------------------------- /App-Template/bin/docker/start: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | echo "== Turning on Docker ==" 5 | docker-compose up 6 | -------------------------------------------------------------------------------- /App-Template/bin/docker/yarn: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | exec docker-compose --rm web yarn "$@" 5 | -------------------------------------------------------------------------------- /App-Template/bin/heroku/release-tasks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Running Release Tasks" 4 | 5 | # These run after a deploy has been build, but before it has been released. 6 | if [ "$DURING_RELEASE_RUN_MIGRATIONS" == "enabled" ]; then 7 | echo "Running Migrations" 8 | bundle exec rake db:migrate || exit $? 9 | fi 10 | 11 | if [ "$DURING_RELEASE_SEED_DB" == "enabled" ]; then 12 | echo "Running Seeds" 13 | bundle exec rake db:seed || exit $? 14 | fi 15 | 16 | echo "Done" 17 | -------------------------------------------------------------------------------- /App-Template/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | require "fileutils" 5 | 6 | # path to your application root. 7 | APP_ROOT = File.expand_path("..", __dir__) 8 | 9 | def system!(*args) 10 | system(*args) || abort("\n== Command #{args} failed ==") 11 | end 12 | 13 | FileUtils.chdir APP_ROOT do 14 | # This script is a way to setup or update your development environment automatically. 15 | # This script is idempotent, so that you can run it at anytime and get an expectable outcome. 16 | # Add necessary setup steps to this file. 17 | 18 | puts "== Installing dependencies ==" 19 | system! "gem install bundler --conservative" 20 | system("bundle check") || system!("bundle install") 21 | 22 | # Install JavaScript dependencies 23 | system("bin/yarn") 24 | 25 | puts "\n== Preparing database ==" 26 | system! "bin/rails db:prepare" 27 | 28 | puts "\n== Removing old logs and tempfiles ==" 29 | system! "bin/rails log:clear tmp:clear" 30 | 31 | puts "\n== Restarting application server ==" 32 | system! "bin/rails restart" 33 | end 34 | -------------------------------------------------------------------------------- /App-Template/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: redis 3 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 4 | 5 | test: 6 | adapter: test 7 | 8 | production: 9 | adapter: redis 10 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 11 | channel_prefix: App_production 12 | -------------------------------------------------------------------------------- /App-Template/config/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 9.3 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On macOS with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On macOS with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem 'pg' 16 | # 17 | default: &default 18 | adapter: postgresql 19 | encoding: unicode 20 | # For details on connection pooling, see Rails configuration guide 21 | # https://guides.rubyonrails.org/configuring.html#database-pooling 22 | pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 23 | url: <%= ENV['DATABASE_URL'] %> 24 | 25 | development: 26 | <<: *default 27 | database: App_development 28 | 29 | # The specified database role being used to connect to postgres. 30 | # To create additional roles in postgres see `$ createuser --help`. 31 | # When left blank, postgres will use the default role. This is 32 | # the same name as the operating system user that initialized the database. 33 | #username: App 34 | 35 | # The password associated with the postgres role (username). 36 | #password: 37 | 38 | # Connect on a TCP socket. Omitted by default since the client uses a 39 | # domain socket that doesn't need configuration. Windows does not have 40 | # domain sockets, so uncomment these lines. 41 | #host: localhost 42 | 43 | # The TCP port the server listens on. Defaults to 5432. 44 | # If your server runs on a different port number, change accordingly. 45 | #port: 5432 46 | 47 | # Schema search path. The server defaults to $user,public 48 | #schema_search_path: myapp,sharedapp,public 49 | 50 | # Minimum log levels, in increasing order: 51 | # debug5, debug4, debug3, debug2, debug1, 52 | # log, notice, warning, error, fatal, and panic 53 | # Defaults to warning. 54 | #min_messages: notice 55 | 56 | # Warning: The database defined as "test" will be erased and 57 | # re-generated from your development database when you run "rake". 58 | # Do not set this db to the same as development or production. 59 | test: 60 | <<: *default 61 | database: App_test 62 | 63 | # As with config/credentials.yml, you never want to store sensitive information, 64 | # like your database password, in your source code. If your source code is 65 | # ever seen by anyone, they now have access to your database. 66 | # 67 | # Instead, provide the password as a unix environment variable when you boot 68 | # the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database 69 | # for a full rundown on how to provide these environment variables in a 70 | # production deployment. 71 | # 72 | # On Heroku and other platform providers, you may have a full connection URL 73 | # available as an environment variable. For example: 74 | # 75 | # DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase" 76 | # 77 | # You can use this database configuration with: 78 | # 79 | # production: 80 | # url: <%= ENV['DATABASE_URL'] %> 81 | # 82 | production: 83 | <<: *default 84 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/action_mailer.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Default to Mailtrap if we have it, then fallback to sendgrid then SENDGRID_USERNAME. 3 | # If nothing is present. don't send emails (Which each environment can override if needed). 4 | if ENV["MAILTRAP_API_TOKEN"].present? 5 | require "net/http" 6 | require "uri" 7 | require "json" 8 | first_inbox = JSON.parse(Net::HTTP.get(URI.parse("https://mailtrap.io/api/v1/inboxes.json?api_token=#{ENV["MAILTRAP_API_TOKEN"]}")))[0] 9 | config.action_mailer.delivery_method = :smtp 10 | config.action_mailer.smtp_settings = { 11 | user_name: first_inbox["username"], 12 | password: first_inbox["password"], 13 | address: first_inbox["domain"], 14 | domain: first_inbox["domain"], 15 | port: first_inbox["smtp_ports"][0], 16 | authentication: :cram_md5 17 | } 18 | elsif ENV["SENDGRID_API_KEY"].present? 19 | # If you're using SendGrid you need to create an API key at: 20 | # https://app.sendgrid.com/settings/api_keys 21 | # with full access to "Mail Send" permissions. 22 | config.action_mailer.smtp_settings = { 23 | address: "smtp.sendgrid.net", 24 | port: 587, 25 | authentication: :plain, 26 | user_name: "apikey", 27 | password: ENV["SENDGRID_API_KEY"], 28 | domain: "heroku.com", 29 | enable_starttls_auto: true 30 | } 31 | elsif Rails.env.development? && defined?(LetterOpenerWeb) 32 | # https://github.com/fgrehm/letter_opener_web 33 | # Preview mailers in your browser. 34 | config.action_mailer.delivery_method = :letter_opener_web 35 | config.action_mailer.perform_deliveries = true 36 | else 37 | config.action_mailer.perform_deliveries = false 38 | end 39 | 40 | # Enable previewing mailers in review environments. 41 | config.action_mailer.show_previews = (ENV["ENABLE_MAILER_PREVIEWS"].present? || Rails.env.development?) 42 | end 43 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/assets.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Add some sensible caching headers all assets. Sometimes Nginx adds these, but not always. 3 | config.static_cache_control = "public, max-age=31536000" 4 | config.public_file_server.headers = { 5 | "Cache-Control" => "public, max-age=31536000", 6 | "Expires" => 1.year.from_now.to_formatted_s(:rfc822) 7 | } 8 | 9 | # Enable serving of images, stylesheets, and JavaScripts from an asset server (Normally https://cdn.yourdomain.com). 10 | if ENV["ASSET_HOST"] 11 | config.action_controller.asset_host = ENV["ASSET_HOST"] 12 | config.action_mailer.asset_host = ENV["ASSET_HOST"] 13 | elsif ENV["HEROKU_APP_NAME"].present? 14 | config.action_controller.asset_host = "https://#{ENV["HEROKU_APP_NAME"]}.herokuapp.com" 15 | config.action_mailer.asset_host = "https://#{ENV["HEROKU_APP_NAME"]}.herokuapp.com" 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/default_url_options.rb: -------------------------------------------------------------------------------- 1 | # Sets the default URL options to the URL env. 2 | if ENV["URL"].present? 3 | Rails.application.default_url_options = { 4 | host: ENV.fetch("URL", "127.0.0.1"), 5 | protocol: ENV.fetch("URL_PROTOCOL", "https") 6 | } 7 | elsif ENV["HEROKU_APP_NAME"].present? 8 | Rails.application.default_url_options = { 9 | protocol: "https", 10 | host: "#{ENV["HEROKU_APP_NAME"]}.herokuapp.com" 11 | } 12 | end 13 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/generators.rb: -------------------------------------------------------------------------------- 1 | # Disable a few of the generators I often just delete after they're created. 2 | Rails.application.config.generators do |g| 3 | g.assets false 4 | g.helper false 5 | g.view_specs false 6 | g.decorator false 7 | g.system_tests = nil 8 | g.jbuilder false 9 | end 10 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/locale.rb: -------------------------------------------------------------------------------- 1 | # Let break our locales into different files nested into subfiles 2 | 3 | Rails.application.configure do 4 | config.i18n.load_path += Dir[Rails.root.join("config/locales/**/*.{rb,yml}")] 5 | config.i18n.fallbacks = true 6 | # config.i18n.available_locales = [:en, :'en-GB', :de] 7 | 8 | ## If you're using the rack-contrib gem - You can use this middleware to auto set the locale. 9 | # config.middleware.use Rack::Locale 10 | end 11 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/logger.rb: -------------------------------------------------------------------------------- 1 | # By default Rails will keep writing to logs/development.log, this can lead to really large files. 2 | # Let's configure this to be at most 50mb. 3 | if Rails.env.development? 4 | Rails.logger = ActiveSupport::Logger.new(Rails.application.config.paths["log"].first, 1, 50.megabytes) 5 | end 6 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/lograge.rb: -------------------------------------------------------------------------------- 1 | # By default Rails can generate very verbose logs. 2 | # I'm a fan of: https://github.com/roidrage/lograge 3 | # It makes every request a single line in the logs. 4 | if defined?(Lograge) 5 | Rails.application.configure do 6 | config.lograge.enabled = true 7 | config.lograge.custom_options = lambda do |event| 8 | # No params? Must be ActionCable. 9 | return {} if event.payload[:params].blank? 10 | 11 | exceptions = %w[controller action format authenticity_token] 12 | 13 | { 14 | params: event.payload[:params].except(*exceptions) 15 | } 16 | end 17 | 18 | config.lograge.custom_payload do |controller| 19 | { 20 | host: controller.request.host, 21 | remote_ip: controller.request.remote_ip, 22 | api_key: controller.request.headers.env["HTTP_X_APIKEY"] 23 | } 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/sentry_raven.rb: -------------------------------------------------------------------------------- 1 | if defined?(Raven) 2 | Raven.configure do |config| 3 | config.async = ->(event) { SentryJob.perform_later(event) } 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/sidekiq.rb: -------------------------------------------------------------------------------- 1 | # Sidekiq is the de-facto standard choice for running Background tasks 2 | # You should use it to perform API requests & long running tasks. 3 | if defined?(Sidekiq) && ENV["REDIS_URL"].present? 4 | require "sidekiq/web" 5 | require "sidekiq/cron/web" if defined?(Sidekiq::Cron) 6 | 7 | # https://github.com/mperham/sidekiq/wiki/Monitoring#rails-http-basic-auth-from-routes 8 | Sidekiq::Web.use Rack::Auth::Basic do |username, password| 9 | ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USERNAME"])) & 10 | ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"])) 11 | end 12 | 13 | # https://github.com/ondrejbartas/sidekiq-cron 14 | # Sidekiq-cron - It's a very sensible approach to performing scheduled tasks. 15 | if Sidekiq.server? && defined?(Sidekiq::Cron) 16 | Rails.application.config.after_initialize do 17 | schedule_file = Rails.root.join("config/schedule.yml") 18 | schedule_file_yaml = YAML.load_file(schedule_file) if schedule_file.exist? 19 | 20 | # Use https://crontab.guru to confirm times 21 | Sidekiq::Cron::Job.load_from_hash(schedule_file_yaml) if schedule_file_yaml 22 | end 23 | end 24 | 25 | Sidekiq.configure_client do |_config| 26 | # Any client specific configuration 27 | end 28 | 29 | Rails.application.config.cache_store = :redis_cache_store, { 30 | url: ENV["REDIS_URL"], 31 | network_timeout: 5 32 | } 33 | Rails.application.config.active_job.queue_adapter = :sidekiq 34 | ActiveJob::Base.queue_adapter = :sidekiq 35 | else 36 | Rails.application.config.active_job.queue_adapter = :inline 37 | ActiveJob::Base.queue_adapter = :inline 38 | end 39 | -------------------------------------------------------------------------------- /App-Template/config/initializers/opinionated_defaults/web_console.rb: -------------------------------------------------------------------------------- 1 | # This adds the IP range for docker host, this allows us to use the web-console gem within docker. 2 | Rails.application.configure do 3 | if Rails.env.development? && defined?(WebConsole) 4 | config.web_console.permissions = %w( 172.0.0.0/10 ) 5 | 6 | # We have to reset the permissions like this as it's memorized within an initializer which is called 7 | # between the config/environments/development.rb file & this file. 8 | WebConsole::Request.permissions = WebConsole::Permissions.new(config.web_console.permissions) 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /App-Template/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 3 | 4 | mount Sidekiq::Web => "/sidekiq" if defined?(Sidekiq) && defined?(Sidekiq::Web) 5 | mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? 6 | end 7 | -------------------------------------------------------------------------------- /App-Template/config/schedule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Add any task you'd like to run a specific times. 3 | # 4 | # Daily Usage Summary: 5 | # :cron: 0 6 * * * 6 | # :class: Slack::UsageSummaryJob 7 | # :queue: slack__usage_summary 8 | -------------------------------------------------------------------------------- /App-Template/config/sidekiq.yml: -------------------------------------------------------------------------------- 1 | # Sample configuration file for Sidekiq. 2 | # Options here can still be overridden by cmd line args. 3 | # Place this file at config/sidekiq.yml and Sidekiq will 4 | # pick it up automatically. 5 | --- 6 | :verbose: false 7 | :concurrency: 3 8 | :max_retries: 3 9 | 10 | # Set timeout to 8 on Heroku, longer if you manage your own systems. 11 | :timeout: 8 12 | 13 | # Sidekiq will run this file through ERB when reading it so you can 14 | # even put in dynamic logic, like a host-specific queue. 15 | # http://www.mikeperham.com/2013/11/13/advanced-sidekiq-host-specific-queues/ 16 | :queues: 17 | - critical 18 | - sentry 19 | - mailers 20 | - default 21 | - action_mailbox_routing 22 | - action_mailbox_incineration 23 | - active_storage_analysis 24 | - active_storage_purge 25 | - low 26 | -------------------------------------------------------------------------------- /App-Template/db/schema.rb: -------------------------------------------------------------------------------- 1 | # This file is auto-generated from the current state of the database. Instead 2 | # of editing this file, please use the migrations feature of Active Record to 3 | # incrementally modify your database, and then regenerate this schema definition. 4 | # 5 | # This file is the source Rails uses to define your schema when running `rails 6 | # db:schema:load`. When creating a new database, `rails db:schema:load` tends to 7 | # be faster and is potentially less error prone than running all of your 8 | # migrations from scratch. Old migrations may fail to apply correctly if those 9 | # migrations use external dependencies or application code. 10 | # 11 | # It's strongly recommended that you check this file into your version control system. 12 | 13 | ActiveRecord::Schema.define(version: 0) do 14 | # These are extensions that must be enabled in order to support this database 15 | enable_extension "plpgsql" 16 | end 17 | -------------------------------------------------------------------------------- /App-Template/docker-compose.ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This is used to run the test suite within CI without requiring extra services. 3 | # 4 | ## Usage: 5 | # 6 | # docker-compose -f docker-compose.ci.yml build test 7 | # docker-compose -f docker-compose.ci.yml run --rm test 8 | version: '3' 9 | 10 | x-ci-app: &ci-app 11 | build: 12 | context: . 13 | dockerfile: Dockerfile 14 | target: development 15 | environment: 16 | DATABASE_URL: postgres://postgres:postgres@postgres:5432/ 17 | RAILS_ENV: test 18 | RACK_ENV: test 19 | BUNDLE_PATH: /usr/src/app/vendor/bundle 20 | entrypoint: ./bin/docker/entrypoints/wait-for-postgres.sh 21 | volumes: 22 | - .:/usr/src/app:cached 23 | depends_on: 24 | - postgres 25 | 26 | services: 27 | postgres: 28 | image: postgres:13.2-alpine 29 | environment: 30 | POSTGRES_USER: postgres 31 | POSTGRES_PASSWORD: postgres 32 | restart: on-failure 33 | logging: 34 | driver: none 35 | 36 | test: 37 | <<: *ci-app 38 | command: bash -c "./bin/setup && ./bin/rake assets:precompile && ./bin/bundle exec rspec" 39 | -------------------------------------------------------------------------------- /App-Template/docker-compose.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This is a set up for Ruby on Rails 6, running a worker & webpack. 3 | # Gems are cached within a volume, which speeds up development when adding new gems. 4 | # 5 | ## Usage: 6 | # 7 | # docker-compose build 8 | # docker-compose run --rm web bin/setup 9 | # docker-compose up 10 | version: "3" 11 | 12 | x-app: &app 13 | build: 14 | context: . 15 | dockerfile: Dockerfile 16 | target: development 17 | tmpfs: 18 | - /tmp 19 | environment: 20 | REDIS_URL: redis://@redis:6379/1 21 | DATABASE_URL: postgres://postgres:postgres@postgres:5432/ 22 | WEBPACKER_DEV_SERVER_HOST: webpacker 23 | entrypoint: ./bin/docker/entrypoints/wait-for-web.sh 24 | volumes: 25 | - .:/usr/src/app:cached 26 | - bundler:/usr/local/bundle:delegated 27 | - bootsnap_cache:/usr/src/bootsnap:delegated 28 | - rails_cache:/usr/src/app/tmp/cache:delegated 29 | - packs:/usr/src/app/public/packs:delegated 30 | - node_modules:/usr/src/app/node_modules:delegated 31 | - yarn_cache:/usr/src/yarn:delegated 32 | - letter_opener:/usr/src/app/tmp/letter_opener:delegated 33 | depends_on: 34 | - postgres 35 | - redis 36 | 37 | services: 38 | postgres: 39 | image: postgres:13.2-alpine 40 | volumes: 41 | - postgresql:/var/lib/postgresql/data:delegated 42 | # Uncomment to access this containers Postgres instance via port 5432 43 | #ports: 44 | #- "127.0.0.1:5432:5432" 45 | environment: 46 | PSQL_HISTFILE: /root/log/.psql_history 47 | POSTGRES_USER: postgres 48 | POSTGRES_PASSWORD: postgres 49 | restart: on-failure 50 | logging: 51 | driver: none 52 | 53 | redis: 54 | image: redis:6.0.12-alpine 55 | volumes: 56 | - redis:/data:delegated 57 | # Uncomment to access this containers Redis instance via port 6379 58 | #ports: 59 | #- "127.0.0.1:6379:6379" 60 | restart: on-failure 61 | logging: 62 | driver: none 63 | 64 | web: 65 | <<: *app 66 | entrypoint: ./bin/docker/entrypoints/wait-for-postgres.sh 67 | command: bash -c "./bin/docker/prepare-to-start-rails && ./bin/rails server -p 3000 -b '0.0.0.0'" 68 | ports: 69 | - "127.0.0.1:3000:3000" 70 | 71 | worker: 72 | <<: *app 73 | command: bundle exec sidekiq -C config/sidekiq.yml 74 | 75 | webpacker: 76 | <<: *app 77 | command: ./bin/webpack-dev-server 78 | environment: 79 | WEBPACKER_DEV_SERVER_HOST: 0.0.0.0 80 | ports: 81 | - "127.0.0.1:3035:3035" 82 | 83 | volumes: 84 | postgresql: 85 | redis: 86 | bundler: 87 | bootsnap_cache: 88 | rails_cache: 89 | packs: 90 | node_modules: 91 | yarn_cache: 92 | letter_opener: 93 | -------------------------------------------------------------------------------- /App-Template/spec/factory_bot_spec.rb: -------------------------------------------------------------------------------- 1 | require "rails_helper" 2 | 3 | describe FactoryBot do 4 | it { FactoryBot.lint traits: true } 5 | end 6 | -------------------------------------------------------------------------------- /App-Template/spec/rails_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | require "spec_helper" 3 | ENV["RAILS_ENV"] ||= "test" 4 | require File.expand_path("../config/environment", __dir__) 5 | # Prevent database truncation if the environment is production 6 | abort("The Rails environment is running in production mode!") if Rails.env.production? 7 | require "rspec/rails" 8 | # Add additional requires below this line. Rails is not loaded until this point! 9 | 10 | # Requires supporting ruby files with custom matchers and macros, etc, in 11 | # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are 12 | # run as spec files by default. This means that files in spec/support that end 13 | # in _spec.rb will both be required and run as specs, causing the specs to be 14 | # run twice. It is recommended that you do not name files matching this glob to 15 | # end with _spec.rb. You can configure this pattern with the --pattern 16 | # option on the command line or in ~/.rspec, .rspec or `.rspec-local`. 17 | # 18 | # The following line is provided for convenience purposes. It has the downside 19 | # of increasing the boot-up time by auto-requiring all files in the support 20 | # directory. Alternatively, in the individual `*_spec.rb` files, manually 21 | # require only the support files necessary. 22 | # 23 | Dir[Rails.root.join("spec/support/**/*.rb")].sort.each { |f| require f } 24 | 25 | # Checks for pending migrations and applies them before tests are run. 26 | # If you are not using ActiveRecord, you can remove these lines. 27 | begin 28 | ActiveRecord::Migration.maintain_test_schema! 29 | rescue ActiveRecord::PendingMigrationError => e 30 | puts e.to_s.strip 31 | exit 1 32 | end 33 | 34 | RSpec.configure do |config| 35 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 36 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 37 | 38 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 39 | # examples within a transaction, remove the following line or assign false 40 | # instead of true. 41 | config.use_transactional_fixtures = true 42 | 43 | # You can uncomment this line to turn off ActiveRecord support entirely. 44 | # config.use_active_record = false 45 | 46 | # RSpec Rails can automatically mix in different behaviours to your tests 47 | # based on their file location, for example enabling you to call `get` and 48 | # `post` in specs under `spec/controllers`. 49 | # 50 | # You can disable this behaviour by removing the line below, and instead 51 | # explicitly tag your specs with their type, e.g.: 52 | # 53 | # RSpec.describe UsersController, type: :controller do 54 | # # ... 55 | # end 56 | # 57 | # The different available types are documented in the features, such as in 58 | # https://relishapp.com/rspec/rspec-rails/docs 59 | config.infer_spec_type_from_file_location! 60 | 61 | # Filter lines from Rails gems in backtraces. 62 | config.filter_rails_from_backtrace! 63 | # arbitrary gems may also be filtered via: 64 | # config.filter_gems_from_backtrace("gem name") 65 | end 66 | -------------------------------------------------------------------------------- /App-Template/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file was generated by the `rails generate rspec:install` command. Conventionally, all 2 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 3 | # The generated `.rspec` file contains `--require spec_helper` which will cause 4 | # this file to always be loaded, without a need to explicitly require it in any 5 | # files. 6 | # 7 | # Given that it is always loaded, you are encouraged to keep this file as 8 | # light-weight as possible. Requiring heavyweight dependencies from this file 9 | # will add to the boot time of your test suite on EVERY test run, even for an 10 | # individual file that may not need all of that loaded. Instead, consider making 11 | # a separate helper file that requires the additional dependencies and performs 12 | # the additional setup, and require it from the spec files that actually need 13 | # it. 14 | # 15 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 16 | RSpec.configure do |config| 17 | # rspec-expectations config goes here. You can use an alternate 18 | # assertion/expectation library such as wrong or the stdlib/minitest 19 | # assertions if you prefer. 20 | config.expect_with :rspec do |expectations| 21 | # This option will default to `true` in RSpec 4. It makes the `description` 22 | # and `failure_message` of custom matchers include text for helper methods 23 | # defined using `chain`, e.g.: 24 | # be_bigger_than(2).and_smaller_than(4).description 25 | # # => "be bigger than 2 and smaller than 4" 26 | # ...rather than: 27 | # # => "be bigger than 2" 28 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 29 | end 30 | 31 | # rspec-mocks config goes here. You can use an alternate test double 32 | # library (such as bogus or mocha) by changing the `mock_with` option here. 33 | config.mock_with :rspec do |mocks| 34 | # Prevents you from mocking or stubbing a method that does not exist on 35 | # a real object. This is generally recommended, and will default to 36 | # `true` in RSpec 4. 37 | mocks.verify_partial_doubles = true 38 | end 39 | 40 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 41 | # have no way to turn it off -- the option exists only for backwards 42 | # compatibility in RSpec 3). It causes shared context metadata to be 43 | # inherited by the metadata hash of host groups and examples, rather than 44 | # triggering implicit auto-inclusion in groups with matching metadata. 45 | config.shared_context_metadata_behavior = :apply_to_host_groups 46 | 47 | # The settings below are suggested to provide a good initial experience 48 | # with RSpec, but feel free to customize to your heart's content. 49 | # # This allows you to limit a spec run to individual examples or groups 50 | # # you care about by tagging them with `:focus` metadata. When nothing 51 | # # is tagged with `:focus`, all examples get run. RSpec also provides 52 | # # aliases for `it`, `describe`, and `context` that include `:focus` 53 | # # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 54 | # config.filter_run_when_matching :focus 55 | # 56 | # # Allows RSpec to persist some state between runs in order to support 57 | # # the `--only-failures` and `--next-failure` CLI options. We recommend 58 | # # you configure your source control system to ignore this file. 59 | # config.example_status_persistence_file_path = "spec/examples.txt" 60 | # 61 | # # Limits the available syntax to the non-monkey patched syntax that is 62 | # # recommended. For more details, see: 63 | # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 64 | # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 65 | # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 66 | # config.disable_monkey_patching! 67 | # 68 | # # Many RSpec users commonly either run the entire suite or an individual 69 | # # file, and it's useful to allow more verbose output when running an 70 | # # individual spec file. 71 | # if config.files_to_run.one? 72 | # # Use the documentation formatter for detailed output, 73 | # # unless a formatter has already been configured 74 | # # (e.g. via a command-line flag). 75 | # config.default_formatter = "doc" 76 | # end 77 | # 78 | # # Print the 10 slowest examples and example groups at the 79 | # # end of the spec run, to help surface which specs are running 80 | # # particularly slow. 81 | # config.profile_examples = 10 82 | # 83 | # # Run specs in random order to surface order dependencies. If you find an 84 | # # order dependency and want to debug it, you can fix the order by providing 85 | # # the seed, which is printed after each run. 86 | # # --seed 1234 87 | # config.order = :random 88 | # 89 | # # Seed global randomization in this process using the `--seed` CLI option. 90 | # # Setting this allows you to use `--seed` to deterministically reproduce 91 | # # test failures related to randomization by passing the same `--seed` value 92 | # # as the one that triggered the failure. 93 | # Kernel.srand config.seed 94 | end 95 | -------------------------------------------------------------------------------- /App-Template/spec/support/active_job.rb: -------------------------------------------------------------------------------- 1 | ActiveJob::Base.queue_adapter = :test 2 | -------------------------------------------------------------------------------- /App-Template/spec/support/factory_bot.rb: -------------------------------------------------------------------------------- 1 | RSpec.configure do |config| 2 | config.include FactoryBot::Syntax::Methods 3 | end 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [Unreleased](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/tree/HEAD) 4 | 5 | [Full Changelog](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/compare/43a8d3381e1a5702e1dae0bdfd35170b8148c2ba...HEAD) 6 | 7 | **Implemented enhancements:** 8 | 9 | - Not sharing redis/postgres ports with host machine by default [\#77](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/77) ([MikeRogers0](https://github.com/MikeRogers0)) 10 | - Adding storage as volume to docker-compose [\#16](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/16) ([MikeRogers0](https://github.com/MikeRogers0)) 11 | - Setup custom database.yml [\#11](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/11) ([MikeRogers0](https://github.com/MikeRogers0)) 12 | - Using rsync to copy hidden files [\#9](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/9) ([MikeRogers0](https://github.com/MikeRogers0)) 13 | - Renaming Docker-Rails-New \> Docker-Rails-Template [\#6](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/6) ([MikeRogers0](https://github.com/MikeRogers0)) 14 | - Auto building the "Docker-Rails-New" repo from our template [\#4](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/4) ([MikeRogers0](https://github.com/MikeRogers0)) 15 | 16 | **Closed issues:** 17 | 18 | - Permission defined error caused by yarn cache clean --all [\#91](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/issues/91) 19 | - Add ERB Lint [\#75](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/issues/75) 20 | - Use V3 of Docker-Compose [\#66](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/issues/66) 21 | - PostgreSQL log mount makes log directory unwritable by Rails [\#49](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/issues/49) 22 | 23 | **Merged pull requests:** 24 | 25 | - fix: Mailtrap was unable to load the JSON as open\(\) wasn't loaded [\#96](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/96) ([MikeRogers0](https://github.com/MikeRogers0)) 26 | - feat: Move common docker commands into bin files [\#95](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/95) ([MikeRogers0](https://github.com/MikeRogers0)) 27 | - fix: Explicitly setting ActiveJob queue adapter [\#94](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/94) ([MikeRogers0](https://github.com/MikeRogers0)) 28 | - bug: Removing yarn cache clean --all from Dockerfile [\#93](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/93) ([MikeRogers0](https://github.com/MikeRogers0)) 29 | - doc: Add example on how to generate Rails Master Key [\#92](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/92) ([MikeRogers0](https://github.com/MikeRogers0)) 30 | - feat: Increasing timeout and retry interval [\#90](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/90) ([MikeRogers0](https://github.com/MikeRogers0)) 31 | - feat: Adds support for web-console [\#89](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/89) ([MikeRogers0](https://github.com/MikeRogers0)) 32 | - refactor: Additional wins for the Dockerfile [\#88](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/88) ([MikeRogers0](https://github.com/MikeRogers0)) 33 | - Bumping installer version to 1.0.0 [\#87](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/87) ([MikeRogers0](https://github.com/MikeRogers0)) 34 | - Upgrading to Ruby 3.0.1 [\#86](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/86) ([MikeRogers0](https://github.com/MikeRogers0)) 35 | - Some of the files were consistent, so fixing adhoc bits [\#85](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/85) ([MikeRogers0](https://github.com/MikeRogers0)) 36 | - Upgrading to Docker Compose V3 [\#84](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/84) ([MikeRogers0](https://github.com/MikeRogers0)) 37 | - Upgrade to GitHub-native Dependabot [\#81](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/81) ([dependabot-preview[bot]](https://github.com/apps/dependabot-preview)) 38 | - Adding workflow dispatch for updating the template repo [\#80](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/80) ([MikeRogers0](https://github.com/MikeRogers0)) 39 | - Locking github\_changelog\_generator to v1.15.2 [\#79](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/79) ([MikeRogers0](https://github.com/MikeRogers0)) 40 | - Upgrading to Postgres 13.2 & Redis 6.0.12 [\#78](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/78) ([MikeRogers0](https://github.com/MikeRogers0)) 41 | - Adding shared-mime-info package to Dockerfile [\#76](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/76) ([MikeRogers0](https://github.com/MikeRogers0)) 42 | - Moving rubocop file to be hidden [\#74](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/74) ([MikeRogers0](https://github.com/MikeRogers0)) 43 | - Readding rubocop.yml for build-stage [\#73](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/73) ([MikeRogers0](https://github.com/MikeRogers0)) 44 | - Removing RAILS\_ENV from Procfile [\#72](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/72) ([MikeRogers0](https://github.com/MikeRogers0)) 45 | - Updating to Ruby 3.0 [\#71](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/71) ([MikeRogers0](https://github.com/MikeRogers0)) 46 | - Using ENV\["URL"\] for setting URL of host [\#70](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/70) ([MikeRogers0](https://github.com/MikeRogers0)) 47 | - Clearing logs on startup [\#68](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/68) ([MikeRogers0](https://github.com/MikeRogers0)) 48 | - Fixing Rubocop reference in standardrb file [\#67](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/67) ([MikeRogers0](https://github.com/MikeRogers0)) 49 | - Disabling dependabot by default [\#65](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/65) ([MikeRogers0](https://github.com/MikeRogers0)) 50 | - Re-adding the volumes to the main docker container [\#63](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/63) ([MikeRogers0](https://github.com/MikeRogers0)) 51 | - Removing duplicate reference to branch when updating repo [\#62](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/62) ([MikeRogers0](https://github.com/MikeRogers0)) 52 | - Updating SendGrids opinionated default to use SENDGRID\_API\_KEY [\#61](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/61) ([MikeRogers0](https://github.com/MikeRogers0)) 53 | - Setting the default branch when pushing [\#60](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/60) ([MikeRogers0](https://github.com/MikeRogers0)) 54 | - Seperating our different caches with namespaces [\#59](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/59) ([MikeRogers0](https://github.com/MikeRogers0)) 55 | - Explicitly setting restore keys for satackey/action-docker-layer-caching [\#58](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/58) ([MikeRogers0](https://github.com/MikeRogers0)) 56 | - Re-writing readmes to be more appealing [\#57](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/57) ([MikeRogers0](https://github.com/MikeRogers0)) 57 | - Changing missed reference to Rubocop \> Standard [\#56](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/56) ([MikeRogers0](https://github.com/MikeRogers0)) 58 | - Switching back to root directory to store the caches more corectly [\#55](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/55) ([MikeRogers0](https://github.com/MikeRogers0)) 59 | - Use Standard over Rubocop [\#54](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/54) ([MikeRogers0](https://github.com/MikeRogers0)) 60 | - Adding option to turn on Rails app after template has run [\#53](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/53) ([MikeRogers0](https://github.com/MikeRogers0)) 61 | - Adding letter opener volume [\#52](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/52) ([MikeRogers0](https://github.com/MikeRogers0)) 62 | - Adding app:template command for rails [\#51](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/51) ([MikeRogers0](https://github.com/MikeRogers0)) 63 | - Stop outputting postgres logs to ./log [\#50](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/50) ([MikeRogers0](https://github.com/MikeRogers0)) 64 | - Renaming FactoryBot spec file to match what Rubocop expects [\#48](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/48) ([MikeRogers0](https://github.com/MikeRogers0)) 65 | - Adding factory\_bot [\#47](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/47) ([MikeRogers0](https://github.com/MikeRogers0)) 66 | - Tidying up env & generators file [\#46](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/46) ([MikeRogers0](https://github.com/MikeRogers0)) 67 | - Adding /letter\_opener link to routes [\#45](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/45) ([MikeRogers0](https://github.com/MikeRogers0)) 68 | - Adding Bootsnap precompile to Dockerfile [\#44](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/44) ([MikeRogers0](https://github.com/MikeRogers0)) 69 | - Telling ruby/setup-ruby to not install a different version of bundler [\#43](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/43) ([MikeRogers0](https://github.com/MikeRogers0)) 70 | - Retagging satackey/action-docker-layer-caching to v0 [\#42](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/42) ([MikeRogers0](https://github.com/MikeRogers0)) 71 | - Bump satackey/action-docker-layer-caching from v0.0.8 to v0.0.10 [\#40](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/40) ([dependabot[bot]](https://github.com/apps/dependabot)) 72 | - Adding rubocop-performance to default workflows [\#39](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/39) ([MikeRogers0](https://github.com/MikeRogers0)) 73 | - Allowing .envs to store DATABASE\_URL/REDIS\_URL [\#38](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/38) ([MikeRogers0](https://github.com/MikeRogers0)) 74 | - Adding rubocop-performance [\#37](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/37) ([MikeRogers0](https://github.com/MikeRogers0)) 75 | - Adding Code Of Conduct [\#36](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/36) ([MikeRogers0](https://github.com/MikeRogers0)) 76 | - Simplifying rubocop setup a bit more [\#35](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/35) ([MikeRogers0](https://github.com/MikeRogers0)) 77 | - Updating to Ruby 2.7.2 [\#34](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/34) ([MikeRogers0](https://github.com/MikeRogers0)) 78 | - Caching Gems & node\_modules between tests - it's so much faster [\#33](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/33) ([MikeRogers0](https://github.com/MikeRogers0)) 79 | - Adding premailer-rails to the default stack [\#32](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/32) ([MikeRogers0](https://github.com/MikeRogers0)) 80 | - Removing unused ENVs from app.json [\#31](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/31) ([MikeRogers0](https://github.com/MikeRogers0)) 81 | - Sorting gemfile with happy\_gemfile [\#30](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/30) ([MikeRogers0](https://github.com/MikeRogers0)) 82 | - Adding in default routes file which includes Sidekiq UI [\#29](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/29) ([MikeRogers0](https://github.com/MikeRogers0)) 83 | - Matching Procfile's web command to heroku default [\#28](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/28) ([MikeRogers0](https://github.com/MikeRogers0)) 84 | - Adjusting GH Actions to work more reliably [\#27](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/27) ([MikeRogers0](https://github.com/MikeRogers0)) 85 | - Running as non-root user [\#26](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/26) ([MikeRogers0](https://github.com/MikeRogers0)) 86 | - Fixing up a few rubocop warnings [\#25](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/25) ([MikeRogers0](https://github.com/MikeRogers0)) 87 | - Allowing access to Redis/Postgres/Web ports on localhost [\#24](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/24) ([MikeRogers0](https://github.com/MikeRogers0)) 88 | - Improving docker-compose default settings based on Evil Martians + schneems writings [\#23](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/23) ([MikeRogers0](https://github.com/MikeRogers0)) 89 | - Bump satackey/action-docker-layer-caching from v0.0.5 to v0.0.8 [\#22](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/22) ([dependabot[bot]](https://github.com/apps/dependabot)) 90 | - Making it clearer this is Rails + Docker :D [\#21](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/21) ([MikeRogers0](https://github.com/MikeRogers0)) 91 | - Renaming repo to Docker-Rails-Generator [\#20](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/20) ([MikeRogers0](https://github.com/MikeRogers0)) 92 | - Build using production image to speed up build [\#19](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/19) ([MikeRogers0](https://github.com/MikeRogers0)) 93 | - Include gitignore in template repo [\#18](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/18) ([MikeRogers0](https://github.com/MikeRogers0)) 94 | - Switching to just generating a template repo [\#17](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/17) ([MikeRogers0](https://github.com/MikeRogers0)) 95 | - Use organisation funding file [\#15](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/15) ([MikeRogers0](https://github.com/MikeRogers0)) 96 | - Adding an Opinionated defaults to Rails template [\#14](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/14) ([MikeRogers0](https://github.com/MikeRogers0)) 97 | - Increase Postgres version to 12.3 [\#13](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/13) ([MikeRogers0](https://github.com/MikeRogers0)) 98 | - bug: Don't try to copy now removed database.sample file [\#12](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/12) ([MikeRogers0](https://github.com/MikeRogers0)) 99 | - Running Bundle & Yarn after creating app [\#10](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/10) ([MikeRogers0](https://github.com/MikeRogers0)) 100 | - Remove 'git log' from template build action [\#8](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/8) ([MikeRogers0](https://github.com/MikeRogers0)) 101 | - Updating README's include helpful links [\#7](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/7) ([MikeRogers0](https://github.com/MikeRogers0)) 102 | - Fixing docker build errors by removing --virtual flag [\#5](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/5) ([MikeRogers0](https://github.com/MikeRogers0)) 103 | - Updating Dockerfile to make it more reliable running rails [\#3](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/3) ([MikeRogers0](https://github.com/MikeRogers0)) 104 | - Changing Organisation name to Ruby Starter Kits [\#2](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/2) ([MikeRogers0](https://github.com/MikeRogers0)) 105 | - Pulling in learnings from Bridgetown [\#1](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator/pull/1) ([MikeRogers0](https://github.com/MikeRogers0)) 106 | 107 | 108 | 109 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 110 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Mike Rogers 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 |

2 | Docker + Rails
Repository Generator 3 |

4 | 5 |

6 | License: MIT 7 | Contributor Covenant 8 |

9 | 10 | This generates the [Ruby-Starter-Kits/Docker-Rails-Template](https://github.com/Ruby-Starter-Kits/Docker-Rails-Template) template repository. It's the latest version of [Ruby on Rails](https://rubyonrails.org/), with all the files required to run via Docker. 11 | 12 | ## Apply To An Existing Rails Project 13 | 14 | You can copy the Docker files into your existing Rails project by running: 15 | 16 | ```bash 17 | $ bin/rails app:template LOCATION=https://raw.githubusercontent.com/Ruby-Starter-Kits/Docker-Rails-Generator/master/template.rb 18 | ``` 19 | 20 | This will copy the core docker files into your current application. 21 | 22 | ## Contributing 23 | 24 | Bug reports and pull requests are welcome on GitHub at [Ruby-Starter-Kits/Docker-Rails-Generator](https://github.com/Ruby-Starter-Kits/Docker-Rails-Generator). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 25 | 26 | ## License 27 | 28 | [MIT](https://opensource.org/licenses/MIT) 29 | 30 | Copyright (c) 2020-present, [Mike Rogers](https://mikerogers.io/) 31 | -------------------------------------------------------------------------------- /bin/build-environment-for-building-app: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Setting up Environment" 4 | cd $GITHUB_WORKSPACE/App 5 | bundle config path $GITHUB_WORKSPACE/vendor/bundle 6 | bundle config set jobs $(nproc) 7 | 8 | echo "Clear previous build" 9 | cd $GITHUB_WORKSPACE/App 10 | shopt -s extglob 11 | rm -rfv !(".git"|"."|".."|"node_modules") 12 | -------------------------------------------------------------------------------- /bin/build-latest-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Create app with latest version of Rails" 4 | cd $GITHUB_WORKSPACE/App 5 | gem install rails 6 | rails new . --database=postgresql --skip-spring 7 | 8 | echo "Remove default Rails files I often remove pretty fast" 9 | cd $GITHUB_WORKSPACE/App 10 | rm $GITHUB_WORKSPACE/App/config/credentials.yml.enc 11 | rm $GITHUB_WORKSPACE/App/config/master.key 12 | rm $GITHUB_WORKSPACE/App/app/views/layouts/mailer.text.erb 13 | 14 | echo "Copy Docker Template Files" 15 | cd $GITHUB_WORKSPACE/App 16 | rsync -a $GITHUB_WORKSPACE/Docker-Rails-Generator/App-Template/ $GITHUB_WORKSPACE/App/ 17 | 18 | echo "Setup Libraries I Often Use & Remove stuff I don't use" 19 | cd $GITHUB_WORKSPACE/App 20 | bundle remove jbuilder 21 | 22 | echo "Remove Minitest (Use RSpec instead)" 23 | rm -rf test 24 | 25 | echo "Updating .gitignore to ignore .env files" 26 | cat .gitignore.append >> .gitignore 27 | rm .gitignore.append 28 | 29 | echo "Adding gems I often add next" 30 | cat Gemfile.append >> Gemfile 31 | rm Gemfile.append 32 | bundle 33 | 34 | echo "Sorting the Gemfile" 35 | gem install happy_gemfile 36 | happy_gemfile all 37 | bundle 38 | 39 | echo "Fixing know weird non-standard Rails files" 40 | gem install rubocop 41 | gem install standardrb 42 | rubocop -A 43 | rm .rubocop.yml 44 | 45 | echo "Running Standard over everything" 46 | bundle exec standardrb --fix 47 | -------------------------------------------------------------------------------- /bin/test-latest-version: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Building Docker Image" 4 | cd $GITHUB_WORKSPACE/App 5 | docker-compose build --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -u)" 6 | docker-compose -f docker-compose.ci.yml build --build-arg USER_ID="$(id -u)" --build-arg GROUP_ID="$(id -u)" test || exit $? 7 | 8 | echo "Running Tests" 9 | docker-compose -f docker-compose.ci.yml run --rm --user="$(id -u):$(id -g)" test || exit $? 10 | 11 | echo "Cleaning Up unused data" 12 | docker image prune -f 13 | docker volume prune -f 14 | -------------------------------------------------------------------------------- /template.rb: -------------------------------------------------------------------------------- 1 | require "open-uri" 2 | 3 | base_uri = "https://raw.githubusercontent.com/Ruby-Starter-Kits/Docker-Rails-Generator/master/App-Template/" 4 | 5 | files = [ 6 | ".github/workflows/tests.yml", 7 | "bin/docker/entrypoints/wait-for-postgres.sh", 8 | "bin/docker/entrypoints/wait-for-web.sh", 9 | "bin/docker/prepare-to-start-rails", 10 | "config/cable.yml", 11 | "config/database.yml", 12 | ".dockerignore", 13 | "docker-compose.ci.yml", 14 | "docker-compose.yml", 15 | "Dockerfile" 16 | ] 17 | 18 | files.each do |file_path| 19 | file file_path, URI.parse("#{base_uri}#{file_path}").open.read 20 | end 21 | 22 | if yes?("Build Docker Environment?") 23 | run("docker-compose build && docker-compose run --rm web bin/setup") 24 | 25 | if yes?("Start Your Ruby on Rails App?") 26 | run("docker-compose up") 27 | else 28 | run("docker-compose down") 29 | end 30 | end 31 | --------------------------------------------------------------------------------