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

Multiple sites on the same hosts enhancements #54

Merged
merged 7 commits into from
Aug 28, 2020
Merged
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,23 @@ as `atom-site` in the role (i.e., tasks required to deploy a site)
and skip the tasks that are required only once per host deploy. The
database and user for the new site will also need to be configured in
the database server if not done already.

## Use a different revision dir for every site update

When the `atom_revision_directory` variable is set to `yes`, a new
`$atom_path/atom-COMMIT_ID` directory is created for every update and a
`$atom_path/$atom_revision_directory_latest_symlink_dir` symlink is created
pointing to the latest revision dir.

For instance:

```
/usr/share/nginx/atom
├── atom-0134577b6ecd763dedf82a7eee4ddc35043c5345
├── atom-1234567b6ecd763dedf92a7bad4ddc35043c5438
├── atom-381f849b6ecd763dedf92a7bad43cc350a3c5439
├── downloads
├── private -> /usr/share/nginx/atom/src
├── src -> /usr/share/nginx/atom/atom-381f849b6ecd763dedf92a7bad43cc350a3c5439
└── uploads
```
24 changes: 20 additions & 4 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ atom_install_dependencies: "true"
# Install some extra packages specific to our official Vagrant-based
# development box. See `tasks/devbox.yml` for more details.
atom_devbox: "no"
# Use a different AtoM directory for each revision
atom_revision_directory: "no"
atom_revision_directory_latest_symlink_dir: "src"
# Create a symlink from atom_path/private to
# atom_path/atom_revision_directory_latest_symlink_dir
atom_private_symlink: "no"

hakamine marked this conversation as resolved.
Show resolved Hide resolved
#
# Choose php version to use
Expand All @@ -36,11 +42,21 @@ atom_worker_service_name: "{{ atom_path | basename }}-worker"
atom_worker_old_config: "no"

#
# Misc
# CLI tasks
#

# Compile all available themes
atom_compile_all_themes: "no"
# Populate search index
atom_populate_index: "no"
# Rebuild nested-set and generate slugs
atom_fix_data: "no"
# Upgrade sql
atom_upgrade_sql: "no"

#
# Misc
#

# Flush database
atom_flush_data: "no"
Expand All @@ -50,9 +66,9 @@ atom_build_static_assets: "yes"

# Themes (to build)
atom_themes:
- path: "{{ atom_path }}/plugins/arDominionPlugin"
- path: "{{ atom_path }}/{{ atom_extra_path }}/plugins/arDominionPlugin"
hakamine marked this conversation as resolved.
Show resolved Hide resolved
build_cmd: "make"
- path: "{{ atom_path }}/plugins/arArchivesCanadaPlugin"
- path: "{{ atom_path }}/{{ atom_extra_path }}/plugins/arArchivesCanadaPlugin"
build_cmd: "make"

# Plug-ins
Expand Down Expand Up @@ -204,7 +220,7 @@ atom_pool_php_envs:
#

atom_drmc: "no"
atom_drmc_path: "{{ atom_path }}/plugins/arDrmcPlugin/frontend"
atom_drmc_path: "{{ atom_path }}/{{ atom_extra_path }}/plugins/arDrmcPlugin/frontend"
# Install Mock API
atom_drmc_mock: "no"
# Copy ES plugins to /etc/elasticsearch
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- name: "Clear sf_cache"
shell: "php symfony cc"
args:
chdir: "{{ atom_path }}"
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
become_user: "{{ atom_user }}"
environment:
- "{{ atom_pool_php_envs }}"
Expand Down
54 changes: 33 additions & 21 deletions tasks/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,30 @@

- name: "Create site directory if it doesn't exist'"
file:
path: "{{ atom_path }}"
path: "{{ atom_path }}/{{ atom_extra_path }}"
state: "directory"
owner: "{{ atom_user }}"
group: "{{ atom_group }}"
mode: "u=rwx,g=rwx,o=rx"

- name: "Cleanup cache/ directory"
command: "rm -rf {{ atom_path }}/cache/*"
command: "rm -rf {{ atom_path }}/{{ atom_extra_path }}/cache/*"

- name: "Temporarily delete uploads symlink to avoid long waits on recursive chmod"
file:
state: "absent"
path: "{{ atom_path }}/uploads"
path: "{{ atom_path }}/{{ atom_extra_path }}/uploads"
when: "atom_uploads_symlink is defined"

- name: "Temporarily delete downloads symlink to avoid long waits on recursive chmod"
file:
state: "absent"
path: "{{ atom_path }}/{{ atom_extra_path }}/downloads"
when: "atom_downloads_symlink is defined"

