welaika / wordmove

Multi-stage command line deploy/mirroring and task runner for Wordpress
https://wptools.it/wordmove
MIT License
1.87k stars 165 forks source link

Enable / disable hook via .env #623

Closed martin-josef closed 2 years ago

martin-josef commented 2 years ago

Is your feature request related to a problem? Please describe.

I use one movefile.yml for all kinds of hosts and specify the details in a .env-file. Hooks however I only run on DigitalOcean, not, for example, on Kinsta.

Describe the solution you'd like Is there a way to enable / disable hooks via .env to be able to keep them as part of my general movefile?

Describe alternatives you've considered Using separate movefiles, which is perfectly fine.

These are the hooks I use, at this point only related to ownership / permissions.

  hooks:
    push:
      after:
        - command: 'sudo chown -R www-data:www-data .'
          where: remote
        - command: 'sudo find -type d -exec chmod 750 {} \;'
          where: remote
        - command: 'sudo find -type f -exec chmod 640 {} \;'
          where: remote
alessandro-fazzi commented 2 years ago

Hello @martin-josef ,

I've studied a bit around this one, and this is what should be possible to achive:

global:
  sql_adapter: 'wpcli'
  <% if ENV.fetch('FOO', nil) %>
  foo: &foo
    - where: remote
      command: 'ls -la && pwd'
      raise: true
  <% else %>
  foo: &foo
  <% end %>

local:
  vhost: "http://localhost:8080"
  wordpress_path: "<%= ENV['WORDPRESS_WORKS_PATH'] %>/sshwordmove" # use an absolute path here

  database:
    name: "sshwordmove"
    user: "root"
    password: ""
    host: "localhost"

production:
  vhost: "http://xxx.welaika.com"
  wordpress_path: "/home/sshwordmove/xxx.welaika.com" # use an absolute path here

  database:
    name: "xxx"
    user: "xxx"
    password: "xxx"
    host: "xxx"

  exclude:
    # [...]

  ssh:
    host: "xxx.welaika.com"
    user: "sshwordmove"
    rsync_options: "--verbose"

  hooks:
    pull:
      after: *foo

  forbid:
    push:
      languages: true

This way you should be able to put

FOO=1

into you .env or directly

FOO=1 wordmove pull -l

The countereffect is that wordmove doctor will report

▬▬ Validating movefile section: global ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬

    ❌  error | [/foo] key 'foo:' is undefined.

But it seems an acceptable one to me.

martin-josef commented 2 years ago

This is much appreciated, thanks! Interesting approach, I will play with it a bit.

alessandro-fazzi commented 2 years ago

Oh well... "keep it simple stupid" approach could even be better @martin-josef

  hooks:
    pull:
      after:
        <% if ENV.fetch('FOO', nil) %>
        - where: remote
          command: 'ls -la && pwd'
          raise: true
        <% end %>
alessandro-fazzi commented 2 years ago

I wrote a new wiki section in order to document this trick https://github.com/welaika/wordmove/wiki/YAML-tips#conditionally-composing-movefileyml