Skip to content

Instantly share code, notes, and snippets.

@AlchemistCamp
Last active July 2, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save AlchemistCamp/d8576449095459064d88853cac7bf3b2 to your computer and use it in GitHub Desktop.
Save AlchemistCamp/d8576449095459064d88853cac7bf3b2 to your computer and use it in GitHub Desktop.
Episode 98 source
# Edeliver config
APP="chit_chat"
BUILD_HOST="doesit.run"
BUILD_USER="alchemist"
BUILD_AT="/home/alchemist/builds/chitchat"
PRODUCTION_HOSTS="doesit.run"
PRODUCTION_USER="alchemist"
DELIVER_TO="/home/alchemist/releases"
pre_erlang_get_and_update_deps() {
local _prod_secret_path="/home/alchemist/configs/chitchat/prod.secret.exs"
if [ "$TARGET_MIX_ENV" = "prod" ]; then
__sync_remote "
ln -sfn '$_prod_secret_path' '$BUILD_AT/config/prod.secret.exs'
"
fi
}
pre_erlang_clean_compile() {
status "Installing NPM dependencies"
__sync_remote " # runs the commands on the build host
[ -f ~/.profile ] && source ~/.profile # load profile
set -e # fail if any command fails
cd '$BUILD_AT' # go to the build directory on the build host
yarn install $SILENCE
"
status "Building static files"
__sync_remote "
[ -f ~/.profile ]
set -e
cd '$BUILD_AT'
mkdir -p priv/static
cd assets && yarn && yarn run deploy $SILENCE
"
status "Running phx.digest"
__sync_remote "
[ -f ~/.profile ] && source ~/.profile
set -e
cd '$BUILD_AT'
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD ecto.migrate $SILENCE
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phx.digest.clean $SILENCE
APP='$APP' MIX_ENV='$TARGET_MIX_ENV' $MIX_CMD phx.digest $SILENCE
"
}
# in /etc/nginx/sites-available/
upstream doesit.run {
server 127.0.0.1:4005;
}
## Serves https
server {
root /var/www/doesit.run/html;
index index.html index.htm index.nginx-debian.html;
server_name doesit.run www.doesit.run;
location / {
allow all;
# Proxy Headers
proxy_pass http://doesit.run;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Cluster-Client-Ip $remote_addr;
# WebSockets
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
listen [::]:443 ssl http2;
listen 443 ssl http2;
include /etc/nginx/snippets/letsencrypt.conf;
ssl_certificate /etc/letsencrypt/live/www.doesit.run/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/www.doesit.run/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/www.doesit.run/fullchain.pem;
}
## Serves http
server {
if ($host = www.doesit.run) {
return 301 https://$host$request_uri;
}
if ($host = doesit.run) {
return 301 https://$host$request_uri;
}
index index.html index.htm index.nginx-debian.html;
server_name doesit.run www.doesit.run;
listen 80;
listen [::]:80;
include /etc/nginx/snippets/letsencrypt.conf;
root /var/www/doesit.run/html;
}
defmodule ChitChat.MixProject do
use Mix.Project
def project do
[
app: :chit_chat,
version: "0.1.0",
elixir: "~> 1.8",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
]
end
def application do
[
mod: {ChitChat.Application, []},
extra_applications: [:logger, :runtime_tools]
]
end
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
defp deps do
[
{:phoenix, "~> 1.4.0"},
{:phoenix_pubsub, "~> 1.1.2"},
{:phoenix_ecto, "~> 4.0"},
{:ecto, "~> 3.0"},
{:ecto_sql, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.11"},
{:phoenix_live_reload, "~> 1.2-rc", only: :dev},
{:gettext, "~> 0.11"},
{:jason, "~> 1.0"},
{:plug_cowboy, "~> 2.0"},
{:comeonin, "~> 4.0"},
{:argon2_elixir, "~> 1.2"},
{:edeliver, ">= 1.6.0"},
{:distillery, "~> 2.0", warn_missing: false}
]
end
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
end
use Mix.Config
config :chit_chat, ChitChatWeb.Endpoint,
http: [:inet6, port: 4005],
url: [host: "doesit.run", port: 80],
cache_static_manifest: "priv/static/cache_manifest.json",
server: true,
code_reloader: false
config :logger, level: :info
import_config "prod.secret.exs"
use Mix.Config
config :chit_chat, ChitChatWeb.Endpoint,
secret_key_base: "RmQ6jWRiQlivUTQQ2GtqqOtoE+DI18NRLUfvO9NHqEMTHAJTx7V+mCwtwjmdGtz/" # create with `mix phx.gen.secret`
# Configure your database
config :chit_chat, ChitChat.Repo,
adapter: Ecto.Adapters.Postgres,
username: "chit_chat",
password: "a very secret pw",
hostname: "localhost",
database: "chit_chat_prod",
pool_size: 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment