Giter VIP home page Giter VIP logo

patschreiber

Homepage for Pat Schreiber.

Current Project Dependency Version
Ruby 2.7.x
Rails 6.x

1. Local Env Bootstrap

1.1 First-time Setup

cd /path/to/project/root

1.1.a RVM (Ruby Version Manager)

RVM is a handy way to manage multiple ruby installations on a single host, say, if said host is running multiple applications that require different Ruby versions. It's also handy for testing new language releases. An optional install, but highly suggested.

1.1.b Installing RVM and Project Gemset

# Update RVM
rvm get head

# Install latest project ruby version
# rvm install ruby-major.minor.revision
# E.g.
rvm install 2.7.1

# Create a gemset for this project
rvm create gemset patschreiber

Note: The ruby version and RVM wrapper should switch to the correct versions (if they're installed) automatically based on the ruby-version and .ruby-gemset files located at the root of the project. If they do not, run rvm use 2.7.1@patschreiber to manually switch.

1.1.c Installing Dependencies

# Installs Ruby Gems
bundle install
# Initializes the database
rake db:setup
# Alternatively, if the db is alreay created, you can run
rake db:migrate
rake db:seed

# Install the Rails Webpack helper
rake webpacker:install
rake webpacker:compile
1.1.d MacOS-only

Install automatic cert updating

  1. rvm osx-ssl-certs cron install

See Troubleshooting: MacOS

2. Continued Development

If you're returning to the project, follow these steps.

cd /path/to/project/root
bundle update
bundle install
rvm get head

# Verifies if Node.js is installed
rake webpacker:check_node
# Verifies if Yarn is installed
rake webpacker:check_yarn
# Verifies that webpack & webpack-dev-server are present
rake webpacker:check_binstubs
# Verifies if Webpacker is installed
rake webpacker:verify_install

webpacker:clean
webpacker:install
webpacker:binstubs
webpacker:compile

rake db:migrate
rake db:schema:load

2. Linters

2.1 Rubocop

  1. Auto generates HAML rubocop suggestions
    • haml-lint --auto-gen-config
  2. Generate warnings for Ruby code
    • bundle exec rubocop

2.1.a Auto-fixing Rubocop infractions

To have Rubocop auto-fix a single rule, you can run:

rubocop --auto-correct --only Style/FrozenStringLiteralComment

where the name of the rule is defined in .rubocop.yml.

3. Maintenance

3.1 Tasks

-[] Update outdated packages -[] Check SSL Cert

3.2 Set Default Gemset

rvm default <ruby version>@<gemset>

e.g. rvm default 2.7.1@patschreiber

cd /path/to/project/root
rvm get head

3.2.a If the Ruby Version Has Changed

Migrate using the RVM syntax:

rvm migrate old ruby version (source) ruby version (destination)`

E.g.

rvm migrate 2.6.5 2.7.1

3.2 Update Gem Dependencies With Bundler

  • Get a list of outdated gems. bundle outdated
  • Update a single gem. bundle update <package>
  • Update a specific group of gems. bundle update --group=GROUP_NAME
  • Update all gems. bundle update --all

3.3 Update Sitemaps

Create or rebuild your sitemap files as needed. Sitemaps are generated into the public/ folder and by default are named sitemap.xml.gz, sitemap1.xml.gz, sitemap2.xml.gz, etc. As you can see, they are automatically GZip compressed for you. In this case, sitemap.xml.gz is your sitemap "index" file.

  1. Clear existing sitemaps

    • Delete all Sitemap files in public/ directory
      • rake sitemap:clean
  2. Generate sitemaps

    • Generate sitemaps and ping search engines
      • rake sitemap:refresh
    • Generate sitemaps but don't ping search engines
      • rake sitemap:refresh:no_ping
  3. Regenerate pretty URLs (friendly_ids)

4 Release to production

Note

All commands should be run on the prod server(s).

4.1 Clear Caches

  1. Clear tmp dirs

    • rake tmp:clear
  2. Creates tmp directories for cache, sockets, and pids

    • rake tmp:create

4.2 Precomile Assets

  1. Clean old compiled webpacks

    • rake webpacker:clean
  2. Compile JavaScript packs using webpack for production with digests

    • rake webpacker:compile

4.3 Prepare database

  1. Creates a db/schema.rb file that is portable against any DB supported by Active Record

    • rake db:schema:dump
  2. Retrieves the current schema version number

    • rake db:version

4.4 Secure Headers

  1. Regenerate hashes
    • rake secure_headers:generate_hashes

4.5Database

  1. Recreates the database from the schema.rb file.
    • rake db:schema:load
  2. Set the current RAILS_ENV environment in the ar_internal_metadata table. (Used as part of the protected environment check.)
    • rake db:environment:set
  3. Checks if a destructive action can be performed in the current RAILS_ENV environment. Used internally when running a destructive action such as db:drop or db:schema:load.
    • rake db:check_protected_environments

4. Feature Docs/Project Info

4.1 Gem Updates

Note Be aware of gems that are installed outside of bundler. e.g. gem install bundler -v 1.17.2

4.2 Sitemap Regeneration

Create or rebuild your sitemap files as needed. Sitemaps are generated into the public/ folder and by default are named sitemap.xml.gz, sitemap1.xml.gz, sitemap2.xml.gz, etc. As you can see, they are automatically GZip compressed for you. In this case, sitemap.xml.gz is your sitemap "index" file.

rake sitemap:refresh

Generate sitemaps but don't ping search engines

rake sitemap:refresh:no_ping

4.2 Whenever (Cron)

Cron is run through the whenever gem and configured in config/schedule.rb. Cron log is assumed to be /var/log/cron.log. See https://askubuntu.com/questions/56683/where-is-the-cron-crontab-log for more info.

Writes the crontab file for your jobs whenever --update-crontab

4.3 Keys and Secrets

  1. Edit Keys
    • EDITOR=vim rails credentials:edit
  2. Use a key
    • Rails.application.credentials.secret_key_base

4.4 Pretty URLs

Add Pretty URLs to already-existing entities Project.find_each(&:save)

"Projects" use the title by default, but you can set your own slug using

lambda {
  project = Project.new
  project.source_type = 'open'
  project.slug = 'my-long-project-pretty-URL'
  # etc...
}

Adds the slug column to a database table

rails g migration AddSlugToUsers slug:uniq

Frontend

Webpack

# Init Webpack
bundle exec rails webpacker:install

# Run Webpack
./bin/webpack-dev-server

Troubleshooting

1. MacOS

1.1 Enable auto-libs

Most of the systems ships with a package manager so the enable mode is the same as packages. Unfortunately on OSX there is not package manger provided so RVM has to detect one of existing user efforts, The detection is in order: homebrew, macports, smf, fink if none of them are available then RVM will install macports.

rvm autolibs enable

You can also optionally enforce a package manager by using one of the following instead of enable:

macports, homebrew, fink, smf (SM Framework) or rvm_pkg (the old rvm pkg), like:

  1. rvm autolibs homebrew

  2. bundle install

    1. cd /path/to/patschreiber_root/ && bundle install
  3. rvm

    1. rvm use <ruby version>@<your gemset>

Patrick Schreiber's Projects

better_grammer icon better_grammer

A collection of <hopefully> thought-provoking links and resources to make a better programmer.

big-list-of-naughty-strings icon big-list-of-naughty-strings

The Big List of Naughty Strings is a list of strings which have a high probability of causing issues when used as user-input data.

chiaro icon chiaro

Front-end framework that emphasizes readability for long form text by tactfully using greyscale.

code_extension icon code_extension

This is the starting point for doing an in-office code extension

coltrane icon coltrane

ðŸŽđðŸŽļA music theory library with a command-line interface

cta icon cta

Finds data about your time with the Chicago Transit Authority

ctabt icon ctabt

I have a CTA stop outside my window, so I decided to hook into Chicago's Bus Tracker API so I can see the time from my window.

dawlog_vst_idea icon dawlog_vst_idea

It's a VST that writes major events to a simple log file, which you can go back and audit later.

document_chicago icon document_chicago

Document Chicago is a social tag-based image sharing site where users upload pictures to the site and can search based on tags for images around Chicago.

drupal-scratchpad-module icon drupal-scratchpad-module

A generic module that can be used to sketch out functionality. Includes a test endpoint at /test-endpoint.

drupal_hooker icon drupal_hooker

A simple Drupal 8 module that shows how many times HOOK_ functions have been defined

fowlgame icon fowlgame

Automated RPG for Twitter. Follow @fowlgame and play with your friends. Tweet #help or visit http://www.fowlgame.com for instructions on how to play.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google âĪïļ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.