Giter Site home page Giter Site logo

docknix's Introduction

Docknix

A Dockerized, zero-dependency Phoenix 1.3 setup which should be used as a sample for future setups. Based on Gist by jswny.

Includes everything needed to build, deploy and run a default Phoenix application (Nginx and PostgreSQL).

Quickstart

Assuming you just want to build and run this application with everything already configured properly:

# Locally
./build.sh

# On the server
docker network create nginx-network
docker-compose up # in app diretory
docker-compose up # in nginx directory

For CI (and building with Docker in general), we need the following environment variables set:

  • DOCKNIX_RELEASE_COOKIE for the distributed Erlang cookie
  • DOCKNIX_SECRET_KEY_BASE for Phoenix secret key base
  • DOCKNIX_DB_USER for PostgreSQL username
  • DOCKNIX_DB_PASS for PostgreSQL password

Additionally, for CircleCI:

  • APP_HOST to know where to deploy to with CI
  • APP_USER to define which user to deploy as with CI

All the steps

Below is a quick outline of the steps we needed to take to achieve this setup.

Lines with * signify files that you might need to change (e.g. app names).

Steps for Phoenix and Distillery

  1. Add Distillery to dependencies in mix.exs: {:distillery, "~> 1.5", runtime: false}
  2. Run mix do deps.get, compile to fetch and compile Distillery
  3. Run mix release.init to initialize a Distillery release
  4. Configure if we want to include erts in rel/config.exs *
  5. Create release tasks module in lib/docknix/release_tasks.ex *
  6. Add release command script at rel/commands/migrate.sh *
  7. Add release command script to list of commands in rel/config.exs (to be able to run migrations with bin/docknix migrate)

Steps for Docker

  1. Add .dockerignore to avoid including unnecessary files
  2. Create Dockerfile.build to specify how to build the release *
  3. Create build.sh to manage the building of the app *
  4. You can now run ./build.sh to build your application in Docker
  5. Create Dockerfile.run for running the built release *
  6. Add docker-compose.yml to provision and manage the containers *

More steps for Phoenix

  1. Adjust config/prod.exs to follow Distillery basics *
  2. Adjust config/prod.secret.exs for production secrets *

Steps for Nginx @ Docker

  1. Create a Docker network with docker network create nginx-network
  2. Create directories nginx and nginx/conf.d and place docker-compose.yml and Nginx configs there

Steps for running everything

  1. Assume we have already run docker network create nginx-network
  2. Run docker-compose up in application directory
  3. Run docker-compose up in nginx directory

Phoenix locally

To start your Phoenix server:

  • Install dependencies with mix deps.get
  • Create and migrate your database with mix ecto.create && mix ecto.migrate
  • Install Node.js dependencies with cd assets && npm install
  • Start Phoenix endpoint with mix phx.server

Now you can visit localhost:4000 from your browser.

Ready to run in production? Please check our deployment guides.

Learn more

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.