Skip to content

Commit

Permalink
Add variables for each deployment
Browse files Browse the repository at this point in the history
- Untar repositories into a temp directory, then rsync to deploy location
- Clean up temp packages and files
- Fix #34
  • Loading branch information
xmunoz committed Dec 31, 2020
1 parent cb1c294 commit 39c2f0e
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 55 deletions.
67 changes: 41 additions & 26 deletions provisioners/deploy-backend.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
---
- name: Deploy code on machine and configure cron and services
- name: Deploy code on the backend machine and configure cron and services
hosts: default
become: true
vars:
repos:
- api
- daemon
- library
- mdot
- task-runner
- uploader
- upload-service
- website
temp_dir: /data/tmp/www
deploy_dir: /data/www
tasks:
- name: Create minute cron dir
file:
Expand All @@ -16,40 +28,43 @@
job: "cd / && run-parts --report /etc/cron.minute"
- name: Copy packages from S3
become_user: deployer
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz /data/tmp/{{ item }}.tar.gz"
loop:
- api
- daemon
- library
- mdot
- task-runner
- uploader
- upload-service
- website
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz {{ temp_dir }}/{{ item }}.tar.gz"
loop: "{{ repos }}"
- name: Create temp untar dir
become_user: deployer
file:
path: "{{ temp_dir }}"
state: directory
- name: Untar packages
unarchive:
src: "/data/tmp/{{ item }}.tar.gz"
dest: /data/www/
src: "{{ temp_dir }}/{{ item }}.tar.gz"
dest: "{{ temp_dir }}"
remote_src: yes
loop:
- api
- daemon
- library
- mdot
- task-runner
- uploader
- upload-service
- website
loop: "{{ repos }}"
- name: Rsync temprorary directory to deployment directory
become_user: deployer
synchronize:
src: "{{ temp_dir }}/{{ item }}"
dest: "{{ deploy_dir }}/{{ item }}"
recursive: yes
delete: yes
delegate_to: "{{ inventory_hostname }}"
loop: "{{ repos }}"
- name: Remove temporary directory
become_user: deployer
file:
path: "{{ temp_dir }}"
state: absent
- name: Change file permissions
file:
path: /data/www
path: "{{ deploy_dir }}"
state: directory
recurse: yes
owner: www-data
group: deployer
- name: Create cronjobs
copy:
src: "/data/www/task-runner/scripts/{{ item }}"
src: "{{ deploy_dir }}/task-runner/scripts/{{ item }}"
dest: "/etc/cron.{{ item }}"
owner: www-data
group: deployer
Expand All @@ -61,7 +76,7 @@
- hourly/system-check
- name: Create daemon service files
copy:
src: "/data/www/daemon/scripts/{{ item }}"
src: "{{ deploy_dir }}/daemon/scripts/{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
owner: www-data
group: deployer
Expand All @@ -72,7 +87,7 @@
- sqs-daemon.service
- name: Create uploader service
copy:
src: /data/www/uploader/scripts/uploader.service
src: "{{ deploy_dir }}/uploader/scripts/uploader.service"
dest: /etc/systemd/system/uploader.service
owner: www-data
group: deployer
Expand Down
46 changes: 33 additions & 13 deletions provisioners/deploy-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
- name: Deploy code on machine and configure cron
hosts: default
become: true
vars:
repos:
- api
- library
- task-runner
temp_dir: /data/tmp/www
deploy_dir: /data/www
tasks:
- name: Create minute cron dir
file:
Expand All @@ -16,30 +23,43 @@
job: "cd / && run-parts --report /etc/cron.minute"
- name: Copy packages from S3
become_user: deployer
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz /data/tmp/{{ item }}.tar.gz"
loop:
- api
- library
- task-runner
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz {{ temp_dir }}/{{ item }}.tar.gz"
loop: "{{ repos }}"
- name: Create temp untar dir
become_user: deployer
file:
path: "{{ temp_dir }}"
state: directory
- name: Untar packages
unarchive:
src: "/data/tmp/{{ item }}.tar.gz"
dest: /data/www/
src: "{{ temp_dir }}/{{ item }}.tar.gz"
dest: "{{ temp_dir }}"
remote_src: yes
loop:
- api
- library
- task-runner
loop: "{{ repos }}"
- name: Rsync temprorary directory to deployment directory
become_user: deployer
synchronize:
src: "{{ temp_dir }}/{{ item }}"
dest: "{{ deploy_dir }}/{{ item }}"
recursive: yes
delete: yes
delegate_to: "{{ inventory_hostname }}"
loop: "{{ repos }}"
- name: Remove temporary directory
become_user: deployer
file:
path: "{{ temp_dir }}"
state: "absent"
- name: Change file permissions
file:
path: /data/www
path: "{{ deploy_dir }}"
state: directory
recurse: yes
owner: www-data
group: deployer
- name: Create cronjobs
copy:
src: "/data/www/task-runner/scripts/{{ item }}"
src: "{{ deploy_dir }}/task-runner/scripts/{{ item }}"
dest: "/etc/cron.{{ item }}"
owner: www-data
group: deployer
Expand Down
51 changes: 35 additions & 16 deletions provisioners/deploy-taskrunner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
- name: Perform taskrunner deployment steps
hosts: default
become: true
vars:
repos:
- api
- daemon
- library
- task-runner
temp_dir: /data/tmp/www
deploy_dir: /data/www
tasks:
- name: Create minute cron dir
file:
Expand All @@ -16,32 +24,43 @@
job: "cd / && run-parts --report /etc/cron.minute"
- name: Copy packages from S3
become_user: deployer
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz /data/tmp/{{ item }}.tar.gz"
loop:
- api
- daemon
- library
- task-runner
command: "aws s3 cp s3://permanent-repos/{{ perm_env }}/{{ item }}.tar.gz {{ temp_dir }}/{{ item }}.tar.gz"
loop: "{{ repos }}"
- name: Create temp untar dir
become_user: deployer
file:
path: "{{ temp_dir }}"
state: directory
- name: Untar packages
unarchive:
src: "/data/tmp/{{ item }}.tar.gz"
dest: /data/www/
src: "{{ temp_dir }}/{{ item }}.tar.gz"
dest: "{{ temp_dir }}"
remote_src: yes
loop:
- api
- daemon
- library
- task-runner
loop: "{{ repos }}"
- name: Rsync temprorary directory to deployment directory
become_user: deployer
synchronize:
src: "{{ temp_dir }}/{{ item }}"
dest: "{{ deploy_dir }}/{{ item }}"
recursive: yes
delete: yes
delegate_to: "{{ inventory_hostname }}"
loop: "{{ repos }}"
- name: Remove temporary directory
become_user: deployer
file:
path: "{{ temp_dir }}"
state: absent
- name: Change file permissions
file:
path: /data/www
path: "{{ deploy_dir }}"
state: directory
recurse: yes
owner: www-data
group: deployer
- name: Create cronjobs
copy:
src: "/data/www/task-runner/scripts/{{ item }}"
src: "{{ deploy_dir }}/task-runner/scripts/{{ item }}"
dest: "/etc/cron.{{ item }}"
owner: www-data
group: deployer
Expand All @@ -52,7 +71,7 @@
- hourly/system-check
- name: Create daemon service files
copy:
src: "/data/www/daemon/scripts/{{ item }}"
src: "{{ deploy_dir }}/daemon/scripts/{{ item }}"
dest: "/etc/systemd/system/{{ item }}"
owner: www-data
group: deployer
Expand Down

0 comments on commit 39c2f0e

Please sign in to comment.