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 Variables for build & host directory #9

Closed
wants to merge 6 commits into from
Closed
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
5 changes: 4 additions & 1 deletion ansible/roles/glimesh-web/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ glimesh_waffle_asset_host: some_value
glimesh_twitter_consumer_key: some_value
glimesh_twitter_consumer_secret: some_value
glimesh_twitter_access_token: some_value
glimesh_twitter_access_secret: some_value
glimesh_twitter_access_secret: some_value

glimesh_web_build_dir: /tmp/glimesh.tv
glimesh_web_host_dir: /opt/glimesh.tv
101 changes: 66 additions & 35 deletions ansible/roles/glimesh-web/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
name: "{{ inventory_hostname }}"

- name: Ensure .ssh directory exists.
file:
file:
dest: "/root/.ssh"
mode: 0700
owner: root
mode: 0700
owner: root
state: directory

- name: Install ssh key
copy:
src: "glimesh-deploy"
copy:
src: "glimesh-deploy"
dest: "/root/.ssh/id_rsa"
mode: 0600
owner: root
Expand All @@ -27,12 +27,12 @@

# - name: install required packages
# apt:
# pkg:
# - esl-erlang
# - elixir
# - npm
# pkg:
# - esl-erlang
# - elixir
# - npm
# - git
# - openssl
# - openssl
# - imagemagick
# state: present
# update_cache: yes
Expand All @@ -43,13 +43,15 @@
- name: install rebar
command: mix local.rebar --force

- name: ensure /tmp/glimesh.tv exists
file: path=/tmp/glimesh.tv state=directory
- name: ensure web_build_dir exists
file:
path: "{{ glimesh_web_build_dir }}"
state: directory

- name: download glimesh.tv
git:
repo: https://github.com/Glimesh/glimesh.tv.git
dest: /tmp/glimesh.tv
dest: "{{ glimesh_web_build_dir }}"
recursive: true
update: true
force: true
Expand All @@ -59,74 +61,103 @@
- name: register short git hash version
command: git rev-parse --short HEAD
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
register: glimesh_git_hash

- name: change version
- name: change version
lineinfile:
path: /tmp/glimesh.tv/mix.exs
path: "{{ glimesh_web_build_dir }}/mix.exs"
regexp: '^\s+version: .*$'
line: "version: \"0.1.0+{{ glimesh_git_hash.stdout }}\","

- name: install mix dependencies
command: mix do deps.get, deps.compile
command: mix do deps.get, deps.compile
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
environment:
MIX_ENV: prod
# when: glimesh.changed

- name: install npm asset deps
command: npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
# when: glimesh.changed

- name: build static assets
command: npm run --prefix ./assets deploy
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
# when: glimesh.changed

- name: digest static assets
command: mix phx.digest
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
# when: glimesh.changed

- name: build glimesh.tv
command: mix do compile --force, release --force --overwrite
command: mix do compile --force, release --force --overwrite
args:
chdir: /tmp/glimesh.tv
chdir: "{{ glimesh_web_build_dir }}"
environment:
MIX_ENV: prod
# when: glimesh.changed

- name: Ensure deploy state directories exist
file:
path: "{{ glimesh_web_host_dir }}-{{ item }}"
state: directory
owner: nobody
recurse: yes
with_items:
- "old"
- "new"

- name: Copy currently live files to old directory
synchronize:
src: "{{ glimesh_web_host_dir }}"
dest: "{{ glimesh_web_host_dir }}-old"
links: yes

- name: Copy newly built files to new store
synchronize:
src: "{{ glimesh_web_build_dir }}/_build/prod"
dest: "{{ glimesh_web_host_dir }}-new"
links: yes

- name: permissions
file:
path: "{{ glimesh_web_host_dir }}-new"
owner: nobody
recurse: yes

- name: setup unit file for glimesh.tv
template: src=glimesh.service.j2 dest=/etc/systemd/system/glimesh.service mode=644
template:
src: glimesh.service.j2
dest: /etc/systemd/system/glimesh.service
mode: 644
tags: config

- name: reload systemd immediately
systemd:
daemon_reload: yes

- name: gracefully shut down old glimesh app
systemd:
systemd:
name: glimesh
state: stopped

# Copying the file will automatically restart the daemon.
- name: copy built glimesh.tv
command: cp -Rf /tmp/glimesh.tv/_build/prod /opt/glimesh.tv

- name: permissions
- name: Change the symlink
file:
path: /opt/glimesh.tv
src: "{{ glimesh_web_host_dir }}-new"
dest: "{{ glimesh_web_host_dir }}"
state: link
owner: nobody
recurse: yes
force: yes

- name: start new glimesh app
systemd:
systemd:
name: glimesh
state: started

Expand All @@ -136,5 +167,5 @@
delay: 5

- name: pause to make sure the other node can take over
pause:
seconds: 15
pause:
seconds: 15
27 changes: 27 additions & 0 deletions ansible/web-rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
- name: web
hosts: web
serial: 1

tasks:
- name: Change the symlink
file:
src: /opt/glimesh.tv-old
dest: /opt/glimesh.tv
state: link
owner: nobody
force: yes

- name: restarted glimesh
systemd:
name: glimesh
daemon_reload: yes
state: restarted

- name: wait for service to be online
wait_for:
port: 8080
delay: 5

- name: pause to make sure the other node can take over
pause:
seconds: 15