Skip to content

Instantly share code, notes, and snippets.

View ndbroadbent's full-sized avatar

Nathan Broadbent ndbroadbent

View GitHub Profile
@ndbroadbent
ndbroadbent / shrine_file_migration_service.rb
Created October 12, 2019 15:45
Shrine file migration Rake task
# frozen_string_literal: true
# Run this with: rake storage:migrate
class ShrineFileMigrationService
def self.migrate_files!(options = {})
dry_run = options[:dry_run]
verbose = options[:verbose]
unless Shrine.version.to_s == '2.19.3'
@ndbroadbent
ndbroadbent / ci_cache
Last active September 2, 2020 12:15
A powerful CI caching tool for Google Cloud Storage
#!/bin/bash
set -e
# CI Cache Script for Google Cloud Storage
# TIP: Set CI_CACHE_VERBOSE=true while testing the script
# to show a list of all files that are compressed/extracted.
# Note that you might see "tar: write error" if there are too many
# files in the verbose output.
@ndbroadbent
ndbroadbent / .bashrc
Last active June 16, 2019 19:46
Notification function for long-running commands
# ~/.bashrc
# Here's a nice alert sound you can use: https://www.dropbox.com/s/ctziqfuqt5q9fek/alert.mp3?dl=0
# Find some more here: https://notificationsounds.com/notification-sounds
alias alert="afplay ~/sounds/alert.mp3"
function n() {
local ALERT="Alert from Bash"
local EXIT_CODE=0
@ndbroadbent
ndbroadbent / puma_sanity_check.sh
Last active June 10, 2019 22:05
Puma sanity check, for CI / Docker builds
#!/bin/bash
set -e
# When running on a local machine, we need to kill the Spring loader.
if [ -f .env ]; then spring stop; fi
# Ensures that the Rails app can boot and pass a simple health check.
export RAILS_ENV=production
export PORT=4123
export DATABASE_URL=postgresql:does_not_exist
@ndbroadbent
ndbroadbent / puma_sanity_check.sh
Created June 10, 2019 21:57
Puma sanity check, for CI / Docker builds
#!/bin/bash
set -e
# When running on a local machine, we need to kill the Spring loader.
if [ -f .env ]; then spring stop; fi
# Ensures that the Rails app can boot and pass a simple health check.
# Also ensures that RubyEncoder is working for the enterprise image.
export RAILS_ENV=production
@ndbroadbent
ndbroadbent / sidekiq_health_check_job.rb
Last active June 10, 2019 19:48
An RSpec test that ensure that the Sidekiq worker can actually boot without crashing, and runs a real test job from Redis
# frozen_string_literal: true
# spec/jobs/worker_health_check_job_spec.rb starts a Sidekiq worker process
# and checks stdout for some expected strings. This ensures that Sidekiq
# can boot without crashing, and run a real job from a Redis queue.
class SidekiqHealthCheckJob
include Sidekiq::Worker
def perform(string)
@ndbroadbent
ndbroadbent / sidekiq_sanity_check_v3.sh
Created June 10, 2019 15:39
sidekiq_sanity_check_v3 - Revert to using --daemon flag, and use a lightweight Ruby script to push the job to Redis
#!/bin/bash
set -e
if [ -f .env ]; then spring stop; fi
# This script is run in the CI build. It requires a REDIS_URL variable,
# and runs a test job through the WorkerHealthCheckJob.
# I added this check after I accidentally pushed a change that caused the sidekiq
# workers to crash on boot. The jobs were well-tested, but the actual
# sidekiq config had an error inside a #configure_server block, so the code
# only crashed when I started an actual Sidekiq worker process.
@ndbroadbent
ndbroadbent / sidekiq_sanity_check_2.sh
Last active June 10, 2019 13:59
sidekiq_sanity_check_2.sh
#!/bin/bash
set -e
if [ -f .env ]; then spring stop; fi
# This script is run in the CI build. It requires a REDIS_URL variable,
# and runs a test job through the WorkerHealthCheckJob.
# I added this check after I accidentally pushed a change that caused the sidekiq
# workers to crash on boot. The jobs were well-tested, but the actual
# sidekiq config had an error inside a #configure_server block, so the code
# only crashed when I started an actual Sidekiq worker process.
@ndbroadbent
ndbroadbent / sidekiq_sanity_check.sh
Last active June 10, 2019 13:46
Sidekiq test that I run on CI
#!/bin/bash
set -e
# This script is run in the CI build. It requires a REDIS_URL variable,
# and runs a test job through the WorkerHealthCheckJob.
# I added this check after I accidentally pushed a change that caused the sidekiq
# workers to crash on boot. The jobs were well-tested, but the actual
# sidekiq config had an error inside a #configure_server block, so the code
# only crashed when I started an actual Sidekiq worker process.
@ndbroadbent
ndbroadbent / Dockerfile.ruby
Last active May 12, 2019 07:31
Ruby Dockerfile with checkinstall (but checkinstall just freezes)
FROM debian:stretch
RUN apt-get update \
&& apt-get install -y \
curl ca-certificates \
checkinstall unzip build-essential \
automake libtool libtool-bin pkg-config \
bison \
dpkg-dev \
gcc \