Skip to content

Instantly share code, notes, and snippets.

View bitwalker's full-sized avatar

Paul Schoenfelder bitwalker

View GitHub Profile
defmodule Features do
use GenServer
@features [chat: true]
def enable(feature), do: GenServer.call(__MODULE__, {:toggle, feature, true})
def disable(feature), do: GenServer.call(__MODULE__, {:toggle, feature, false})
def enabled?(feature) do
case :ets.lookup(__MODULE__, feature) do
@bitwalker
bitwalker / howto.txt
Created October 14, 2016 02:35
Deploying releases within containers
This is not meant to be comprehensive, a guide, or anything quite that sophisticated, just a couple
notes on what I do at work, in production, and how my environment is set up.
Overview:
- Infrastructure runs on AWS
- We run an internal PaaS based on OpenShift Origin/Kubernetes
- We push code to GitHub, which triggers a webhook, which in turn
triggers OpenShift to start a build, which fetches the source
code, and runs the build using the Dockerfile contained in the
@bitwalker
bitwalker / Dockerfile
Created September 2, 2016 15:05
Release container image
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <paulschoenfelder@gmail.com>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
APP=myapp \
APPVER=0.1.0
@bitwalker
bitwalker / Dockerfile
Last active March 12, 2017 03:25
Example Dockerfile for a release
FROM bitwalker/alpine-erlang:latest
MAINTAINER Paul Schoenfelder <paulschoenfelder@gmail.com>
ENV REFRESHED_AT=2016-06-21 \
HOME=/opt/app/ \
MIX_ENV=prod \
TERM=xterm \
REPLACE_OS_VARS=true
EXPOSE 5000
@bitwalker
bitwalker / config.ex
Created July 19, 2016 23:00
Useful config wrapper for Elixir
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
@bitwalker
bitwalker / run.sh
Created June 15, 2016 20:57 — forked from djo/run.sh
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
@bitwalker
bitwalker / config.ex
Created June 6, 2016 17:33
A nice config wrapper which allows using the {:system, "VAR"} convention comfortably
defmodule Config do
@moduledoc """
This module handles fetching values from the config with some additional niceties
"""
@doc """
Fetches a value from the config, or from the environment if {:system, "VAR"}
is provided.
An optional default value can be provided if desired.
[centos@ip-172-22-245-135 ~]$ sudo iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
681K 129M ACCEPT all -- tun0 * 0.0.0.0/0 0.0.0.0/0 /* traffic from docker for internet */
743K 517M ACCEPT udp -- * * 0.0.0.0/0 0.0.0.0/0 multiport dports 4789 /* 001 vxlan incoming */
2825K 2958M ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
336 29457 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
59589 3575K ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
1786 99404 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
6827 429K OS_FIREWALL_ALLOW all -- * * 0.0.0.0/0 0.0.0.0/0
@bitwalker
bitwalker / len.ex
Created March 29, 2016 17:34
How a body recursive function expands in Elixir
# This is our function definition,
# It is body (not tail) recursive, as it must wait for
# len(tail) to return before the addition can be performed
# on each iteration
def len([]), do: 0
def len([head | tail]), do: 1 + len(tail)
# If we call len([1, 2, 3]), this is what happens
len([1, 2, 3]) == 1 + len([2, 3])
len([2, 3]) == 1 + len([3])
@bitwalker
bitwalker / app.ex
Created March 23, 2016 22:48
A simple solution to executing code as part of a release
defmodule MyApp do
use Application
def start(_type, _args) do
import Supervisor.Spec, warn: false
:ok = handle_args!
children = []
Supervisor.start_link(children, strategy: :one_for_one, name: MyApp.Supervisor)