Skip to content

Commit

Permalink
Update the workflow of wordpress installation program
Browse files Browse the repository at this point in the history
  • Loading branch information
thib-info committed Nov 24, 2023
1 parent 9b0ab1e commit b11f120
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 87 deletions.
14 changes: 14 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,23 @@
- steamengine_cron
tags: always

- name: Check if steamengine_project_type/post_deploy.yml exists
ansible.builtin.stat:
path: "{{ steamengine_project_type }}/post_deploy.yml"
register: steamengine_post_deploy_check

- include_tasks:
file: "{{ steamengine_project_type }}/post_deploy.yml"
apply:
tags:
- steamengine_deploy
when: steamengine_post_deploy_check.stat.exists
tags: always

- include_tasks:
file: common/post_deploy.yml
apply:
tags:
- steamengine_deploy
when: not steamengine_post_deploy_check.stat.exists
tags: always
87 changes: 4 additions & 83 deletions tasks/wordpress/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

- name: Is there a .env file
ansible.builtin.stat:
path: "{{ steamengine_project_root_path }}/.env"
path: "{{ steamengine_conf_path }}/.env"
register: project_env_file_exist

- name: "Create .env backup file"
ansible.builtin.copy:
src: "{{ steamengine_project_root_path }}/.env"
dest: "{{ steamengine_project_root_path }}/.env.backup"
src: "{{ steamengine_conf_path }}/.env"
dest: "{{ steamengine_conf_path }}/.env.backup"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
mode: u=rw,g=r,o=r
Expand All @@ -19,7 +19,7 @@
- name: "Create configuration file for projects"
ansible.builtin.template:
src: wordpress.env.j2
dest: "{{ steamengine_project_root_path }}/.env"
dest: "{{ steamengine_conf_path }}/.env"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
mode: u=rw,g=r,o=r
Expand Down Expand Up @@ -69,22 +69,9 @@
dest: "{{ steamengine_project_wordpress_new_release_path }}"
remote_src: true
list_files: true
when: new_build_to_deploy is defined and new_build_to_deploy

- name: "Add read permission for {{ steamengine_app_user }}"
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_new_release_path }}/"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
recurse: true
mode: u=rw,g=rw,o=
tags:
- steamengine_deploy_wordpress

- name: Is there a uploads directory
ansible.builtin.stat:
path: "{{ steamengine_project_wordpress_uploads_path }}"
register: project_uploads_directory_exist
when: new_build_to_deploy is defined and new_build_to_deploy

- name: "Is there a current release : {{ steamengine_project_wordpress_current_release_path }}"
Expand All @@ -102,15 +89,6 @@
mode: u=rw,g=rw,o=
when: new_build_to_deploy is defined and new_build_to_deploy and not project_current_release_exist.stat.exists

- name: "Ensure {{ steamengine_project_wordpress_uploads_path }} has the right permissions"
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_uploads_path }}"
state: directory
mode: u=rwx,g=rx,o=
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
when: new_build_to_deploy is defined and new_build_to_deploy

- name: Clean old release directory
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_old_release_path }}"
Expand All @@ -125,60 +103,3 @@
group: "{{ steamengine_app_user }}"
mode: u=rw,g=rw,o=
when: new_build_to_deploy is defined and new_build_to_deploy and project_current_release_exist.stat.exists

- name: Move current release to old release
ansible.builtin.shell: "mv {{ steamengine_project_wordpress_current_release_path }}/* {{ steamengine_project_wordpress_old_release_path }}"
when: new_build_to_deploy is defined and new_build_to_deploy and project_current_release_exist.stat.exists

- name: Remove symlink on old release
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_old_release_path }}/item.symlink_src"
state: absent
with_items: "{{ steamengine_project_wordpress_symlinks }}"
when: new_build_to_deploy is defined and new_build_to_deploy and project_current_release_exist.stat.exists

- name: "Move the .env.backup file on the old directory"
ansible.builtin.copy:
src: "{{ steamengine_project_root_path }}/.env.backup"
dest: "{{ steamengine_project_wordpress_old_release_path }}/.env"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
remote_src: yes
mode: u=rw,g=r,o=r
become: true
when: project_env_file_exist.stat.exists and new_build_to_deploy is defined and new_build_to_deploy

- name: "Delete the .env.backup file"
ansible.builtin.file:
path: "{{ steamengine_project_root_path }}/.env.backup"
state: absent
when: project_env_file_exist.stat.exists and new_build_to_deploy is defined and new_build_to_deploy

- name: Move next release to current release using mv command
ansible.builtin.shell: "mv {{ steamengine_project_wordpress_new_release_path }}/* {{ steamengine_project_wordpress_current_release_path }}"
when: new_build_to_deploy is defined and new_build_to_deploy

- name: Add/Switch symlink on the new current release
ansible.builtin.file:
src: "{{ item.path }}"
dest: "{{ steamengine_project_wordpress_current_release_path }}/{{ item.symlink_src }}"
state: link
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
with_items: "{{ steamengine_project_wordpress_symlinks }}"
when: new_build_to_deploy is defined and new_build_to_deploy

- name: "Ensure {{ steamengine_project_wordpress_current_release_path }} has the right permissions"
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_current_release_path }}"
state: directory
mode: u=rw,g=rw,o=
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
when: new_build_to_deploy is defined and new_build_to_deploy

- name: Clean new release directory
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_new_release_path }}"
state: absent
when: new_build_to_deploy is defined and new_build_to_deploy
81 changes: 81 additions & 0 deletions tasks/wordpress/post_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---

- name: Create storage subdirectories
ansible.builtin.file:
state: directory
path: "{{ steamengine_persistent_base_path }}/{{ item.path }}"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
mode: u=rwx,g=rwx,o=
when: new_build_to_deploy is defined and new_build_to_deploy
loop: "{{ steamengine_persistent_directories }}"

- name: Delete directories if exists
ansible.builtin.file:
state: absent
path: "/{{ steamengine_project_name }}/{{ item.symlink_src }}"
when:
- item.delete_dir is defined and item.delete_dir
- new_build_to_deploy is defined and new_build_to_deploy
loop: "{{ steamengine_persistent_directories }}"

- name: Create symbolic link to storage directories on new release directory
ansible.builtin.file:
state: link
src: "{{ steamengine_persistent_base_path }}/{{ item.path }}"
dest: "/{{ steamengine_project_wordpress_new_release_path }}/{{ item.symlink_src }}"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
mode: u=rwx,g=rwx,o=
when:
- item.symlink_src is defined and item.symlink_src
- new_build_to_deploy is defined and new_build_to_deploy
loop: "{{ steamengine_persistent_directories }}"

- name: Move current release to old release
ansible.builtin.shell: "mv {{ steamengine_project_wordpress_current_release_path }}/* {{ steamengine_project_wordpress_old_release_path }}"
when: new_build_to_deploy is defined and new_build_to_deploy and project_current_release_exist.stat.exists

- name: Remove symlink on old release
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_old_release_path }}/item.symlink_src"
state: absent
with_items: "{{ steamengine_project_wordpress_symlinks }}"
when: new_build_to_deploy is defined and new_build_to_deploy and project_current_release_exist.stat.exists

- name: "Move the .env.backup file on the old directory"
ansible.builtin.copy:
src: "{{ steamengine_project_root_path }}/.env.backup"
dest: "{{ steamengine_project_wordpress_old_release_path }}/.env"
owner: "{{ steamengine_project_user }}"
group: "{{ steamengine_app_user }}"
remote_src: yes
mode: u=rw,g=r,o=r
become: true
when: project_env_file_exist.stat.exists and new_build_to_deploy is defined and new_build_to_deploy

- name: "Delete the .env.backup file"
ansible.builtin.file:
path: "{{ steamengine_project_root_path }}/.env.backup"
state: absent
when: project_env_file_exist.stat.exists and new_build_to_deploy is defined and new_build_to_deploy

- name: Move next release to current release using mv command
ansible.builtin.shell: "mv {{ steamengine_project_wordpress_new_release_path }}/* {{ steamengine_project_wordpress_current_release_path }}"
when: new_build_to_deploy is defined and new_build_to_deploy

- name: Clean new release directory
ansible.builtin.file:
path: "{{ steamengine_project_wordpress_new_release_path }}"
state: absent
when: new_build_to_deploy is defined and new_build_to_deploy

- name: "Run post deploy commands"
ansible.builtin.command: "/{{ steamengine_project_name }}/bin/steamengine {{ item }}"
when: new_build_to_deploy is defined and new_build_to_deploy and steamengine_wrapper_scripts_post_deploy
loop: "{{ steamengine_wrapper_scripts_post_deploy }}"

- name: Start extra services
ansible.builtin.command: "/{{ steamengine_project_name }}/bin/steamengine {{ item.name }}_start"
when: new_build_to_deploy is defined and new_build_to_deploy
loop: "{{ steamengine_extra_services }}"
5 changes: 1 addition & 4 deletions vars/wordpress.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
---

steamengine_project_wordpress_uploads_path: "{{ steamengine_project_root_path }}/uploads"
steamengine_project_wordpress_current_release_path: "{{ steamengine_project_root_path }}/current_release"
steamengine_project_wordpress_old_release_path: "{{ steamengine_project_root_path }}/old_release"
steamengine_project_wordpress_new_release_path: "{{ steamengine_project_root_path }}/new_release"
steamengine_project_wordpress_symlinks:
- path: "{{ steamengine_project_root_path }}/.env"
symlink_src: ".env"
- path: "{{ steamengine_project_wordpress_uploads_path }}"
symlink_src: "web/app/uploads"
symlink_src: "{{ steamengine_conf_path }}/.env"

# WORDPRESS
steamengine_wrapper_scripts_base:
Expand Down

0 comments on commit b11f120

Please sign in to comment.