- name: "Temporarily change permissions of site directory to be able to clone repo"
file:
path: "{{ atom_path }}"
path: "{{ atom_path }}/{{ atom_extra_path }}"
state: "directory"
mode: "o+w"
recurse: yes
Expand All @@ -37,16 +43,18 @@
update: "yes"
repo: "{{ atom_repository_url }}"
version: "{{ atom_repository_version }}"
dest: "{{ atom_path }}"
dest: "{{ atom_path }}/{{ atom_extra_path }}"
accept_hostkey: "yes"
depth: "{{ atom_git_pull_code_depth | default(omit) }}"
force: "{{ atom_git_pull_code_force | default('no') }}"
notify:
- "Clear sf_cache"
- "Reload PHP service"
become: "no"

- name: "Restore permissions and fix ownership of site directory"
file:
path: "{{ atom_path }}"
path: "{{ atom_path }}/{{ atom_extra_path }}"
state: "directory"
owner: "{{ atom_user }}"
group: "{{ atom_group }}"
Expand All @@ -55,7 +63,7 @@

- name: "Create log directory"
file:
path: "{{ atom_path }}/log"
path: "{{ atom_path }}/{{ atom_extra_path }}/log"
state: "directory"
owner: "{{ atom_user }}"
group: "{{ atom_group }}"
Expand All @@ -70,28 +78,28 @@
backup: "yes"
with_items:
- src: "{{ atom_template_config_php }}"
dest: "{{ atom_path }}/config/config.php"
dest: "{{ atom_path }}/{{ atom_extra_path }}/config/config.php"
- src: "{{ atom_template_propel_ini }}"
dest: "{{ atom_path }}/config/propel.ini"
dest: "{{ atom_path }}/{{ atom_extra_path }}/config/propel.ini"
- src: "{{ atom_template_app_yml }}"
dest: "{{ atom_path }}/apps/qubit/config/app.yml"
dest: "{{ atom_path }}/{{ atom_extra_path }}/apps/qubit/config/app.yml"
- src: "{{ atom_template_factories_yml }}"
dest: "{{ atom_path }}/apps/qubit/config/factories.yml"
dest: "{{ atom_path }}/{{ atom_extra_path }}/apps/qubit/config/factories.yml"
- src: "{{ atom_template_settings_yml }}"
dest: "{{ atom_path }}/apps/qubit/config/settings.yml"
dest: "{{ atom_path }}/{{ atom_extra_path }}/apps/qubit/config/settings.yml"
- src: "{{ atom_template_gearman_yml }}"
dest: "{{ atom_path }}/apps/qubit/config/gearman.yml"
dest: "{{ atom_path }}/{{ atom_extra_path }}/apps/qubit/config/gearman.yml"
- src: "{{ atom_template_search_yml }}"
dest: "{{ atom_path }}/apps/qubit/config/search.yml"
dest: "{{ atom_path }}/{{ atom_extra_path }}/apps/qubit/config/search.yml"
notify:
- "Clear sf_cache"
- "Reload PHP service"

- name: "Install sf symlink"
file:
state: "link"
src: "{{ atom_path }}/vendor/symfony/data/web/sf"
path: "{{ atom_path }}/sf"
src: "{{ atom_path }}/{{ atom_extra_path }}/vendor/symfony/data/web/sf"
path: "{{ atom_path }}/{{ atom_extra_path }}/sf"
owner: "{{ atom_user }}"
group: "{{ atom_group }}"

Expand All @@ -107,21 +115,21 @@

- name: "Check if the composer.lock file exists"
stat:
path: "{{ atom_path }}/composer.lock"
path: "{{ atom_path }}/{{ atom_extra_path }}/composer.lock"
register: composer_lock

- name: "Install Composer dependencies for production"
composer:
command: install
working_dir: "{{ atom_path }}"
working_dir: "{{ atom_path }}/{{ atom_extra_path }}"
when:
- composer_lock.stat.exists
- atom_environment_type != "development"

