Roots Discourse

Whats requirements for the first deploy?

Provisioning the server works fine.

My issue starts when doing the first ever deploy.

My brand new github repo is empty except for readme files.

I would really like to know what is the requirements, should the github repo contain bedrock already?

When running

ansible-playbook deploy.yml -e "site=staging.reshape.nu env=staging" -i hosts/staging

I get this

PLAY [Ensure necessary variables are defined] **********************************************************************************************************************

TASK [Ensure environment is defined] *******************************************************************************************************************************
skipping: [localhost]

PLAY [Test Connection] *********************************************************************************************************************************************

TASK [connection : Require manual definition of remote-user] *******************************************************************************************************
skipping: [35.228.230.145]

TASK [connection : Specify preferred HostKeyAlgorithms for unknown hosts] ******************************************************************************************
skipping: [35.228.230.145]

TASK [connection : Check whether Ansible can connect as web] *******************************************************************************************************
ok: [35.228.230.145 -> localhost]

TASK [connection : Warn about change in host keys] *****************************************************************************************************************
skipping: [35.228.230.145]

TASK [connection : Set remote user for each host] ******************************************************************************************************************
skipping: [35.228.230.145]

TASK [connection : Announce which user was selected] ***************************************************************************************************************
skipping: [35.228.230.145]

TASK [connection : Load become password] ***************************************************************************************************************************
skipping: [35.228.230.145]

PLAY [Deploy WP site] **********************************************************************************************************************************************

TASK [Gathering Facts] *********************************************************************************************************************************************
ok: [35.228.230.145]

TASK [Ensure site is valid] ****************************************************************************************************************************************
skipping: [35.228.230.145]

TASK [Ensure repo is valid] ****************************************************************************************************************************************
skipping: [35.228.230.145]

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : Initialize] *****************************************************************************************************************************************
ok: [35.228.230.145]

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : Add known_hosts] ************************************************************************************************************************************
ok: [35.228.230.145] => (item=github.com ssh-rsa NOT SHOWING MY ID_RSA FOR.... REASONS =) )

TASK [deploy : Clone project files] ********************************************************************************************************************************
ok: [35.228.230.145]

TASK [deploy : Remove untracked files from project folder] *********************************************************************************************************
ok: [35.228.230.145]

TASK [deploy : Failed connection to remote repo] *******************************************************************************************************************
skipping: [35.228.230.145]

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : Check for project repo subtree] *********************************************************************************************************************
skipping: [35.228.230.145]

TASK [deploy : Fail if repo_subtree_path is set incorrectly] *******************************************************************************************************
skipping: [35.228.230.145]

TASK [deploy : Create new release dir] *****************************************************************************************************************************
changed: [35.228.230.145]

TASK [deploy : Run git archive to populate new build dir] **********************************************************************************************************
changed: [35.228.230.145]

TASK [deploy : Run git archive with subdirectory to populate new build dir] ****************************************************************************************
skipping: [35.228.230.145]

TASK [deploy : write unfinished file] ******************************************************************************************************************************
changed: [35.228.230.145]

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : include_tasks] **************************************************************************************************************************************

TASK [deploy : Copy project templates] *****************************************************************************************************************************
changed: [35.228.230.145] => (item={u'dest': u'.env', u'src': u'roles/deploy/templates/env.j2', u'name': u'.env config'})

TASK [deploy : Check if project folders exist] *********************************************************************************************************************
ok: [35.228.230.145] => (item=vendor)

TASK [deploy : Copy project folders] *******************************************************************************************************************************
skipping: [35.228.230.145] => (item={'failed': False, u'stat': {u'exists': False}, 'ansible_loop_var': u'item', 'item': u'vendor', u'invocation': {u'module_args': {u'follow': False, u'get_checksum': True, u'path': u'/srv/www/staging.reshape.nu/current/vendor', u'checksum_algorithm': u'sha1', u'get_md5': None, u'get_mime': True, u'get_attributes': True}}, u'changed': False}) 

