douyou2234 2013-07-02 08:49
浏览 33
已采纳

带钩子,迁移和bash的版本控制

I'm trying to find a fine solution for migration control betweem local wamp and server lamp involving git and Drupal.

I've already found a nice solution for migration control with CodeIgniter thanks to the Migration class. Then I can utilize the post-receive hook and just run php path/to/codeigniter/index.php migrate/index and it simply updates the database design along with the files.

However from what I've seen so far with Drupal, this is a bit trickier. I am currently considering to in some manner store Drush commands for enabling new modules and such. The idea would then be to have a system similiar to Migration which I simply run with post-receive and the new modules gets enabled through drush en -y new_module whos command is saved somewhere.

The ideal flow illustrated here:

Ideal flow

What I suppose I would need to complete this flow is to have the bash script executed by post-receive, fetch some file named for instance 001.txt inside a directoy named drush_commands, and based on a variable I have saved in a file mentioned in .gitignore, execute the files with a number higher then the saved value, then set the value to the highest number amongst the executed files.

Question

However I'm not sure how to and if it's even possible to do this with bash scripts ideally. Is this approach an ideal one and how would the bash script work, or do you know any better way to have the same modules enabled (and other drush things) on both my local wamp and the server upon pushing?

Bonus question: Could I use this approach to handle changes to field data, content type and such? I have some trouble grasping exactly how I can sync the overall structure between local and live version.

  • 写回答

1条回答 默认 最新

  • dongren7374 2013-07-02 12:08
    关注

    This is absolutely possible both in theory and practice although I wouldn't attempt to complete it entirely using a post-receive hook.

    The ideal solution would be to have a CI server for example Jenkins (http://jenkins-ci.org/) sat listening with a job configured to handle migrations and use the post-receive hook to trigger this job via either the CLI interface or a cURL request. This takes the onus of a build away from Git (where it doesn't belong) and into CI (where it does).

    There are a number of decent CI solutions out there, both free and proprietary which will handle all of this for you with some basic configuration.

    The configured job when triggered, checks out your repo (based on a branch you specify) into its own workspace directory and can then call a script to build it as an application.

    # post-receive hook
    curl http://my.ci-server.local/job/drush_command/buildWithParameters?&GITBRANCH=$GIT_BRANCH&delay=0
    
    • my.ci-server.local Your locally installed CI server installation
    • drush_command would be the name of your job
    • GIT_BRANCH is the name of the branch to build (default develop???)

    Within the CI job you would then have a script which executes steps similar to the following:

    # GitIgnore file
    savedValue:0001
    
    # bash script
    savedValue=$(cat $WORKSPACE/.gitignore | grep 'savedValue' | cut -d: -f2);
    newValue=$(savedValue);
    for file in $(ls $WORKSPACE/drush_commands); do
    
        currentValue=$(echo $file | cut -d. -f1);
        if [ $currentValue -gt $savedValue ] ; then
    
            drush en -y "${currentValue}.txt}";
            if [ $currentValue > $newValue ] ; then
                newValue=$currentValue;
            fi
        fi
    done
    
    sed -i '' "s/savedValue.*/savedValue:$newValue/" $WORKSPACE/.gitignore;
    

    You could further extend this to handle changes to data by having a separate script called after the loop which looks for other scripts to execute which would then pick up the changes to carry out from a separate directory?

    Couple of points:

    • I wouldn't add the saved value to the .gitignore file - this isn't really the place for it. Use a separate configuration file (e.g. conf/last_enabled) for this kind of information.
    • The loop isn't going to work terribly well if you have files within the drush_commands dir which are not named '001.txt 002.txt' etc. You'll have to filter around these to make sure you're getting the latest.

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面