Deploy to development?

Hi,

I included a wp-config.yml task file with some wp-cli commands for activating plugins, adding widgets etc… to the finalize_after deploy hook. Now I want to these tasks to be also run on the development machine. how can i achieve this?

./deploy.sh development site doesn’t work…

You don’t deploy to local dev, only remote servers.

Thanks for the prompt answer @benword. But that doesn’t actually help me with my concern to define and execute some tasks that install and configure the site.

Where should I pack the tasks, that

  • activate the plugins I installed with composer,
  • creates the sidebars and menus I need for the site to work,
  • creates and places all widgets I need

So where do I put these tasks, so that not only staging and production envs get deployed, but the development environment get initialized equally for every developer in my team?

Thanks again for your help!

To begin with I would look at your Vagrantfile and from there maybe dev.yml or something.

There is no database migration type stuff in Trellis by default. The more I use a framework like Laravel with proper database migrations and seeders, the more I want to see it in WordPress. However, things like that just don’t generally exist yet.

Since there is no actual way to sync databases by default with Trellis, you do have to figure out a way to handle it. Some people use shell scripts, many are fans of WP Migrate DB Pro, where you could make updates to some type of dev/staging server and developers could pull the database from there.

There’s also https://github.com/danielbachhuber/dictator, which may be able to handle the tasks you are looking to have synced, and keep it in version control. I haven’t tried it in a while though, so I can’t say for sure.

1 Like

Wouldn’t it be easier to run his Wordpress config as a task?

Also why wouldn’t you just use WP-CLI if you wanted to push/pull dB’s instead?

What am I missing?

I’m actually not sure which way to go.

I could try to keep track of all the config changes with wp-cli and collect all changes into a task file and execute it with dev and deploy playbooks. Not sure if all config changes can be described this way.

Alternatively I could work with something like WP DB Migrate Pro and save config changes in an export file. Not sure which tables to export…

The dictator doesn’t describe all possible changes completly enough, i think.

But the original question of mine in this forum here was:
How can i achieve that a taskfile installed like deploy hooks gets executed by dev and deploy playbooks (and receives the correct vars)?

Thanks again for your help!

And the original answer is that Trellis doesn’t “deploy” to dev.

It sounds like you’re looking for something similar to the old Roots theme activation that can be handled via PHP or WP-CLI. It’s up to you to determine how to implement that.

I agree with Ben that Trellis doesn’t “deploy” to development (and it probably shouldn’t). But if you want to leave out the concept “deploy,” here are a couple possibilities (among many) for having Trellis run extra tasks on all environments, including development.

If your tasks should run every time (with dev.yml and deploy.yml), for staging and production you could set them up using deploy hooks, as you’ve mentioned. For development, you could modify the Trellis core file wordpress-install/tasks/main.yml and add the following include after the WordPress install.

- include: deploy-hooks/my-tasks.yml

Now those tasks will run every time dev.yml runs via vagrant up or vagrant provision. You’ll need to have set up your tasks to be idempotent so they can safely run every time.

Alternatively, you could just create a new role my-role and add it to the end of dev.yml and deploy.yml.

If you will run your tasks only occasionally you could make a playbook my-playbook.yml and add your tasks as a tasks list, role or includes. You could then run your playbook whenever you want, for example:

ansible-playbook my-playbook.yml -i hosts/production

Note that for the command to work on development, you must add some info to your ~/.ssh/config file. Assuming your hosts/development still has 127.0.0.1, run the following command:

vagrant ssh-config --host 127.0.0.1

Now add the output info to the end of your ~/.ssh/config. You could automate this ssh config setup for dev using the idea in roots/trellis#314.

Now you can run the tasks on dev with the following command:

ansible-playbook my-playbook.yml -i hosts/development

The first option above has the advantage that you don’t have to run any extra commands. The second option does require an extra command, but has the advantage of keeping your custom tasks/edits more separated from Trellis core files.

1 Like