Can I use my existing git repo with openshift?

前端 未结 11 880
野的像风
野的像风 2020-11-28 17:36

Is it necessary to have git repo on openshift only? I already have bitbucket / github git repo and would prefer to push there only. Can I simply hook into it so that openshi

11条回答
  •  囚心锁ツ
    2020-11-28 18:03

    Mohannd's answer is perfect, but I would like to sum up the complete solution, in case some else needs it:

    To use your github repo as an Openshift repo, there is no perfect solution now, because, Openshfit uses git hooks to trigger the deployment or redeployment based on your commits. However, the smartest way would be to use 2 repos (the openshift's one and your github's one) to push simultaneously the code to.

    To do this: Add a remote named "all" and add 2 push urls to it.

    git remote add all ssh://23456781234567@yourapp-namespace.rhcloud.com/~/git/yourapp.git
    git remote set-url openshift-git-repo --push --add ssh://23456781234567@yourapp-namespace.rhcloud.com/~/git/yourapp.git
    git remote set-url github-repo --push --add git@github.com:youruser/yourapp.git
    

    Then set the remote named 'all' as the default push remote:

    git push -u all
    

    To commit and push your code, proceed as usual: It will push on the 2 remotes and deploy on OpenShift

    git add .
    git commit -m "my commit"
    git push
    

    And watch the result:

    [master 3fc96b2] my commit
     1 file changed, 2 deletions(-)
    MyLaptop:myapp User$ git push
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 291 bytes | 0 bytes/s, done.
    Total 3 (delta 2), reused 0 (delta 0)
    To git@github.com:User/myapp.git
       a036a44..3fc96b2  master -> master
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (3/3), 291 bytes | 0 bytes/s, done.
    Total 3 (delta 2), reused 0 (delta 0)
    remote: Stopping PHP 5.4 cartridge (Apache+mod_php)
    remote: Waiting for stop to finish
    remote: Waiting for stop to finish
    remote: Building git ref 'master', commit 3fc96b2
    remote: Preparing build for deployment
    remote: Deployment id is 9037d37a
    remote: Activating deployment
    remote: Starting PHP 5.4 cartridge (Apache+mod_php)
    remote: Application directory "/" selected as DocumentRoot
    remote: -------------------------
    remote: Git Post-Receive Result: success
    remote: Activation status: success
    remote: Deployment completed with status: success
    To ssh://23456789@myapp-namespace.rhcloud.com/~/git/myapp.git/
       a036a44..3fc96b2  master -> master
    MyLaptop:myapp User$
    

    Hope this helps

提交回复
热议问题