TASK [deploy : include_tasks] **************************************************************************************************************************************
included: /Users/danadalis/Roots/reshape.nu/trellis/roles/deploy/hooks/build-after.yml for 35.228.230.145

TASK [deploy : Check for composer.json in project root or project_subtree_path] ************************************************************************************
ok: [35.228.230.145]

TASK [deploy : Fail if composer.json not found] ********************************************************************************************************************
System info:
  Ansible 2.8.4; Darwin
  Trellis Head
---------------------------------------------------
Unable to find a `composer.json` file in the root of
'/srv/www/staging.reshape.nu/releases/20200212191739'. Make sure your repo
has a `composer.json` file in its root or edit `repo_subtree_path` for
'staging.reshape.nu' in `wordpress_sites.yml` so it points to the directory
with a `composer.json` file.
fatal: [35.228.230.145]: FAILED! => {"changed": false}

PLAY RECAP *********************************************************************************************************************************************************
35.228.230.145             : ok=13   changed=4    unreachable=0    failed=1    skipped=20   rescued=0    ignored=0   
localhost                  : ok=0    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

danadalis@Daniels-MacBook-Pro-2 trellis %

Ansible provides pretty helpful error messages. In your case it threw this one:

TASK [deploy : Check for composer.json in project root or project_subtree_path] ************************************************************************************
ok: [35.228.230.145]

TASK [deploy : Fail if composer.json not found] ********************************************************************************************************************
System info:
  Ansible 2.8.4; Darwin
  Trellis Head
---------------------------------------------------
Unable to find a `composer.json` file in the root of
'/srv/www/staging.reshape.nu/releases/20200212191739'. Make sure your repo
has a `composer.json` file in its root or edit `repo_subtree_path` for
'staging.reshape.nu' in `wordpress_sites.yml` so it points to the directory
with a `composer.json` file.
fatal: [35.228.230.145]: FAILED! => {"changed": false}

This particular line tells you why the deploy failed:

TASK [deploy : Fail if composer.json not found]

Your repo doesn’t have a composer.json, which Trellis expects, so the deploy fails.

Trellis as configured by default expects you at the very least to be deploying a valid Bedrock install. It will do a number of things (i.e. attempt to install dependencies from a composer.json) based on that expectation, so you will need at least that much. The example repo should give you a pretty good idea of what a minimally configured full Roots stack project looks like.

Ok, but does this mean i need bedrock in my github repo before first deploy?

Yes. It’s deploying the repo, not your local files.

1 Like

Trellis expects Bedrock at this time of writing. There are efforts to make trellis App-agnostic.

1 Like

Ok… now i’m starting to get confused. I’ve always been under the impression that the workflow of trellis is
develop in local - push to stage - push from stage to prod.

Could you please explain to me, like i’m a 5 yr old =)

There are basically two parts to a site:

  • The “App” - This is all of the files (the theme, Dedrock, etc). Everything that’s part of the app is stored in a git repo and tracked.
  • The Content - This is all of the content (i.e. images, database, etc). This is not stored in the git repo.

When Trellis runs a deploy, it is deploying a new version of the App. It does not do anything with the Content; it’s up to you to move that around as appropriate.

You’re correct that our recommended system is to develop locally. That means you have a version of the App running in a virtual machine on your local machine (Trellis will do this for you). You deploy your changes to the App to a staging server with Trellis. Once you’re satisfied that those changes are good, you deploy them to the production server.

When you run a deploy, Trellis connects to your remote server via SSH, clones your git repo to that server, and then runs a bunch of tasks on the remote server to set up the deploy and switch to it with zero downtime. It is not pushing files up from your local machine to the remote server (although there is an exception: If you’re using the Sage build process and have un-commented the relevant sections of the build-before deploy hook in Trellis, it will build your assets locally and then push them to the remote server).

This whole process is built around the idea of the “12-Factor App”, which you can read about here (and I recommend you do; it will illuminate a lot of why Roots does the things it does): https://roots.io/twelve-factor-wordpress/

2 Likes