Skip to content

Instantly share code, notes, and snippets.

@mazz
mazz / Flexible Dockerized Phoenix Deployments.md
Created February 16, 2018 17:16 — forked from jswny/Flexible Dockerized Phoenix Deployments.md
A guide to building and running zero-dependency Phoenix (Elixir) deployments with Docker. Works with Phoenix 1.2 and 1.3.

Prelude

I. Preface and Motivation

This guide was written because I don't particularly enjoy deploying Phoenix (or Elixir for that matter) applications. It's not easy. Primarily, I don't have a lot of money to spend on a nice, fancy VPS so compiling my Phoenix apps on my VPS often isn't an option. For that, we have Distillery releases. However, that requires me to either have a separate server for staging to use as a build server, or to keep a particular version of Erlang installed on my VPS, neither of which sound like great options to me and they all have the possibilities of version mismatches with ERTS. In addition to all this, theres a whole lot of configuration which needs to be done to setup a Phoenix app for deployment, and it's hard to remember.

For that reason, I wanted to use Docker so that all of my deployments would be automated and reproducable. In addition, Docker would allow me to have reproducable builds for my releases. I could build my releases on any machine that I wanted in a contai

fatal: [kjvrvg_production]: FAILED! => {"changed": true, "cmd": ["/srv/pyramid/kjvrvg/venv/bin/ws-alembic", "-c", "/srv/pyramid/kjvrvg/faithfulaudio/kjvrvg/conf/generated.ini", "upgrade", "head"], "delta": "0:00:01.357724", "end": "2017-12-06 03:30:09.818628", "failed": true, "invocation": {"module_args": {"_raw_params": "/srv/pyramid/kjvrvg/venv/bin/ws-alembic -c /srv/pyramid/kjvrvg/faithfulaudio/kjvrvg/conf/generated.ini upgrade head", "_uses_shell": false, "chdir": "/srv/pyramid/kjvrvg", "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2017-12-06 03:30:08.460904", "stderr": "Traceback (most recent call last): File \"/srv/pyramid/kjvrvg/venv/bin/ws-alembic\", line 11, in <module>
load_entry_point('websauna', 'console_scripts', 'ws-alembic')()
File \"/srv/pyramid/kjvrvg/venv/src/websauna/websauna/system/devop/scripts/alembic.py\", line 21, in main
load_entry_point('alembic', 'console_scripts', 'alembic')()
File \"/srv/pyramid/kjvr
~/src/elixir/searchex (master ✘)✹ ᐅ ./searchex query genesis 'joseph'
Collection 'sample/genesis' Query 'joseph'
+----+-------+-------+-----------+-----------+---------------------------------+
| ID | Docid | Score | Startbyte | Doclength | Body |
+----+-------+-------+-----------+-----------+---------------------------------+
| 1 | 62294 | 0.856 | 141268 | 197 | Then there passed by Midianites |
| 2 | c1d12 | 0.749 | 137626 | 257 | These are the generations of Ja |
| 3 | dd0ad | 0.749 | 140563 | 145 | And it came to pass, when Josep |
| 4 | efad7 | 0.749 | 147385 | 161 | And he left all that he had in |
| 5 | 2c19f | 0.749 | 158406 | 172 | And Pharaoh called Joseph's nam |
import json
import uuid
import re
import datetime
from base64 import b64decode
import time
import jwt
import logging
logger = logging.getLogger(__name__)
"""Place your admin resources in this file."""
from websauna.system.admin.modeladmin import model_admin
from websauna.system.admin.modeladmin import ModelAdmin
# Import our models
from . import models
"""Place your SQLAlchemy models in this file."""
'''
PROD/live environment EXPORTING:
pg_dump -U postgres --no-owner --no-acl kjvrvg_production > kjvrvg_dev.pgsql
PROD/live environment IMPORTING:
sudo -i
defmodule TwitterKittensWeb do
@moduledoc """
The entrypoint for defining your web interface, such
as controllers, views, channels and so on.
This can be used in your application as:
use TwitterKittensWeb, :controller
use TwitterKittensWeb, :view
defmodule Gadgety.Mixfile do
use Mix.Project
@target System.get_env("MIX_TARGET") || "host"
Mix.shell.info([:green, """
Mix environment
MIX_TARGET: #{@target}
MIX_ENV: #{Mix.env}
""", :reset])
@mazz
mazz / nerves_init_gadget.log
Created August 22, 2017 23:22
nerves_init_gadget terminal log
~/src/nerves/gadgety ᐅ MIX_TARGET=rpi0 mix deps.get
Mix environment
MIX_TARGET: rpi0
MIX_ENV: dev
Running dependency resolution...
Dependency resolution completed:
bootloader 0.1.2
distillery 1.5.1
dns 1.0.1

Keybase proof

I hereby claim:

  • I am mazz on github.
  • I am mazz (https://keybase.io/mazz) on keybase.
  • I have a public key whose fingerprint is DE44 88A1 8DFF 192F 932C 35EA 0A31 1F93 51B5 E830

To claim this, I am signing this object: