DesignProjectX

Journal

2009-07-05

Symphony Extensions and Git Submodules

Posted 2009-07-05 in Technology | XSL | XML | Text

I am in the process of evaluating some of the available Symphony CMS extensions and have been experimenting with including extensions as submodules in Symphony ensemble repositories. This is a list of the commands used to set up additional submodules for a clean Symphony install.

Install Symphony from GitHub

On my Mac, I open a Terminal window and issue the following commands:

                      cd Sites/sym
git clone git://github.com/symphony/symphony-2.git
mv symphony-2 site
cd site
git submodule init
git submodule update
chmod 777 . symphony

                    

I have a virtual host set up for my Sites directory so that instead of find the Sites directory here:

                      http://localhost/~stephen/

                    

I can find it here:

                      http://home/

                    

I create a MySQL database called sym_site and install by navigating to:

                      http://home/sym/site/

                    

I add my server configuration and user settings and Symphony is installed.

Set Up the GitHub Repository

I create a new repository on GitHub called sym-site. Since I have cloned my local repository from the official Symphony symphony-2 repository on GitHub, my local repository has the following configuration in ~/Sites/sym/site/.git/config:

                      [core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = git://github.com/symphony/symphony-2.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[submodule "extensions/debugdevkit"]
    url = git://github.com/symphony/debugdevkit.git
[submodule "extensions/export_ensemble"]
    url = git://github.com/pointybeard/export_ensemble.git
[submodule "extensions/jit_image_manipulation"]
    url = git://github.com/pointybeard/jit_image_manipulation.git
[submodule "extensions/maintenance_mode"]
    url = git://github.com/pointybeard/maintenance_mode.git
[submodule "extensions/markdown"]
    url = git://github.com/pointybeard/markdown.git
[submodule "extensions/profiledevkit"]
    url = git://github.com/symphony/profiledevkit.git
[submodule "extensions/selectbox_link_field"]
    url = git://github.com/pointybeard/selectbox_link_field.git

                    

I manually modify the file to point to my new repository on GitHub:

                      [remote "origin"]
    url = git@github.com:bauhouse/sym-site.git
    fetch = +refs/heads/*:refs/remotes/origin/*

                    

Then, I push the repository to GitHub:

                      git push origin master

                    

Install Symphony Extensions from GitHub

The first step is to add some extensions. I’ll do this by adding submodules with Git:

                      git submodule add git://github.com/rowan-lewis/activitylog.git extensions/activitylog
git submodule add git://github.com/pointybeard/asdc.git extensions/asdc
git submodule add git://github.com/pointybeard/content_type_mappings.git extensions/content_type_mappings
git submodule add git://github.com/yourheropaul/databasemanipulator.git extensions/databasemanipulator
git submodule add git://github.com/makenosound/dynamic_event_redirect.git extensions/dynamic_event_redirect
git submodule add git://github.com/czheng/enhancedtaglist.git extensions/enhancedtaglist
git submodule add git://github.com/nickdunn/entity_diagram.git extensions/entity_diagram
git submodule add git://github.com/yourheropaul/eventex.git extensions/eventex
git submodule add git://github.com/carsten/globalparamloader.git extensions/globalparamloader
git submodule add git://github.com/rowan-lewis/globalresourceloader.git extensions/globalresourceloader
git submodule add git://github.com/ahwayakchih/markitup.git extensions/markitup
git submodule add git://github.com/Demwunz/multiselect_to_checkboxes.git extensions/multiselect_to_checkboxes
git submodule add git://github.com/pointybeard/numberfield.git extensions/numberfield
git submodule add git://github.com/nickdunn/order_entries.git extensions/order_entries
git submodule add git://github.com/pointybeard/pagesfield.git extensions/pagesfield
git submodule add git://github.com/nickdunn/publishfiltering.git extensions/publishfiltering
git submodule add git://github.com/czheng/referencelink.git extensions/referencelink
git submodule add git://github.com/rowan-lewis/reflectionfield.git extensions/reflectionfield
git submodule add git://github.com/nickdunn/section_schemas.git extensions/section_schemas

                    

Committing the Changes to GitHub

To keep Git from including the manifest directory and the install-log.txt file in the repository, I modify the .gitignore file:

                      .Apple*
.DS_Store
*config.php
.htaccess
symphony/.htaccess
workspace/
manifest
install-log.txt

                    

Add the update files to be staged for committing to the repository:

                      git add -u

                    

Check the status before committing

                      git status

                    

Commit the changes to the repository

                      git commit -m "Add additional extensions as submodules"

                    

Push the changes to GitHub

                      git push origin master

                    

Committing Changes to the Database

I don’t want to store sessions, server configuration or user authentication information in the GitHub repository. The Symphony Export Ensemble extension removes this information and creates an install.php file with the SQL statements required to reinstall a copy of the site, encoded as base64.

I tried to create an ensemble with all the extensions I had added as submodules. This caused an fopen error, stating there were too many files open. I discovered that this had to do with limits imposed by the PHP function for the number of files that needed to be included in the ZIP archive. The problem was solved by uninstalling all extensions except the Export Ensemble extension, renaming the extensions folder to _extensions and creating another extensions folder with only the Export Ensemble extension. Then, I was able to export the ensemble successfully.

                      Fatal error: Uncaught exception 'RuntimeException' with message 'fopen(/Users/stephen/Sites/sym/site/manifest/logs/main) [<a href='function.fopen'>function.fopen</a>]: failed to open stream: Too many open files' in /Users/stephen/Sites/sym/site/symphony/lib/core/class.log.php:93 Stack trace: #0 /Users/stephen/Sites/sym/site/symphony/lib/core/class.log.php(93): fopen('/Users/stephen/...', 'a') #1 /Users/stephen/Sites/sym/site/symphony/lib/core/class.log.php(80): Log->writeToLog('09:15:32 > WARN...', true) #2 /Users/stephen/Sites/sym/site/symphony/lib/core/class.symphony.php(290): Log->pushToLog('2 - DirectoryIt...', 1, true) #3 [internal function]: Symphony->__errorHandler(2, 'DirectoryIterat...', '/Users/stephen/...', 37, Array) #4 /Users/stephen/Sites/sym/site/extensions/export_ensemble/extension.driver.php(37): DirectoryIterator->__construct('/Users/stephen/...') #5 /Users/stephen/Sites/sym/site/extensions/export_ensemble/extension.driver.php(42): extension_export_ensemble->__addFolderToArchive(Object(ZipArchive), '/Use in /Users/stephen/Sites/sym/site/symphony/lib/core/class.log.php on line 93

                    

Hmm. Not sure how to avoid this issue. Go to plan B: include only the extensions that I need.

Creating a Production Branch

I wanted to deploy the test site to a production server to see if I encountered similar issues. Joyent Shared Accelerators provide SSH access and Git is installed, so I might as well try out using Git on Joyent to deploy a site to a production server. One issue with this is that the install.php and update.php files need to be removed as soon as Symphony has been installed. However, I want to keep these files in the master branch of the repository so that I can still install from a copy of the repository. So, I’ve created a production repository that omits the install.php and update.php files.

Set Up the Repository to Push to GitHub

I needed to generate SSH keys and provide my SSH public key to GitHub to be able to push changes from my Joyent Accelerator account. First, configure the Global Git Config on Joyent:

                      git config --global user.name "username"
git config --global user.name username@example.com
git config --global github.user bauhouse
git config --global github.token {GitHub API Token}

                    

Generate a public/private dsa key pair

                      ssh-keygen -t dsa

                    

Copy the public key to GitHub. Copy the Terminal output from this command:

                      cat id_dsa.pub

                    

And add this public key to the GitHub account as an SSH public key.

An Issue with Git on Joyent

Everything was working fine with Git on Joyent until I tried to commit. Every time I tried to commit, I received the following error:

                      Duplicate Signed-off-by lines.

                    

Google was my friend. I found others had come up against this issue as well. Thanks to Will Norris for the solution. This helped me git going again on Joyent’s Shared Accelerators once I realized I needed to modify the first line of the .git/hooks/commit-msg file in my repository from this:

                      #!/bin/sh

                    

to this:

                      #!/usr/bin/bash

                    

Now, commits work as expected and I can push my changes to the production branch to GitHub from Joyent. First, I can change the name of the master branch to production:

                      git branch -m master production

                    

Then push the changes to GitHub:

                      git push origin production

                    

Now, any changes I make locally can be merged into the production branch, pushed to GitHub, then pulled into the production site. Deploying to a production server while using version control couldn’t be any easier. A local branch can be used as a repository for a MySQL dump file to ensure that database changes are also reflected for each commit. This should probably remain private, so as to avoid any mistakes that post sensitive data to a public repository.

Git on Windows

I ran into an issue where Git was changing end of line characters and files were modified in the process of cloning a repository. Issuing a git status command would return a list of changed files as soon as the files were cloned. This made it impossible to working on the repositories unless I committed the changed files. It didn’t make sense to commit files where the only changes consisted of end of line characters. Line feeds (LF) and carriage returns (CR) were being changed to carriage returns plus line feeds (CRLF). It turns out there is a fix: to change the Git configuration file:

                      git config core.autocrlf false

                    

This will ensure that Git ignores end of line characters, leaving them as they are.

DesignProjectX | The digital sandbox of Stephen Bau