Skip to content

Instantly share code, notes, and snippets.

@adbatista
Created May 26, 2025 01:09
Show Gist options
  • Save adbatista/6189355b46f78fca34b98d5ae1fa58f1 to your computer and use it in GitHub Desktop.
Save adbatista/6189355b46f78fca34b98d5ae1fa58f1 to your computer and use it in GitHub Desktop.
template of rails application that I used in some clients
gem 'active_model_serializers'
gem 'airbrake'
gem_group :development do
gem 'rubocop', '~> 1.30', require: false
gem 'brakeman', require: false
gem 'rubocop-rspec', '~> 2.11', require: false
gem 'rubocop-rails', require: false
end
gem_group :development, :test do
gem "dotenv-rails"
gem "factory_bot_rails"
gem "rspec-rails"
end
application do
<<~CONFIG
config.tag_version = File.readlines(File.join(Rails.root, 'version')).join.chop
config.i18n.default_locale = :"en-US"
CONFIG
end
empty_directory ".github/workflows"
empty_directory "docker"
file 'version'
file 'CHANGELOG.md'
copy_file "config/environments/production.rb", "config/environments/staging.rb"
gsub_file 'config/environments/staging.rb', /(config.consider_all_requests_local)\s+= false/, '\1 = true'
gsub_file 'config/environments/staging.rb', /(config.log_level)\s+= :info/, '\1 = :warn'
file ".github/workflows/github-actions.yml", URI.open("https://raw.githubusercontent.com/template_path/github-actions.yml", http_basic_authentication: [ENV["GITHUB_OAUTH_TOKEN"]]).read
gsub_file '.github/workflows/github-actions.yml', /<PROJECT>/, app_name.dasherize.upcase
# `DATA.read` does not work with template scripts
data_files = URI.open(__FILE__).read.split(/__END__\n/, 3).last
data_files.split(/@@(\.?.+)\n/)[1..-1].each_slice(2).each do |file_name, content|
file file_name, ERB.new(content).result
end
after_bundle do
generate("rspec:install")
generate(:airbrake)
run "rubocop -A"
git :init
git add: "."
git commit: %Q{ -m 'Initial commit' }
end
__END__
@@.github/pull_request_template.md
**Motivation:**
...
**Solution:**
...
@@docker/dev/Dockerfile
FROM ruby:<%= RUBY_VERSION %>-alpine
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
RUN apk update \
&& apk --no-cache add \
--update \
build-base \
freetds-dev \
tzdata \
git \
linux-headers \
shared-mime-info \
curl \
coreutils \
libcrypto1.1 \
libssl1.1 \
bash
ENV BUNDLE_WITHOUT='development:test:debug' \
BUNDLE_GITHUB__COM=x-access-token:${GITHUB_OAUTH_TOKEN} \
BUNDLE_PATH=/bundle \
BUNDLE_BIN=/bundle/bin \
GEM_HOME=/bundle
ENV PATH="${BUNDLE_BIN}:${PATH}"
RUN mkdir $BUNDLE_PATH && \
adduser -D app && \
chown -R app $BUNDLE_PATH
USER app
WORKDIR /usr/src/app
COPY --chown=app . ./
RUN gem install bundler --no-document && \
bundle install --jobs=3 --retry=3
ARG SOURCE_TAG
RUN echo ${SOURCE_TAG} > ./version
EXPOSE 3000
HEALTHCHECK --interval=5m --timeout=10s \
CMD curl -f http://localhost:3000/healthcheck || exit 1
CMD ["bundle", "exec", "puma", "-C", "./config/puma.rb"]
@@docker-compose.yml
services:
app:
build:
context: .
args:
GITHUB_OAUTH_TOKEN: ${GITHUB_OAUTH_TOKEN}
command: 'bundle exec rails s -p 3000 -b 0.0.0.0'
ports:
- 3000:3000
volumes:
- .:/usr/src/app
@@.rubocop.yml
require:
- rubocop-rails
- rubocop-rspec
AllCops:
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- 'bin/*'
- 'vendor/**/*'
Bundler/OrderedGems:
Enabled: false
Layout/ExtraSpacing:
Enabled: false
Layout/SpaceInsidePercentLiteralDelimiters:
Enabled: false
StringLiterals:
Enabled: false
Style/BlockComments:
Enabled: false
Style/Documentation:
Enabled: false
Style/SymbolArray:
Enabled: false
Rails/FilePath:
Enabled: false
Naming/RescuedExceptionsVariableName:
Enabled: false
Style/PreferredHashMethods:
Enabled: false
Style/NumericPredicate:
Enabled: false
Style/HashSyntax:
EnforcedShorthandSyntax: either
RSpec/NestedGroups:
Max: 4
Layout/ClosingParenthesisIndentation:
Enabled: false
Layout/EndAlignment:
Enabled: false
Layout/ArgumentAlignment:
Enabled: false
Layout/ElseAlignment:
Enabled: false
RSpec/ExampleLength:
CountAsOne: ['array', 'heredoc', 'hash']
Layout/IndentationWidth:
Enabled: false
RSpec/NamedSubject:
Enabled: false
Metrics/MethodLength:
CountAsOne: ['array', 'heredoc', 'hash']
RSpec/StubbedMock:
Enabled: false
RSpec/AnyInstance:
Enabled: false
Metrics/ClassLength:
CountAsOne: ['array', 'heredoc', 'hash']
Rails/DynamicFindBy:
Enabled: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment