Deploying content from a staging server to the live site is important: that’s the first thing you learn when you actually start using a Drupal site with any significant traffic, that editing a live site with traffic is hopeless. A couple days ago I showed a simple example with two brand new sites (one staging, one in the role of “live”), installing the deployment module in order to have node operations and references carried out on the basis of a once-in-a-lifetime-assigned UUID rather than its arbitrary node id (the arbitrary nid assigned if you say export and import nodes using the otherwise excellent Node Export module). But what if you now realize that you need this after the site has already entered production? This article reports back upon attempting to do this with the literary workshop example published in my book, Leveraging Drupal.
Getting your staging site deployment ready
The staging site is a brought-up-to-date and slightly enhanced version of my old literary workshop app. Let’s analyze the front page:
Literary Workshop Staging site front page
We have a nodereference implemented one to many relationship between literary piece and magazine. We wish to deploy the content types, the taxonomy, the content (actual literary pieces by actual users, actual taxonomy) and some views also, such that the nodereferences will not be broken in spite of all the nodes having very different nid’s on the live site than they do on this staging site.
First we’ll set up deployment, then we’ll create a deployment plan including all this stuff.
Install the modules required for the content
- cck
- date/time
- global redirect
- pathauto
- token
- tagadelic
- views
Install the modules required for deployment
- deploy
- services
Enable the following modules
- Content: all of content except Content permissions
- Date
- Date
- Date API
- Date Timezone
- Date Tools
- Deploy
- Deploy Content Type
- Deploy Dates
- Deploy Nodereferences
- Deploy System Settings
- Deploy Views
- Deployment
- Node Deployment
- Taxonomy Deployment
- User Deployment
- UUID
- Pathauto
- Token
- Services
- Services
- Key Authentication
- UUID Service
- Views
Add a live server
I went to /admin/build/deploy/servers and clicked on Add a new server. I entered “Live Literary Workshop Server” in the Name field, http://deploydest.example.com/services/xmlrpc in the URL field, left “Session id” selected in the Authentication type field and clicked the Save Deployment Server button.
Create a deployment plan
I went to Administer > Site building > Deployment and clicked on Add a new deployment plan. In the Name field, I entered “LitDose”, added an optional description and clicked on the Save Deployment Plan button.
I went to Administer > Site configuration > Performance and hit the Clear cache data button.
Configure Services authentication for session id
I went to Administer > Site building > Services > Settings and selected Key authentication in theAuthentication module field. In the check boxes that opened up as a result I de-selected Use keys and left Use sessid selected, and clicked on the Save settings button.
Add stuff to the deployment plan
- Nodes: I went to Administer > Content management > Content. I filtered for the Literary Piece content type, and selected all nodes. I then selected Add to deployment plan from the Update options drop down list and clicked on the Update button. I left the “LitDose” deployment plan selected and hit the Submit button. I was greeted with a list of the items attached to the deployment plan so far. I didn’t select the Magazine node, since this should be deployed automatically since it is invoked in several of the selected literary piece nodes (see Advanced uses of deploy handbook page).
- Content types: I went to Administer > Content management > Content types. I clicked on the Deploy tab. Leaving the deployment plan LitDose selected, I selected Literary Piece and Magazine from the list in the Content type field. I clicked the Add Content Type button. The two content types were placed at the top of the deployment plan items list.
- Views: I went to Administer > Site building > Views and clicked on the Deploy tab. Leaving the deployment plan LitDose selected, I selected the views genre_browser and magazine_browser and clicked the Add to deployment plan button. The views were cleverly placed under the content type items in the deployment plan items list.
- Taxonomy: I went to Administer > Content management > Taxonomy and hit the Deploy tab. But I saw a different setup, one designed to deploy right away invoking the live server and pushing the deployment plan right now. I did nothing here, crossing my fingers that the taxonomy items would be pushed by virtue of being dependencies. Deploy Taxonomy is enabled, so it should get sent as a dependency.
- Users: nothing there either… Deploy Users is enabled, so they should get sent as dependencies.
Getting your live site deployment ready
This site, initially, is a copy of the staging site with no content in it, no content types, no views, no taxonomy terms,, and no services or deployment modules either installed or enabled. Its pathetic front page:
Pathetic front page of empty literary workshop live site
Configuration in order to be ready to receive a “pushing” of the LitDose deployment plan from the staging server:
Install the modules required for the content
- cck
- date/time
- global redirect
- pathauto
- token
- tagadelic
- views
Install the modules required for deployment
- deploy
- services
Enable the following modules
- Content: all of content except Content permissions
- Date
- Date
- Date API
- Date Timezone
- Date Tools
- Deployment: UUID
- Pathauto
- Token
- Services
- Services
- Key Authentication
- XMLRPC Server
- Content Copy Service
- Node Service
- System Service (for remote login!)
- Taxonomy Service
- User Service
- UUID Service
- Views Service
- Views
Configure Services authentication for session id
I went to Administer > Site building > Services > Settings and selected Key authentication in the Authentication module field. In the check boxes that opened up as a result I de-selected Use keys and left Use sessid selected, and clicked on the Save settings button.
Doing it!
After saving the state of both sites, I went to the source site and did the following:
- I went to Administer > Site building > Deployment.
- I clicked on the push link associated with the LitDose deployment plan.
- In the Server field I selected the Live Literary Workshop Server.
- I supplied the user name and password.
- I clicked on the Push Deployment Plan button.
Comments on the experience
- Dependencies were very cleverly determined: content types, then views, then taxonomy vocabularies, then taxonomy terms, then users, then nodes (first the “parent” node referenced via nodereference fields, automatically included, then the other nodes).
- I had to use user #1 (the first user created with full permissions) since even a user given all permissions would be reject with an access denied error upon attempting to push content types.
- I had to turn off the Deploy user module on the source server, since it would create a fatal error if the user already existed on the destination server (“The name xxx is already taken. The e-mail address xxx@xxx.xxx is already registered….”); so deploy to get the users deployed once, then turn off the module.
- The nodereference pointers worked great and didn’t break even though the nids were different. This is the main thing! This is what we are seeking above all.
- The views had a problem, even though they were working fine and weren’t in the process of being edited on the source server, they wouldn’t work on the destination server right off the bat (not listing any found items) and upon being editing had an error message “This view is being edited by user admin, and is therefore locked from editing by others. This lock is 37 min 8 sec old. Click here to break this lock.” Then, upon trying to see the Live preview in the Views UI, the error “An invalid vocabulary is selected. Please change it in the options.” appeared. Simply editing, confirming the selected vocabulary and saving the field and the view fixed everything (so the nodes transferred the vocabulary ok).
And… success!
Without any nodes being edited (only the views touched up, and they would probably be deployed via source control or as part of a feature, anyway), the literary pieces know they are part of a given magazine issue. Usable deployment has been achieved for this architecture. The front page has been restored:
Front page of live server has content restored via deploy module