- name: "Install Composer dependencies for dev"
composer:
command: install
working_dir: "{{ atom_path }}"
working_dir: "{{ atom_path }}/{{ atom_extra_path }}"
no_dev: no
when:
- composer_lock.stat.exists
Expand All @@ -130,11 +138,15 @@
- name: "SELinux tasks"
block:
- name: "Selinux: allow httpd to write on atom folder"
shell: 'semanage fcontext -a -t httpd_sys_rw_content_t {{ atom_path }}\(/.*\)? && restorecon -R -v {{ atom_path }}'
shell: 'semanage fcontext -a -t httpd_sys_rw_content_t {{ atom_path }}/{{ atom_extra_path }}\(/.*\)? && restorecon -R -v {{ atom_path }}/{{ atom_extra_path }}'
- name: "Selinux: allow httpd to write on uploads folders"
shell: 'semanage fcontext -a -t httpd_sys_rw_content_t {{ atom_uploads_symlink }}\(/.*\)? && restorecon -R -v {{ atom_uploads_symlink }}'
when:
- "atom_uploads_symlink is defined"
- name: "Selinux: allow httpd to write on downloads folders"
shell: 'semanage fcontext -a -t httpd_sys_rw_content_t {{ atom_downloads_symlink }}\(/.*\)? && restorecon -R -v {{ atom_downloads_symlink }}'
when:
- "atom_downloads_symlink is defined"
- name: "Selinux: enable httpd_can_network_connect"
seboolean:
name: httpd_can_network_connect
Expand All @@ -144,4 +156,4 @@
- ansible_os_family == "RedHat"
- ansible_selinux is defined and ansible_selinux != False and ansible_selinux.status == 'enabled'
tags:
- selinux
- selinux
60 changes: 44 additions & 16 deletions tasks/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- name: "Temporarily change ownership of site directory (to be able to build)"
file:
path: "{{ atom_path }}"
path: "{{ atom_path }}/{{ atom_extra_path }}"
state: "directory"
mode: "o+w"
recurse: yes
Expand All @@ -16,23 +16,51 @@
# AtoM
#

- name: "Find themes"
shell: "find {{ atom_path }}/{{ atom_extra_path }}/plugins -name Makefile | sed -r 's/Makefile//g'"
register: theme_makefiles
when: atom_compile_all_themes|bool

- name: "Build AtoM themes (Ubuntu)"
command: "{{ item.build_cmd }}"
args:
chdir: "{{ item.path }}"
with_items: "{{ atom_themes }}"
become: "no"
when:
- ansible_os_family == "Debian"
block:
- name: "Build all AtoM themes (Ubuntu)"
command: "make"
args:
chdir: "{{ item }}"
with_items: "{{ theme_makefiles.stdout_lines }}"
become: "no"
when:
- atom_compile_all_themes|bool
- name: "Build selected AtoM themes (Ubuntu)"
command: "{{ item.build_cmd }}"
args:
chdir: "{{ item.path }}"
with_items: "{{ atom_themes }}"
become: "no"
when:
- not atom_compile_all_themes|bool # Don't compile themes when they are alreay compiled
when: ansible_os_family == "Debian"

- name: "Build AtoM themes (CentOS/RH)"
command: "scl enable rh-nodejs6 {{ item.build_cmd }}"
args:
chdir: "{{ item.path }}"
with_items: "{{ atom_themes }}"
become: "no"
when:
- ansible_os_family == "RedHat"
block:
- name: "Build all AtoM themes (CentOS/RH)"
command: "scl enable rh-nodejs6 make"
args:
chdir: "{{ item }}"
with_items: "{{ theme_makefiles.stdout_lines }}"
become: "no"
when:
- atom_compile_all_themes|bool
- name: "Build selected AtoM themes (CentOS/RH)"
command: "scl enable rh-nodejs6 {{ item.build_cmd }}"
args:
chdir: "{{ item.path }}"
with_items: "{{ atom_themes }}"
become: "no"
when:
- not atom_compile_all_themes|bool # Don't compile themes when they are alreay compiled
when: ansible_os_family == "RedHat"

#
# DRMC/Binder
#
Expand Down Expand Up @@ -72,7 +100,7 @@

- name: "Restore permissions and fix ownership of site directory"
file:
path: "{{ atom_path }}"
path: "{{ atom_path }}/{{ atom_extra_path }}"
state: "directory"
owner: "{{ atom_user }}"
group: "{{ atom_group }}"
Expand Down
41 changes: 41 additions & 0 deletions tasks/cli_tools.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---

- name: "Update database"
command: "php symfony tools:upgrade-sql -B"
args:
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
when: "atom_upgrade_sql|bool"

- name: "Build nested set"
command: "php symfony propel:build-nested-set"
args:
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
when: "atom_fix_data|bool"

- name: "Generate slugs"
command: "php symfony propel:generate-slugs"
args:
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
when: "atom_fix_data|bool"

- name: "Clear cache"
command: "php symfony cache:clear"
args:
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
notify:
- "Reload PHP service"

# stdout is ignored, not very useful and too verbose (--quiet opt would be nice)
- name: "Populate search index"
shell: "php symfony search:populate"
args:
chdir: "{{ atom_path }}/{{ atom_extra_path }}"
ignore_errors: "yes" # segfault in php7, not sure yet why!
environment: "{{ atom_pool_php_envs }}"
register: "search_populate"
when: "atom_populate_index|bool"
DavidHume-ArtefactualSystems marked this conversation as resolved.
Show resolved Hide resolved

- name: "Print populate search index output"
debug:
msg: "{{ search_populate.stdout_lines | last }}"
when: "search_populate.changed"
Loading