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

Conversation

mamedin
Copy link
Contributor

@mamedin mamedin commented Aug 6, 2020

This PR adds:

  • Use a different revision directory for every site update.
  • Add new tasks file for CLI commands.
  • Add private symlink.
  • Add downloads symlink.
  • Ensure downloads and uploads symlink directories exist.

Connects to #53 and #20

Copy link
Member

@amayita amayita left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome!

defaults/main.yml Outdated Show resolved Hide resolved
defaults/main.yml Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
tasks/cli_tools.yml Outdated Show resolved Hide resolved
Copy link
Member

@hakamine hakamine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll try to summarize my added comments below:

  1. Example in README.md needs quick correction (either change /usr/share/nginx/atom in the first line with /use/share/nginx/test5, or change the "test5" in the other lines with "atom")
  2. Try to avoid defining atom_extra_path in defaults/main.yml (as it is not a variable whose value could be customized by the user)
  3. task/cli_tools.yml is adding tasks that build the AtoM themes, but there are tasks that already do a similar thing in tasks/build.yml
  4. git task added in tasks/revision-dir.yml could fail if the repository has not been already cloned before?
  5. Is the "private" symlink needed?

For 2. and 4. I was thinking we could for example:

  • In defaults/main.yml remove the atom_extra_path:"" declaration
  • In tasks/main.yml, remove the when conditional for task include: "revision-dir.yml"
  • Refactor revision_dir.yml for example like (haven't tested it):
- name: Get latest revision
  shell: "git ls-remote {{ atom_repository_url }} {{ atom_repository_version }} | awk '{print $1}'"
  register: latest_revision
- name: "Define atom_extra_path when using atom_revision_directory"
  set_fact:
    atom_extra_path: "atom-{{ latest_revision.stdout }}"
  when: 
atom_revision_directory is defined and atom_revision_directory|bool 
- name: "Define atom_extra_path as empty when not using atom_revision_directory"
  set_fact:
    atom_extra_path: ""
  when: 
atom_revision_directory is undefined or not atom_revision_directory|bool

@mamedin mamedin force-pushed the dev/atom-site_enhancements branch 2 times, most recently from ad53093 to a1084d5 Compare August 11, 2020 10:49
@mamedin
Copy link
Contributor Author

mamedin commented Aug 11, 2020

Thanks very much for CR!

I have changed the branch to include your suggestions. Using the summary points added by @hakamine in last comment:

  1. Fixed duplicated variables added to defaults/main.yml

  2. Fixed example in README.md

  3. atom_extra_path is now defined with set_fact. I added this task in tasks/main.yml because this variable is used by drmc-mock and atom-devbox tasks. The "always" tag has been added to this task and the include: "revision-dir.yml" one because it is used by almost all tags, the explicit list should be:

    • "atom-site"
    • "drmc-mock"
    • "atom-devbox"
    • "atom-basic"
    • "atom-flush"
    • "atom-plugins"
    • "atom-search"
    • "atom-cli"
    • "atom-build"
    • "atom-worker"
    • "atom-uploads"
    • "atom-downloads"
  4. (No changes from last PR branch) The "Compile all themes" task is useful to avoid having to explicitly declare the themes you want to build in the atom_themes dictionary. Do you think it is a good idea to add and additional conditional to the existing "Build AtoM themes (DISTRO)" tasks (to avoid compile 2 times the themes when atom_compile_all_themes|bool)? For instance:

    • not atom_compile_all_themes|bool
  5. I have not detected any issue when the repository has not been already cloned before.

  6. Probably the "private symlink" task doesn't make sense in the AtoM role. We can remove the "private symlink" commit and create the post_task directly in the AtoM playbook when needed.

  7. Added a new commit to use version() instead of version_compare() <- Python3 compatibility

@hakamine
Copy link
Member

@mamedin thank you for the fixes. I have a comment regarding the use of the "always" tag in role, the tasks will execute every time a playbook is run and there is no way to exclude them. For example, the following playbook:

- hosts: somehost
  roles:
    - role: "nginx"
      tags: nginx
    - role: "atom"
      tags: atom

even if running the playbook with tag nginx (e.g. ansible-playbook playbook.yml -t nginx) it will execute the tasks in the atom role tagged with "always". It's probably safe if the tasks do not modify the target host (assigning vars, etc), but it could be kind of confusing.

@DavidHume-ArtefactualSystems
Copy link
Contributor

@mamedin @hakamine - I believe for atom_revision_directory style deploys of AtoM the private symlink is required for digital object access control (copyright etc.), at least was when originally set up, I'd have to recall which Hosted clients definitely used it (Mills?) and per my using this method for SFU this year, should be required.

Or Miguel are you saying it would still be present if the boolean is set, just not going to do it in the role now (number 5. in your lists).

@mamedin
Copy link
Contributor Author

mamedin commented Aug 12, 2020

@mamedin @hakamine - I believe for atom_revision_directory style deploys of AtoM the private symlink is required for digital object access control (copyright etc.), at least was when originally set up, I'd have to recall which Hosted clients definitely used it (Mills?) and per my using this method for SFU this year, should be required.

Or Miguel are you saying it would still be present if the boolean is set, just not going to do it in the role now (number 5. in your lists).

I was thinking on moving the private symlink task to our atom26.yml playbook as a post_task.

@mamedin mamedin closed this Aug 12, 2020
@mamedin mamedin reopened this Aug 12, 2020
@mamedin
Copy link
Contributor Author

mamedin commented Aug 12, 2020

Ups, wrong click!

@mamedin
Copy link
Contributor Author

mamedin commented Aug 12, 2020

@mamedin thank you for the fixes. I have a comment regarding the use of the "always" tag in role, the tasks will execute every time a playbook is run and there is no way to exclude them. For example, the following playbook:

- hosts: somehost
  roles:
    - role: "nginx"
      tags: nginx
    - role: "atom"
      tags: atom

even if running the playbook with tag nginx (e.g. ansible-playbook playbook.yml -t nginx) it will execute the tasks in the atom role tagged with "always". It's probably safe if the tasks do not modify the target host (assigning vars, etc), but it could be kind of confusing.

I'm going to change the always tag to the explicit list. Thanks Hector!

@mamedin mamedin force-pushed the dev/atom-site_enhancements branch 2 times, most recently from 454f422 to 83c699e Compare August 12, 2020 18:16
@mamedin
Copy link
Contributor Author

mamedin commented Aug 12, 2020

Hi!, branch updated again. Using again the summary points, these are the new changes:

2.- "always" tag changed on revision tasks, the tasks are using the big tag list instead.
3.- Build all themes tasks have been moved to the build.yml task file.
7.- New commit. The "deph" and "force" options for git clone are now configurable. Using old values as default options.

@@ -0,0 +1,37 @@
---

# Compile available themes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Cosmetic) Having moved this section back to tasks/build.yml, should remove this comment line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

register: "atom_revision_git_output"

- name: "Print revisions"
debug: "msg='current={{ atom_revision_git_output.before }} latest={{ atom_revision_git_output.after }}'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests, even with a previous revision these two results would be the same - but I think that might be because of the other issues we encountered. Hence my wondering @mamedin if you have gotten this output with different results yet. That is, atom_revision_git_output.before value via akin to what we used to keep in the latest file before a branch update, and atom_revision_git_output.after being the true current (which I assume the above first task does more efficiently than shell command "git ls-remote {{ atom_repository_url }} {{ atom_repository_version }} | awk '{print $1}'" did).

That said, I think as we discussed as long as .after is correct as used in the "Define atom_extra_path..." task below (so won't try to overwrite a previous or fallback revision directory) all is well...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hakamine - did you have a similar concern, I guess this relates to your refactor suggestion for revision-dir.yml on August 10 above?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DavidHume-ArtefactualSystems when I first saw the PR code I was concerned that maybe using git with "clone: no" and "update:no" would fail if there was no local repo. But re-checking the ansible docs, they provide a usage example of git with "clone: no" and "update:no", to "just get information about the repository whether or not it has already been cloned locally." therefore I think it should be good regarding my original concern. However, the problem you encountered seems to be a different issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably related to:

https://github.com/artefactual-labs/ansible-atom/blob/master/tasks/basic.yml#L3-L9

Using depth=1 is known problem.

Copy link

@luisilara luisilara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the new changes on a client upgrade and it worked properly

  • The revision-dir.yml improves the command shell: "git ls-remote {{ atom_repository_url }} {{ atom_repository_version }} | awk '{print $1}'" where in some cases it created the revision folder with the stdout with two lines eg. 'atom-d6ffd39c150ebe74adb0bc9e7e8d84797ad8def2'$'\n''c017acb60e8dceeb6ec453e368381bf12bc940ad'/
  • The new variable atom_git_pull_code_depth will produce a shallow clone, probably the default value could be set to 1 to avoid adding that variable to the playbook?

@mamedin
Copy link
Contributor Author

mamedin commented Aug 13, 2020

I tested the new changes on a client upgrade and it worked properly

  • The revision-dir.yml improves the command shell: "git ls-remote {{ atom_repository_url }} {{ atom_repository_version }} | awk '{print $1}'" where in some cases it created the revision folder with the stdout with two lines eg. 'atom-d6ffd39c150ebe74adb0bc9e7e8d84797ad8def2'$'\n''c017acb60e8dceeb6ec453e368381bf12bc940ad'/
  • The new variable atom_git_pull_code_depth will produce a shallow clone, probably the default value could be set to 1 to avoid adding that variable to the playbook?

@luisilara The omit variable is an ansible special variable:

https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#omitting-parameters

So the default value is depth: null when running the playbook with -vvv option (the same value that you can see when not defining the depth option in task).

And about setting 1 as default value, there's a comment in role about it:

https://github.com/artefactual-labs/ansible-atom/blob/master/tasks/basic.yml#L3-L9

So I prefer to use the old default values for depth and force and change it with extra-vars when is needed.

@djjuhasz djjuhasz removed their request for review August 13, 2020 20:04
@hakamine
Copy link
Member

@mamedin I think the accept_hostkey: "yes" parameter may also be needed in the git task in tasks/revision-dir.yml (currently only the git task in tasks/basic.yml has it). I just did a test and failed there.

@hakamine
Copy link
Member

@mamedin @DavidHume-ArtefactualSystems What do you think about removing the {{ atom_path }}/{{ atom_extra_path }} prefix in the atom_themes path items in defaults/main.yml (i.e., making the paths in atom_themes relative to the AtoM base directory), and instead adding this prefix to the "Build selected AtoM themes" tasks in tasks/build.yml. I think it could make the atom_themes definitions in host_vars simpler.

@mamedin
Copy link
Contributor Author

mamedin commented Aug 14, 2020

@mamedin @DavidHume-ArtefactualSystems What do you think about removing the {{ atom_path }}/{{ atom_extra_path }} prefix in the atom_themes path items in defaults/main.yml (i.e., making the paths in atom_themes relative to the AtoM base directory), and instead adding this prefix to the "Build selected AtoM themes" tasks in tasks/build.yml. I think it could make the atom_themes definitions in host_vars simpler.

Yes, it will be a nice change, but the problem is that we already have 25 config files with the atom_themes dict in deploy-private repo.

We are going to change some other settings on upgrades, so if you agree I can change it.

@mamedin
Copy link
Contributor Author

mamedin commented Aug 14, 2020

I have upgraded again the branch with these changes:

  • The line # Compile available themes in cli_tools.yml has been removed
  • Added accept_hostkey: "yes" to the revision task.

@mamedin mamedin force-pushed the dev/atom-site_enhancements branch from 83c699e to f8cdcc6 Compare August 14, 2020 17:36
@DavidHume-ArtefactualSystems
Copy link
Contributor

DavidHume-ArtefactualSystems commented Aug 14, 2020

@mamedin I think the accept_hostkey: "yes" parameter may also be needed in the git task in tasks/revision-dir.yml (currently only the git task in tasks/basic.yml has it). I just did a test and failed there.

Great catch @hakamine! Thanks @mamedin for latest upgrades.

@hakamine
Copy link
Member

hakamine commented Aug 14, 2020

@mamedin I ran a test for an upgrade (deployed a branch, then did another deploy with a different code commit; strictly speaking it wasn't a branch update but a branch change), and I think I got the same problem that @DavidHume-ArtefactualSystems reported. The first time I tried the upgrade, the "before:" and "after:" commit hashes reported by the git task were the same (old commit). I had to run the playbook again so that the upgrade was completed, this time the git task reported "before:" and "after:" commit hashes were the same but the new commit (I am NOT using depth=1 BTW). So this meaning that in order to do an upgrade would need to run the playbook twice. Could it be a bug in the ansible git module? Could it be better to stick with the old way (using git ls-remote) ?

@mamedin mamedin force-pushed the dev/atom-site_enhancements branch from f8cdcc6 to 0b3961d Compare August 17, 2020 12:40
@mamedin
Copy link
Contributor Author

mamedin commented Aug 17, 2020

@mamedin I ran a test for an upgrade (deployed a branch, then did another deploy with a different code commit; strictly speaking it wasn't a branch update but a branch change), and I think I got the same problem that @DavidHume-ArtefactualSystems reported. The first time I tried the upgrade, the "before:" and "after:" commit hashes reported by the git task were the same (old commit). I had to run the playbook again so that the upgrade was completed, this time the git task reported "before:" and "after:" commit hashes were the same but the new commit (I am NOT using depth=1 BTW). So this meaning that in order to do an upgrade would need to run the playbook twice. Could it be a bug in the ansible git module? Could it be better to stick with the old way (using git ls-remote) ?

Thanks! I could reproduce the issue when using different branches. I could fix it with git module but using 2 different tasks for getting the current and candidate revision. The dest option is optional when using clone=yes, so I tested without the dest option for the candidate tasks and it fixes the issue.

I prefer to use the git module because the git ls-remote tasks requires remote: 127.0.0.1 and sometimes it fails with AWX or when running the ansible playbook in a different server/VM (ssh forwarding issues).

@mamedin
Copy link
Contributor Author

mamedin commented Aug 17, 2020

Thanks again for suggestions :)

Branch updated again. The revision-dir.yml file has changed:

  • Use candidate instead of latest for the revision to be installed. (Cosmetic)
  • Use separate tasks to get the candidate and current revisions.

Miguel Angel added 4 commits August 18, 2020 21:36
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
```
New tasks have been added to create a symlink to a custom `downloads`
directory in the same way we do for custom `upload` directories.

The old uploads-dir tasks have been moved to symlink-dirs.yml task file.
Ensure `atom_uploads_symlink` and `atom_downloads_symlink` exist to avoid the
following error when running the "Temporarily change ownership of site
directory to be able to clone repo" task (and directory doesn't exist):

```
"Errno 2] No such file or directory: '/usr/share/nginx/atom-uploads'"
```
Create a symlink for digital object access control from `$atom_path/private` to
`$atom_path/$atom_revision_directory_latest_symlink_dir` when
`atom_private_symlink` and `atom_revision_directory` are `true`.
@mamedin mamedin force-pushed the dev/atom-site_enhancements branch from 0b3961d to 95a93a3 Compare August 18, 2020 19:36
@mamedin mamedin force-pushed the dev/atom-site_enhancements branch from 95a93a3 to cac3ec8 Compare August 27, 2020 18:53
Miguel Angel added 3 commits August 27, 2020 21:17
The new task file includes the following commands:

  - rebuild index
  - Update database
  - fix data: Rebuild nested-set and generate slugs
  - Compile all available themes

The `search.yml` task file has been removed, and the "Update database" task has
been moved to the new cli tasks file.
@mamedin mamedin force-pushed the dev/atom-site_enhancements branch from cac3ec8 to 1f0277e Compare August 27, 2020 19:17
@mamedin mamedin merged commit 9dcd974 into master Aug 28, 2020
@mamedin mamedin deleted the dev/atom-site_enhancements branch August 28, 2020 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants