How can I auto-deploy my git repo's submodules on push?

前端 未结 2 582
野趣味
野趣味 2020-12-17 20:42

I have a PHP Cartridge that is operating normally, except I can\'t find a straightforward way to get OpenShift to (recursively) push the files for my git submodules when/aft

相关标签:
2条回答
  • 2020-12-17 21:23

    Ok, I'll take a stab at this for 50 extra points ;)

    Here are the steps that I followed:

    1.) Create php-5.3 application on OpenShift on clone to local machine.
    2.) Create public git repository on github to use as the submodule.
    3.) Add the github repository to the OpenShift application using the following commands, make sure that you use the https url instead of the git@ url, or you will get private key issues when OpenShift Online tries to checkout the sub-module.

     cd into your locally cloned openshift application directory  
     git submodule add https://github.com/developercorey/somesubmodule.git ./directory_name
     git add .
     git commit -am "adding a submodule"
     git push
    

    If you don't see any errors in your git push, then everything should have worked correctly. if you see an error like this

    remote: Host key verification failed.
    remote: fatal: Could not read from remote repository.
    remote: 
    remote: Please make sure you have the correct access rights
    remote: and the repository exists.
    

    That means you used the git@ url instead of the https url to add your git submodule, or you are trying to access a private repository. Now you can ssh into your application using the rhc ssh command and cd into your ~/app-root/runtime/repo directory and you should see your submodule directory there with the files from that repository inside.

    If that doesn't work for you, please let me know what the output of your git push is and we'll go from there.

    0 讨论(0)
  • 2020-12-17 21:23

    For a parent repo (which contains submodules), you should only have to push the parent repo itself: it includes the gitlink (special entries in the index) referencing the right SHA1 for each submodule.

    Once pushed, a post-receive hook can trigger a:

    git submodule update --init --recursive
    

    That would update each submodule to the right SHA1.

    The post-receive hook is in the parent bare repo: /path/to/parent.git/hooks/post-receive with:

    #! /bin/bash
    cd /path/to/non-bare/parent
    git --git-dir=/path/to/parent.git checkout 
    git --git-dir=/path/to/parent.git submodule update --init --recursive
    
    0 讨论(0)
提交回复
热议问题