Can I use my existing git repo with openshift?

前端 未结 11 866
野的像风
野的像风 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 17:50

    From you project folder, do

    git remote add backup user@server:/path/to/git/test.git
    git push backup master
    

    You can read Pushing to two git remote origins from one repository and Changing git remote origin.

    0 讨论(0)
  • 2020-11-28 17:50

    I agree with @adietisheim's answer: you need to understand better git before deploying with openshift =)

    Now, even if you understand git, it is not necessarily obvious how to deploy your existing repo if your directory structure does not match the directory structure required by openshift, and if you want to keep your old directory structure.

    For that, I have the following tips:

    • separate options that are deployment dependent from those that are not into different files. For example, I separate my database settings from other settings into different files as:

      • settings_deploy/openshift

      • settings_deploy/localhost

      and then symlink to your localhost test as something like:

      ln -s settings_deploy/localhost settings_deploy_file
      

      Another option is to detect the host by using environment variables:

      if 'OPENSHIFT_APP_NAME' in os.environ:
          //openshift configurations
      else:
          //localhost
      

      This is a bit simpler since it allows you to put all the configs on a single file. It is a bit less general, since if ever another one of your hosts offers an OPENSHIFT_APP_NAME environment variable (unlikely for this one) the method breaks. Anyways, you still have to clearly separate what is deployment dependent and what is not.

    • create a local deploy directory

    • clone the initial openshift template into it

    • create a deploy script that:

      • hardlinks everything from your old existing local to their correct locations at the

        hardlinks are fast to create and use very little memory

        you could use something like:

        cp -lrf original_repo_dir deploy_repo_dir

      • keep only the correct settings_deploy file in the deploy repo:

        cd deploy_repo

        mv settings_deploy/openshift settings_deploy_file

        rm -r settings_deploy

      • force push:

        cd deploy_repo

        git push -f origin master

      • clean the deploy repo:

        git reset --hard HEAD

        git clean -df

    for those interested in django deployment, I have an example on my github, in particular check out the deploy.sh script and the project projects/elearn which it deploys.

    0 讨论(0)
  • 2020-11-28 17:55

    I ran into problems deploying a pre-existing code repository to Openshift. In my particular context, where I tried to deploy a tomcat webapp, the Openshift tomcat configuration files included in the .openshift folder were crucial.

    What fixed it for me was the inclusion of the .openshift folder in my existing source tree, as well as the inclusion of the openshift profile in my maven pom.xml file.

    This is highly likely the same that would happen by merging your repository with the new openshift upstream one. For me, this is the "why" behind following sentence in adietisheim's great answer:

    "In order to then be able to push the code from your local git repo to openshift you first have to merge your openshift repo with your local bitbucket clone."

    In my case, this merge was needed to get the config files from the .openshift directory. It took a long time to figure out for me because pushing without the .openshift directory still made my app build and deploy successfully. The only behaviour I saw was a report on missing jsp files, which made me think that the problem was related to my own web.xml and servlet configuration.

    0 讨论(0)
  • 2020-11-28 17:55

    TAKE EASY!

    step 1: Create app. With your favorite method (from gitRepository, pre-maker Openshift, etc). if you use console metod
    step 2: rhc git-clone nameApp
    step 3: rhc app-configure nameApp --auto-deploy
    step 4: ENJOY!

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题