Giter Club home page Giter Club logo

ansible-elixir-stack's Introduction

ansible-elixir-stack

Tool to deploy Elixir & Phoenix apps to servers.

Docs: [Configuration], [Hot code-reloading], [prod.secret.exs file], [Logs]

Features

  • 1-command setup & deploys
  • Ships with Postgres support
  • Automatically creates a prod.secret.exs file
  • Deploy multiple hobby apps on a $5 DigitalOcean server
  • Custom domains
  • Hot code-reloading using exrm
  • Monitoring & automatic restarts using monit
  • Organized as an Ansible role, BUT requires no knowledge of Ansible

To deploy to Heroku, use the Heroku Elixir buildpack instead.

Install

$ pip install ansible
$ ansible-galaxy install HashNuke.elixir-stack

# assuming your SSH key is called `id_rsa`
# run this everytime you start your computer
$ ssh-add ~/.ssh/id_rsa

If the above commands fail, try with sudo. For Mac OS X, Ansible is also available on homebrew.

Setup your project

1.) Add exrm as your project's dependency in mix.exs

defp deps do
  [{:exrm, "~> 0.18.1"}]
end

2.) In your project dir, run following command:

$ curl -L http://git.io/ansible-elixir-stack.sh | bash

FOLLOW INSTRUCTIONS OF ABOVE COMMAND

Checkout the documentation on configuration options

Deploy your project

Assuming you have root SSH access to the server

To deploy the first time
$ ansible-playbook playbooks/setup.yml
To update your project
$ ansible-playbook playbooks/deploy.yml

By default the application is restarted on each deploy. Read how to enable hot code-reloading.

FAQ

  • Is this only meant for small $5 servers?
    Should fit servers of any size. In that case you could also increase the swap and npm

  • How to have different set of servers for staging and production?
    Use the inventory file as a template and maintain different inventory files for staging and production. Let's say your staging inventory file is called staging.inventory, then you could do ansible-playbook setup.yml -i staging.inventory (and similar for deploy). Notice the -i switch. B/w if you are going this way, you probably should learn Ansible or hire someone who knows it

Misc

ansible-elixir-stack's People

Contributors

hashnuke avatar manukall avatar pinx avatar rubytree avatar zabirauf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ansible-elixir-stack's Issues

Deployment errors out if adding dependencies w/o updating mix.lock

If a new dependency is added to mix.exs, eg:

diff --git a/mix.exs b/mix.exs
index 7f8fb0c..df627cd 100644
--- a/mix.exs
+++ b/mix.exs
@@ -35,6 +35,7 @@ defmodule HelloPhoenix.Mixfile do
      {:phoenix_html, "~> 1.4"},
      {:phoenix_live_reload, "~> 0.5", only: :dev},
      {:cowboy, "~> 1.0"},
-     {:exrm, "~> 0.18.1"}]
+     {:exrm, "~> 0.18.1"},
+     {:exprotobuf, "~> 0.11.0"}]
   end
 end

..and then the project is deployed without updating mix.lock, then the NEXT deploy after that will fail:

TASK: [HashNuke.elixir-stack | clone project] ********************************* 
failed: [178.62.201.149] => {"failed": true}
msg: Local modifications exist in repository (force=no).

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/johwar/deploy.retry

178.62.201.149             : ok=9    changed=0    unreachable=0    failed=1   

This is due to the Ansible 'git' task not forcing overwrites of modified files in the working tree by default. At the first deploy, mix.lock in the working tree on the server was updated with the new dependency, meaning it's now modified compared to what's in the Git repo.. so when we deploy a second time, the 'git' task fails as above.

Problem with swap

Hey!

I'm trying to update existing project (I received it from another developer), and I'm trying to ansible-playbook playbooks/deploy.yml. Unfortunately, I have a problems with these lines.

TASK: [HashNuke.elixir-stack | create file] *********************************** 
fatal: [162.243.77.207] => error while evaluating conditional: create_swap_file == True and swap_info.stat.exists == False

FATAL: all hosts have already failed -- aborting

What is reason for the problem?

Use roles for installing packages

I think it would be a good idea to use roles for installing Postgresql, nodejs, erlang, elixir and other dependencies. The tasks directory will also become much cleaner.
A project that does something like this is this one

RPM Package Support

I am planning on taking a stab at adapting this for a CentOS server and wanted to get input ahead of time.

I'm planning on following yoyoclouds' blog post. It seems like that approach would also be easy to transition to Ansible 2.0's package management module in the future.

Yay/Nay/Thoughts?

If an asdf plugin is installed, setup playbook fails

If an asdf plugin is installed, setup playbook fails. Because when a plugin is already added to asdf, it exists with 1 code. It's quite annoying.
A solution may be to ignore errors in this step, but in this case the playbook will continue it's work even if asdf failed to add a plugin. What do you think? Should ansible ignore errors on this step? Would it be a good improvement?

Update postgresql version

The Ubuntu 16.04 LTS is released and even available as a digitalocean droplet. Also postgresql 9.5 is stable. What do you think about changing the postgresql version to 9.5? Would you like me to submit such pull request?

Usage with private git repo

When trying to use this with a private repo I get:

TASK: [HashNuke.elixir-stack | clone project] *********************************
failed: [128.199.129.15] => {"cmd": "/usr/bin/git ls-remote '' -h refs/heads/master", "failed": true, "rc": 128}
stderr: Warning: Permanently added the RSA host key for IP address '131.103.20.167' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

This makes sense as I have not given access to the git repo to the deployer user.

Somewhere in the workflow I need to create and upload ssh keys for the deployer user, then copy the public key in repository.

