Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy to a different dir to fix hot upgrades #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ enable_mail_alerts: False
smtp_port: 587
smtp_use_tls: False

deploy_to_dir: "/srv/apps"
deploy_to_path: "{{ deploy_to_dir }}/{{ app_name }}"

# PRIVATE
smtp_tls_option: ""
npm_install_options: ""
4 changes: 4 additions & 0 deletions tasks/project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,7 @@
remote_user: "{{ deployer }}"
environment:
MIX_ENV: "{{ mix_env }}"


- name: "create directory for running app"
file: path="{{ deploy_to_path }}" state="directory" owner={{ deployer }}
25 changes: 20 additions & 5 deletions tasks/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
remote_user: "{{ deployer }}"


- name: get app version
command: bash -lc "mix run -e 'IO.puts \"RELEASE_VERSION=\" <> Mix.Project.config[:version]' | grep RELEASE_VERSION | sed 's/RELEASE_VERSION=//'" chdir="{{ project_path }}"
remote_user: "{{ deployer }}"
register: app_version_result
- set_fact: app_version="{{ app_version_result.stdout }}"


- name: "create release"
command: bash -lc 'SERVER=1 mix release' chdir="{{ project_path }}"
remote_user: "{{ deployer }}"
Expand All @@ -18,26 +25,34 @@
PORT: "{{ app_port }}"


- name: "extract release in running app dir"
unarchive: src="{{ project_path }}/rel/{{ app_name }}/releases/{{ app_version }}/{{ app_name}}.tar.gz" dest="{{ deploy_to_path }}" owner="{{ deployer }}" copy=no


- when: deploy_type == "restart"
name: start app
monit: name="{{ app_name }}" state=started


- when: deploy_type == "upgrade"
name: get app version
command: bash -lc "mix run -e 'IO.puts Mix.Project.config[:version]'" chdir="{{ project_path }}"
name: "create directory for new release version"
file: path="{{ deploy_to_path }}/releases/{{ app_version }}" state="directory" owner={{ deployer }}


- when: deploy_type == "upgrade"
name: "copy release to running app dir"
command: cp {{ project_path }}/rel/{{ app_name }}/releases/{{ app_version }}/{{ app_name}}.tar.gz {{ deploy_to_path }}/releases/{{ app_version }}
remote_user: "{{ deployer }}"
register: app_version


- when: deploy_type == "upgrade"
name: set upgrade command
set_fact: upgrade_command='rel/{{ app_name }}/bin/{{ app_name }} upgrade "{{ app_version.stdout }}"'
set_fact: upgrade_command='bin/{{ app_name }} upgrade "{{ app_version }}"'


- when: deploy_type == "upgrade"
name: upgrade app
command: bash -lc "{{ upgrade_command }}" chdir="{{ project_path }}"
command: bash -lc "{{ upgrade_command }}" chdir="{{ deploy_to_path }}"
remote_user: "{{ deployer }}"
environment:
MIX_ENV: "{{ mix_env }}"
Expand Down
4 changes: 2 additions & 2 deletions templates/app.monit.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check process {{app_name}} MATCHING "{{app_name}}/releases"
start program = "/bin/su - {{ deployer }} -c 'PORT={{ app_port }} {{project_path}}/rel/{{app_name}}/bin/{{app_name}} start'"
stop program = "/bin/su - {{ deployer }} -c 'PORT={{ app_port }} {{project_path}}/rel/{{app_name}}/bin/{{app_name}} stop'"
start program = "/bin/su - {{ deployer }} -c 'PORT={{ app_port }} {{ deploy_to_path }}/bin/{{app_name}} start'"
stop program = "/bin/su - {{ deployer }} -c 'PORT={{ app_port }} {{ deploy_to_path }}/bin/{{app_name}} stop'"
{% for alert_email in app_alert_emails %}
alert {{ alert_email }}
{% endfor %}