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

Symfony app deployment: shared files #346

Closed plashenkov closed 4 years ago

plashenkov commented 4 years ago

Hi!

I have been trying to make a deployment of Symfony app, and I need to add these shared items:

I get the following error message on deploy:

TASK [ansistrano.deploy : ANSISTRANO | Create softlinks for shared paths and files] *******
failed: {
    "msg": "src file does not exist, use force=yes if you really want to create the link: /path/to/app/releases/20200222010404Z/var/../../../shared/var/log", 
    "path": "/path/to/app/releases/20200222010404Z/var/log",
    "src": "../../../shared/var/log"
}
failed: {
    "msg": "src file does not exist, use force=yes if you really want to create the link: /path/to/app/releases/20200222010404Z/var/../../../shared/var/sessions",
    "path": "/path/to/app/releases/20200222010404Z/var/sessions",
    "src": "../../../shared/var/sessions"}
}
failed: {
    "msg": "src file does not exist, use force=yes if you really want to create the link: /path/to/app/releases/20200222010404Z/../../shared/.env.local",
    "path": "/path/to/app/releases/20200222010404Z/.env.local",
    "src": "../../shared/.env.local"}
}
failed: {
    "msg": "src file does not exist, use force=yes if you really want to create the link: /path/to/app/releases/20200222010404Z/../../shared/.env.local.php",
    "path": "/path/to/app/releases/20200222010404Z/.env.local.php",
    "src": "../../shared/.env.local.php"}
}

Yes, I have already viewed the similar issue: https://github.com/ansistrano/deploy/issues/275 and have seen the suggestion to create a hook to ensure the var folder exists inside shared.

But the problem is not the var folder doesn't exist inside shared (I can clearly see that var/log and var/sessions folders are inside shared). The problem is the var folder doesn't exist inside {{ ansistrano_release_path.stdout }}.

Okay... I've created a task file (ansistrano_before_symlink_shared_tasks_file) which creates the var folder inside {{ ansistrano_release_path.stdout }} manually. And now it works!

But now files: .env.local and .env.local.php. Especially the last one (.env.local.php): it shouldn't exist — it will be generated later, but now I need just a softlink to it even if it currently doesn't exist. I do not see a clear way to beautifully workaround this.

And the main question: why not just use force: yes here: https://github.com/ansistrano/deploy/blob/master/tasks/symlink-shared.yml#L16? It looks like it would solve all the problems.

ricardclau commented 4 years ago

Using force: yes will cause all sorts of other problems and undesired side effects if something exists there and ansistrano deletes it with a bad configuration

As you point out, you can for instance easily create the var folder with a .gitkeep file in your repo or as part of your before / after setup hooks. As for .env.local files they should be provided with other ways (either provision it or download it from somewhere as part of your provisioning / deployment) or create a symlink as you say

Closing as this is not an ansistrano issue but something specific to Symfony that can be solved easily without causing undesired side effects in other setups

plashenkov commented 4 years ago

Thank you, you are right. Already configured everything and all is great, thank you.