ansistrano / deploy

Ansible role to deploy scripting applications like PHP, Python, Ruby, etc. in a capistrano style
https://ansistrano.com
MIT License
2.37k stars 343 forks source link

Current and version dir cannot different paths structures. #332

Closed AjkP closed 3 years ago

AjkP commented 5 years ago

This seems like a bug to me, but it might also be a feature request?

Basically what Im trying to do:

ansistrano_deploy_to: "/var/www" # Base path to deploy to.
ansistrano_version_dir: "releases" # Releases folder name
ansistrano_current_dir: "foo/bar" # Softlink name. You should rarely changed it.
ansistrano_current_via: "symlink"

During the:

TASK [ansistrano.deploy : ANSISTRANO | Change softlink to new release] 

I get a failure since it's somehow assumed that they're both going to have the shared base folder.

I can make a quick pull request if someone thinks it's reasonable to change in deploy/tasks/symlink.yml:

FROM

- name: ANSISTRANO | Change softlink to new release
  file:
    state: link
    path: "{{ ansistrano_deploy_to }}/{{ ansistrano_current_dir }}"
    src: "./{{ ansistrano_version_dir }}/{{ ansistrano_release_version }}"

TO

- name: ANSISTRANO | Change softlink to new release
  file:
    state: link
    path: "{{ ansistrano_deploy_to }}/{{ ansistrano_current_dir }}"
    src: "{{ ansistrano_deploy_to }}/{{ ansistrano_version_dir }}/{{ ansistrano_release_version }}"
ricardclau commented 5 years ago

Does this change make any difference at all? Maybe I am missing something but I think you will end up with the same result

And yes, being all under the same parent path is by design. In order to be able to have the current folder in a completely different location you would need an extra variable like {{ ansistrano_full_path_to_current_code }}

Does it provide any benefit at all?

AjkP commented 5 years ago

Does this change make any difference at all? Maybe I am missing something but I think you will end up with the same result

They won't have the same result. With the example above:

ansistrano_deploy_to: "/var/www"
ansistrano_version_dir: "releases"
ansistrano_current_dir: "foo/bar

Actual: Symlink /var/www/foo/bar from /var/www/foo/releases.

Expected: Symlink /var/www/foo/bar from /var/www/releases.

After my proposed change the expected would correctly happen.


Does it provide any benefit at all?

Yes. There's many scenarios where you could want to deploy a "sub folder" of a system.

Example above. My app could start at /var/www/foo but I want to deploy /var/www/foo/bar separately. I don't want to keep the releases within my app (inside /var/www/foo/releases (and have some risk that they will be accessed by third party or interfere with my development. I want to keep the releases in some separate folder under /var/www/foo_releases or something similar, that noone has access to.

ricardclau commented 5 years ago

If security is your concern, you need to make sure your app cannot access those folders and your web server is properly configured. That has nothing to do with ansistrano or any deployment tool and it can happen no matter where you put the releases files if any of them are wrongly configured.

And you could always deploy to /opt/your_app and symlink /var/www/app to /opt/your_app/current in a post deployment hook if that gives you extra confidence about other releases folders not being accidentally exposed

Also, some discussion around this from years ago at https://github.com/ansistrano/deploy/issues/92 as such change can break some existing behaviors which are arguably edge cases but so is yours. And IMHO it does not justify introducing potentially breaking changes for your reasoning

I will have a look though as anyway, specifying a 2 folder structure should provide your expected result

AjkP commented 5 years ago

I have worked around this, but I genuinely thought this was a bug when I first saw it (and still sort of do).


Here's another example where you'd get in a really weird place:

ansistrano_deploy_to: "/var/www"
ansistrano_version_dir: "foo/releases"
ansistrano_current_dir: "foo/bar

Now your version dir is /var/www/foo/foo/releases


It being a breaking change does kind of suck. Another option could be to just disallow nested dirs in those configs if there's other edge cases you wouldn't wanna deal with.

ricardclau commented 3 years ago

Closing as we will not be fixing this any time soon