Skip to content

Instantly share code, notes, and snippets.

View gottfrois's full-sized avatar

Pierre-Louis Gottfrois gottfrois

View GitHub Profile
defmodule Rabbit.ConnectionPool do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, [])
end
def init(_) do
pool_options = [
{:name, {:local, :rabbit_connection_pool}},
defmodule Rabbit.ConnectionWorker do
use Connection
def start_link(opts) do
Connection.start_link(__MODULE__, opts)
end
def init(opts) do
state = %{opts: opts, conn: nil}
{:connect, nil, state}
defmodule Rabbit do
use Supervisor
def start_link do
Supervisor.start_link(__MODULE__, [])
end
def init(_opts) do
children = [
worker(Rabbit.ConnectionPool, []),
@gottfrois
gottfrois / components.rb
Created January 4, 2018 15:41
Dry-system component example using gems
# foo/lib/foo.rb
require 'dry/system'
require 'foo/version'
module Foo
Dry::System.register_provider(
:foo,
boot_path: Pathname(__dir__).join('foo/components').realpath
)
end
@gottfrois
gottfrois / Dockerfile
Last active September 6, 2018 09:07
medium-multi-stage-dockerfile-full-classic-dockerfile
FROM ruby:2.5.1-alpine3.7
WORKDIR /home/app
RUN apk add --update --no-cache \
build-base \
libxml2-dev \
libxslt-dev \
nodejs \
tzdata
@gottfrois
gottfrois / Gemfile
Created September 6, 2018 08:52
medium-multi-stage-dockerfile-rails-gemfile
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.5.1'
gem 'rails', '~> 5.2.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
group :development, :test do
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 08:57
medium-multi-stage-dockerfile-ruby-stage
######################
# Stage: ruby
FROM ruby:2.5.1-alpine3.7 as ruby
LABEL description="Base ruby image used by other stages"
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 08:58
medium-multi-stage-dockerfile-bundler-stage
######################
# Stage: bundler
FROM ruby as bundler
LABEL description="Install and cache gems for all environments"
WORKDIR /home/app
# Copy the Gemfile and Gemfile.lock
COPY Gemfile* /home/app/
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 08:59
medium-multi-stage-dockerfile-runner-stage
###############################
# Stage runner
FROM ruby as runner
LABEL description="Builds an image ready to be run"
# Install runtime deps and create non-root user.
#
# If you need to install specific libraries for test environment
# please use a virtual pkg holder you can easily remove on the
# `release` stage.
@gottfrois
gottfrois / Dockerfile
Created September 6, 2018 09:00
medium-multi-stage-dockerfile-compiler-stage
###############################
# Stage compiler
FROM runner as compiler
LABEL description="Builds a compiler image used to compile assets"
# Copy cached compiled assets to avoid re-compiling them
# We use latest compiler image to get already compiled assets
# and save lots of time on assets compilation for this new image
COPY --chown=app:app --from=my-app:compiler /home/app/public /home/app/public
COPY --chown=app:app --from=my-app:compiler /home/app/tmp /home/app/tmp