Skip to content

Commit

Permalink
update - fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
superstes committed Oct 27, 2021
1 parent bf0d915 commit 07df3be
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 8 deletions.
1 change: 1 addition & 0 deletions setup/roles/update/tasks/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- name: GA | Update | Backup | Backing up directories
ansible.builtin.shell: "tar cf - {{ item.src }} | xz -7 > {{ item.dst }}"
warn: false
with_items:
- {src: "{{ ga_update_path_core }}", dst: "{{ ga_update_path_backup }}/core.tar.xz"}
- {src: "{{ ga_update_path_web }}", dst: "{{ ga_update_path_backup }}/web.tar.xz"}
Expand Down
34 changes: 32 additions & 2 deletions setup/roles/update/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
---

- debug:
msg: "########################################\n
########################################\n
Preparing for Update!\n
########################################\n
########################################"

- name: GA | Update | Installing dependencies
ansible.builtin.apt:
name: "{{ ga_update_packages }}"
Expand All @@ -13,6 +20,13 @@
- name: GA | Update | Backing-up current version
ansible.builtin.import_tasks: backup.yml

- debug:
msg: "########################################\n
########################################\n
GrowAutomation will now be upgraded to version {{ ga_update_release_now }} - '{{ ga_update_commit_now }}'!\n
########################################\n
########################################"

- name: GA | Update | Running update tasks
ansible.builtin.import_tasks: do.yml

Expand Down Expand Up @@ -47,8 +61,8 @@
- name: GA | Update | Updating version number
ansible.builtin.shell: "echo \"{{ item }};\" | mysql --defaults-file={{ ga_update_path_web }}/{{ ga_db_config }} {{ ga_sql_db }}"
with_items:
- "update ga_systemagentmodel set version='{{ ga_update_release }}', version_detail='{{ ga_update_commit }}'" # todo: once there is support for multiple agents we will need to target the update-cmd
- "update ga_systemservermodel set version='{{ ga_update_release }}', version_detail='{{ ga_update_commit }}'"
- "update ga_systemagentmodel set version='{{ ga_update_release_now }}', version_detail='{{ ga_update_commit_now }}'" # todo: once there is support for multiple agents we will need to target the update-cmd
- "update ga_systemservermodel set version='{{ ga_update_release_now }}', version_detail='{{ ga_update_commit_now }}'"
when: not ga_update_failed

- name: GA | Update | Restarting services
Expand All @@ -58,3 +72,19 @@
with_items:
- 'ga_core.service'
- 'apache2.service'

- debug:
msg: "########################################\n
########################################\n
GrowAutomation was successfully updated to version {{ ga_update_release_now }} - '{{ ga_update_commit_now }}'!\n
########################################\n
########################################"
when: not ga_update_failed

- debug:
msg: "########################################\n
########################################\n
GrowAutomation update to version {{ ga_update_release_now }} - '{{ ga_update_commit_now }}' FAILED!\n
########################################\n
########################################"
when: ga_update_failed
28 changes: 22 additions & 6 deletions setup/roles/update/tasks/preparations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

- name: GA | Update | Prep | Getting last release version
ansible.builtin.set_fact:
ga_update_release: "{{ ga_release_list.json | json_query('[*].name') | first }}"
ga_update_release_now: "{{ ga_release_list.json | json_query('[*].name') | first }}"
changed_when: false
when:
- ga_update_method == 'online'
Expand All @@ -24,7 +24,7 @@

- name: GA | Update | Prep | Getting commit-id of last release version
ansible.builtin.set_fact:
ga_update_commit: "{{ ga_release_list.json | json_query('[*].commit.sha') | first }}"
ga_update_commit_now: "{{ ga_release_list.json | json_query('[*].commit.sha') | first }}"
changed_when: false
when:
- ga_update_method == 'online'
Expand All @@ -33,6 +33,22 @@

# validating repo

- name: GA | Update | Prep | Setting release version
ansible.builtin.set_fact:
ga_update_release_now: "{{ ga_update_release }}"
when:
- ga_update_release is defined
- ga_update_release != 'None'
- ga_update_type != 'commit'

- name: GA | Update | Prep | Setting release version
ansible.builtin.set_fact:
ga_update_commit_now: "{{ ga_update_commit }}"
when:
- ga_update_commit is defined
- ga_update_commit != 'None'
- ga_update_type == 'commit'

- name: GA | Update | Prep | Checking if repository exists
ansible.builtin.stat:
path: "{{ ga_update_path_repo }}"
Expand Down Expand Up @@ -60,11 +76,11 @@
# setting repo to target version

- name: GA | Update | Prep | Setting repo to target release
ansible.builtin.shell: "cd {{ ga_update_path_repo }} && git reset --hard {{ ga_update_release }}"
ansible.builtin.shell: "cd {{ ga_update_path_repo }} && git reset --hard {{ ga_update_release_now }}"
when: ga_update_type != 'commit'

- name: GA | Update | Prep | Setting repo to target commit
ansible.builtin.shell: "cd {{ ga_update_path_repo }} && git reset --hard {{ ga_update_commit }}"
ansible.builtin.shell: "cd {{ ga_update_path_repo }} && git reset --hard {{ ga_update_commit_now }}"
when: ga_update_type == 'commit'

- name: GA | Update | Prep | Getting release of commit
Expand All @@ -76,7 +92,7 @@
# get 'parent'-release of commit if commit is used as a target version

- name: GA | Update | Prep | Setting release version
ansible.builtin.set_fact:
ga_update_release: "{{ ga_raw_commit_release.stdout }}"
ansible.builtin.vars:
ga_update_release_now: "{{ ga_raw_commit_release.stdout }}"
changed_when: false
when: ga_update_type == 'commit'
2 changes: 2 additions & 0 deletions setup/roles/update/tasks/restore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- name: GA | Update | Restore | Saving logs for debug reasons
ansible.builtin.shell: "tar cf - {{ ga_update_path_log }} | xz -7 > {{ ga_update_path_backup }}/log_restore.tar.xz"
warn: false

- name: GA | Update | Restore | Stopping core service
ansible.builtin.systemd:
Expand All @@ -23,6 +24,7 @@

- name: GA | Update | Restore | Restoring directories
ansible.builtin.shell: "tar -xJf {{ item }} -C /"
warn: false
with_items:
- "{{ ga_update_path_backup }}/core.tar.xz"
- "{{ ga_update_path_backup }}/web.tar.xz"
Expand Down

0 comments on commit 07df3be

Please sign in to comment.