Thoughts on this?

i cant create postgresql user on ubuntu 16.04

i get following output.

TASK [HashNuke.elixir-stack : create postgres user for deployer] ***************
fatal: [1.2.3.4]: FAILED! => {"changed": false, "failed": true, "msg": "unable to connect to database: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?\n"}
to retry, use: --limit @playbooks/setup.retry

PLAY RECAP *********************************************************************
1.2.3.4 : ok=37 changed=24 unreachable=0 failed=1

Version 1.0

Refactor and test the following actions:

  • Remove patched monit module
  • setup
  • deploy strategy: restart
  • deploy strategy: upgrade
  • migrate
  • remove app
  • run-cmd
  • support for AWS Ubuntu AMIs

Notes

  • Test once after fix is complete
  • Test with phoenix apps
  • Test with plug apps
  • Test with AWS

Remove monit module once Ansible 2.0 is released

monit module is included within this role is a copy of the latest monit module from the ansible-modules-extras repo. Needed for a bugfix (else monit stop won't work in Ansible v1.9.2 stable release)

Staging Configuration Help

I've got production working great, pulling from my master branch and placed under projects on the server like so:
/home/deployer/projects/appname_web

I would also like to have staging under projects as well:
/home/deployer/projects/appname_web_staging

Unfortunately I'm getting a error on the "create release" task (see below).

I've changed the following in the staging branch files:

/config/prod.exs
url: [host: "staging.appname.com", port: 80]

playbooks/vars/main.yml

app_name: appname_web_staging
repo_url: "[email protected]:company/appname.git"
git_ref: staging
app_port: 3002
domains: ["staging.appname.com"]
enable_mail_alerts: False

Here is the top part of the error I'm getting when deploying:

TASK [HashNuke.elixir-stack : create release] **********************************
task path: /usr/local/etc/ansible/roles/HashNuke.elixir-stack/tasks/release.yml:13

fatal: [IPADDRESS]: FAILED! => {"changed": true, "cmd": ["bash", "-lc", "SERVER=1 mix release"], "delta": "0:01:05.441843", "end": "2016-02-13 17:33:05.265316", "failed": true, "invocation": {"module_args": {"_raw_params": "bash -lc 'SERVER=1 mix release'", "_uses_shell": false, "chdir": "/home/deployer/projects/appname_web_staging", "creates": null, "executable": null, "removes": null, "warn": true}, "module_name": "command"}, "rc": 1, "start": "2016-02-13 17:31:59.823473", "stderr": "lib/conform/schema.ex:17: warning: redefining @doc attribute previously set at line 10\nlib/conform/translate.ex:16: warning: redefining @doc attribute previously set at line 9", "stdout": "==> connection\nCompiled lib/connection.ex\nGenerated connection app\n==> poolboy (compile)\n==> decimal\nCompiled lib/decimal.ex\nGenerated decimal app\nWARN: Missing plugins: [rebar3_hex]\n==> neotoma (compile)\n==> rebar3_hex (compile)\n==> poison\nCompiled lib/poison.ex\n

Create postgres user fails on ubuntu 15.10 target

Not sure if I am doing something wrong, but using brew-installed ansible on El Capitan as well as pip-installed ansible on a Ubuntu 14.04 server, the initial setup.yml fails on an Ubuntu 15.10 target on the step for creating the PostgreSQL user.

Solution was to add a task to ensure the service is started.

npm: command not found

It seems that node is not installed?

TASK [HashNuke.elixir-stack : set npm jobs config] *****************************
fatal: [138.68.27.79]: FAILED! => {"changed": true, "cmd": ["bash", "-lc", "npm config set jobs 1"], "delta": "0:00:00.013386", "end": "2016-08-04 11:57:42.123368", "failed": true, "rc": 127, "start": "2016-08-04 11:57:42.109982", "stderr": "bash: npm: command not found", "stdout": "", "stdout_lines": [], "warnings": []}

Missing License file

Hi -

Curious what the license on this repository is? Happy to create PR to add the correct license file.

Thanks!

Failed to connect to the host via ssh

I've noticed that release.yml:

- when: deploy_type == "restart"
  name: stop app
  monit: name="{{ app_name }}" state=stopped

Then, I got this error:

TASK [HashNuke.elixir-stack : stop app] ****************************************
fatal: [x.x.x.x]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
    to retry, use: --limit @playbooks/setup.retry

Please advice

unable to install hex

Have a look at following error.

TASK [HashNuke.elixir-stack : install hex] *************************************
fatal: [1.2.3.4]: FAILED! => {"changed": true, "cmd": ["bash", "-lc", "mix local.hex --force"], "delta": "0:00:00.007902", "end": "2016-07-18 02:49:50.697173", "failed": true, "rc": 127, "start": "2016-07-18 02:49:50.689271", "stderr": "bash: mix: command not found", "stdout": "", "stdout_lines": [], "warnings": []}
    to retry, use: --limit @playbooks/setup.retry

PLAY RECAP *********************************************************************
1.2.3.4               : ok=52   changed=31   unreachable=0    failed=1

Default password for deployer user

What is the default password for the deployer user?
I don't see it being specified in the deployer-user.yml task nor anywhere else in the role.

Skip action: deployer-user

I am new to Ansible (as well as Elixir & Phoenix) and am trying to deploy my first test app to production. I tried ansible-elixir-stack and get the following error at the action deployer-user:

fatal: [*.*.*.*] => SSH Error: Permission denied (publickey,password).
    while connecting to *.*.*.*
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

Is there a way to skip the action: deployer-user? I already have a deployer user setup on my production server so I do not need this.

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.