This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SageExample do | |
import Sage | |
require Logger | |
# It is better to build Saga struct in a module attribute, | |
# we don't need to spend resources each time we want to execute it | |
@create_and_subscribe_user_sage | |
new() | |
|> run(:user, &create_user/2) | |
|> run(:plans, &fetch_subscription_plans/2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Sample.Application do | |
use Application | |
# ... | |
def start(_type, _args) do | |
import Supervisor.Spec | |
# ... | |
# Update application environment from system environment variable when application starts | |
Application.put_env(:sample_app, :configurable_env_var, System.get_env("CONFIGURABLE_ENV_VAR")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
command -v fswatch >/dev/null 2>&1 || { echo >&2 "fswatch is not installed. To install it use 'brew install fswatch'. Aborting."; exit 1; } | |
command -v mix >/dev/null 2>&1 || { echo >&2 "mix is not installed. Aborting."; exit 1; } | |
PROJECT_PATH=$(git rev-parse --show-toplevel) | |
[[ "$?" != "0" ]] && echo "Stale test watch works only within git project." && exit 1; | |
declare -a IGNORED_PATHS | |
declare -i throttle_by=2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM nebo15/alpine-elixir:1.5.1 as builder | |
MAINTAINER Nebo#15 support@nebo15.com | |
# Always build with production environment | |
ENV MIX_ENV=prod | |
# `/opt` is a common place for third-party provided packages that are not part of the OS itself | |
WORKDIR /opt/app | |
# Required in elixir_make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "myappapi", | |
"description": "MyApp Backend Application", | |
"scripts": { | |
"postdeploy": "/app/bin/myapp seed" | |
}, | |
"env": { | |
"MY_ENV_VARIABLE": { | |
"required": true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -xe | |
# Create a release tarball | |
mix release --verbose | |
# Find tarball location | |
APP_NAME="myapp" | |
APP_TARBALL=$(find _build/${MIX_ENV}/rel/${APP_NAME}/releases -maxdepth 2 -name ${APP_NAME}.tar.gz) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
release: /app/bin/myapp migrate | |
web: /app/bin/myapp foreground |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Mix.Releases.Config, | |
default_release: :default, | |
default_environment: :default | |
environment :default do | |
set dev_mode: false | |
set include_erts: false | |
set include_src: false | |
set cookie: :"this_is_a_secret" | |
# Add release commands |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
/app/bin/myapp command "Elixir.MyAppAPI.ReleaseTasks" migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyAppAPI.ReleaseTasks do | |
alias Ecto.Migrator | |
@otp_app :myapp_api | |
@start_apps [:logger, :ssl, :postgrex, :ecto] | |
def migrate do | |
init(@otp_app, @start_apps) | |
run_migrations_for(@otp_app) |