Can I use my existing git repo with openshift?

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 openshift gets intimation ?

Or for simplification, I push only at github, but when I want to deploy, I do something with openshift?

I did check this but it confused me: it's talking about merging exiting and new (openshift) git ?


I have the impression that you're not used to use git enough yet. I'd advise you to get into git to fully understand how to push your code to openshift. Nevertheless let me try to explain you the steps involved: As you'd do with git in general, the approach to choose here is to clone your other git repo (ex. on bitbucket) to your local machine:

git clone <bitbucket-repo-url>

Your local clone has then your other repo (bitbucket etc.) as remote repo. Your remote repo is stored with the alias "origin" (the default alias used by git if you clone). You then add the openshift repo as remote to your clone. You do that while explicitly using an alias for the remote repo you add - I'm using "openshift" as alias here:

git remote add openshift -f <openshift-git-repo-url>

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. You do that by issuing locally:

git merge openshift/master -s recursive -X ours

With this command you tell git to merge the master branch in the openshift git repo with your local git repo. You tell it to merge using the recursive merging strategy and to choose your ("ours") version when there are conflicts.

Once the merge is executed you're ready to push your git repo to openshift. You do that by doing:

git push openshift HEAD

You tell git to push your local code to the HEAD branch on the remote repo called "openshift" (the alias we stored the openshift git repo at, some paragraphs further up).

btw. I wrote a jboss tools blog which was demonstrating how to use the openshift-java-client some months ago: https://community.jboss.org/wiki/Enable-openshift-ciFullExampleUsingOpenshift-java-client . You'll spot the above steps in the last paragraph "We're almost there".


I know the question is 2-year old and the @adietisheim's answer has been accepted. I personally don't like to merge the openshift repo into my local clone because I don't want to mix the OpenShift repo into the master branch of my public repo.

Assuming you have added the remote using git remote add openshift <openshift-git-repo-url>, here is what I would do:

Create a new local branch openshift based on the master branch.

git checkout -b openshift

You could make some commits on the branch openshift such as your app deployment configurations. Then, push the current branch to the remote ref matching master in the OpenShift repository with the flag -f to overwrite everything in the remote master branch.

git push openshift master -f

Whenever I want to deploy my app to OpenShift, I would check out the local openshift branch and merge master branch with it, then force push to OpenShift, however -f may not be required for the next pushes:

git checkout openshift
git merge --no-ff master
git push openshift master -f

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.


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.


You should be able to pass in an existing Git repository into the asset pipeline via

rhc create-app $APPNAME ruby-1.9 --from-code $GIT_LOCATION

The remote Git repository then delivers the initial application for OpenShift.

As a second possibility, you can skip the creation of the local OpenSHift Git repository via

rhc create-app $APPNAME ruby-1.9 --no-git

and then use the steps described above to merge the OpenShift remote Git repository into your local Git repository.