Skip to content

Instantly share code, notes, and snippets.

@vovimayhem
Last active November 10, 2015 00:26
Show Gist options
  • Save vovimayhem/b804845f1f22d79c31e5 to your computer and use it in GitHub Desktop.
Save vovimayhem/b804845f1f22d79c31e5 to your computer and use it in GitHub Desktop.
Sample Docer+Phoenix project
# App artifacts
/_build
/db
/deps
/*.ez
# Generate on crash by the VM
erl_crash.dump
# The config/prod.secret.exs file by default contains sensitive
# data and you should not commit it into version control.
#
# Alternatively, you may comment the line below and commit the
# secrets file as long as you replace its contents by environment
# variables.
/config/prod.secret.exs
use Mix.Config
# For development, we disable any cache and enable
# debugging and code reloading.
#
# The watchers configuration can be used to run external
# watchers to your application. For example, we use it
# with brunch.io to recompile .js and .css sources.
config :hi_phoenix, HiPhoenix.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
cache_static_lookup: false,
check_origin: false,
watchers: []
# Watch static and templates for browser reloading.
config :hi_phoenix, HiPhoenix.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
]
]
# Do not include metadata nor timestamps in development logs
config :logger, :console, format: "[$level] $message\n"
# Set a higher stacktrace during development.
# Do not configure such in production as keeping
# and calculating stacktraces is usually expensive.
config :phoenix, :stacktrace_depth, 20
# Configure your database
config :hi_phoenix, HiPhoenix.Repo,
adapter: Ecto.Adapters.Postgres,
url: System.get_env("DATABASE_URL"),
pool_size: 10
#! /bin/bash
set -e
: ${APP_PATH:="/usr/src/app"}
: ${APP_TEMP_PATH:="$APP_PATH/tmp"}
: ${APP_SETUP_LOCK:="$APP_TEMP_PATH/setup.lock"}
: ${APP_SETUP_WAIT:="5"}
# 1: Define the functions lock and unlock our app containers setup processes:
function lock_setup { mkdir -p $APP_TEMP_PATH && touch $APP_SETUP_LOCK; }
function unlock_setup { rm -rf $APP_SETUP_LOCK; }
function wait_setup { echo "Waiting for app setup to finish..."; sleep $APP_SETUP_WAIT; }
# 2: 'Unlock' the setup process if the script exits prematurely:
trap unlock_setup HUP INT QUIT KILL TERM
# 3: Wait until the setup 'lock' file no longer exists:
while [ -f $APP_SETUP_LOCK ]; do wait_setup; done
# 4: 'Lock' the setup process, to prevent a race condition when the project's
# app containers will try to install gems and setup the database concurrently:
lock_setup
# 5: Check or install the app dependencies via Mix:
mix deps.get
# X: Check if the database exists, or setup the database if it doesn't, as it is
# the case when the project runs for the first time.
mix ecto.create
# 7: 'Unlock' the setup process:
unlock_setup
# 8: Especificar el comando default:
if [ -z "$1" ]; then set -- mix phoenix.server "$@"; fi
# 9: If the command to execute is 'rails server', then force it to write the pid
# file into an private directory - suddenly killing and removing app containers
# without this would leave a pidfile in the project's tmp dir, preventing containers
# from starting up on further attempts:
# if [[ "$1" = "rails" && ("$2" = "s" || "$2" = "server") ]]; then set -- "$@" -P /tmp/server.pid; fi
# 10: Execute the given or default command:
exec "$@"
# This should be very similar to an official Phoenix Docker Image:
# 1: Begin with the elixir image, which should include Erlang+rebar & Elixir+Hex:
FROM elixir:1.1.1
# 2: Make a base install of Phoenix... which is just needed for... wtf???
ENV PHOENIX_VERSION=1.0.3
RUN PHOENIX_DOWNLOAD_SHA512=68cd993932140cde233a0ac35a9927799e58b81235b9e8a95d75800137eaebf9f6a603131faa7b9c5b4cac049f5f8590fd73275d83fb6c59462ab61bd7b0605a \
&& mix archive.install --force --sha512 $PHOENIX_DOWNLOAD_SHA512 \
https://github.com/phoenixframework/phoenix/releases/download/v${PHOENIX_VERSION}/phoenix_new-${PHOENIX_VERSION}.ez
# 3: Install NodeJS from dist, as debian:jessie's nodejs is outdated for use with Phoenix:
RUN NODE_VERSION=5.0.0 \
&& set -ex \
&& for key in \
9554F04D7259F04124DE6B476D5A82AC7E37093B \
94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
0034A06D9D9B0064CE8ADF6BF1747F4AD2306D93 \
FD3A5288F042B6850C66B31F09FE44734EB7990E \
71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
; do \
gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; \
done \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.gz" \
&& curl -SLO "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
&& gpg --verify SHASUMS256.txt.asc \
&& grep " node-v$NODE_VERSION-linux-x64.tar.gz\$" SHASUMS256.txt.asc | sha256sum -c - \
&& tar -xzf "node-v$NODE_VERSION-linux-x64.tar.gz" -C /usr/local --strip-components=1 \
&& rm "node-v$NODE_VERSION-linux-x64.tar.gz" SHASUMS256.txt.asc
# 4: Install postgres client used by ecto-postgres, and the inotify-tools:
RUN apt-get update \
&& apt-get install -y postgresql-client inotify-tools \
&& rm -rf /var/lib/apt/lists/*
EXPOSE 4000
CMD ["mix","phoenix.server"]
---
# Our data container, mainly for storing the Postgres container's database
# files. This will allow us to move between postgres versions without losing the
# data currently in our development environment.
# We won't worry if this container is not in a "running state" when you
# type 'docker-compose ps'.
data:
image: tianon/true
volumes: [ "/var/lib/postgresql/data", "/app/tablas" ]
# Our PostgreSQL service:
postgres:
image: postgres:9.4.5
# Bind host port 5432 to PostgreSQL port 5432:
ports: [ "5432:5432" ]
# We're mounting 'db/dumps' into the postgres container so we can backup and
# restore data dumps easily:
volumes: [ "./priv/repo/dumps:/data-dumps" ]
volumes_from: [ "data" ]
environment:
LC_ALL: C.UTF-8
# Web:
web:
build: .
dockerfile: development.Dockerfile
volumes: [ ".:/usr/src/app" ]
ports: [ "4000:4000" ]
working_dir: /usr/src/app
entrypoint: /usr/src/app/development-entrypoint.sh
command: mix phoenix.server
environment: &app_environment
DATABASE_URL: postgres://postgres:h1ph03n1x@postgres.hi-phoenix.local:5432/hi_phoenix_dev?pool=25&encoding=unicode&schema_search_path=public
PHO_ENV: development
links:
- postgres:postgres.hi-phoenix.local
env_file: [] # [ "dev.env" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment