我可以在 openshift 中使用我现有的 git repo 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12657168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I use my existing git repo with openshift?
提问by Jigar Shah
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 ?
是否有必要仅在 openshift 上使用 git repo?我已经有了 bitbucket / github git repo,并且更愿意只推送到那里。我可以简单地连接它以便 openshift 得到提示吗?
Or for simplification, I push only at github, but when I want to deploy, I do something with openshift?
或者为了简单起见,我只在github上推送,但是当我想部署时,我用openshift做一些事情?
I did check thisbut it confused me: it's talking about merging exiting and new (openshift) git ?
我确实检查过这个,但它让我感到困惑:它正在谈论合并 exiting 和 new (openshift) git ?
回答by adietisheim
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。我建议您进入 git 以完全了解如何将您的代码推送到 openshift。不过,让我尝试向您解释所涉及的步骤:正如您通常使用 git 所做的那样,此处选择的方法是将您的其他 git 存储库(例如在 bitbucket 上)克隆到您的本地机器:
git clone <bitbucket-repo-url>
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:
您的本地克隆然后将您的其他存储库(bitbucket 等)作为远程存储库。您的远程存储库使用别名“origin”(如果您进行克隆,则 git 使用的默认别名)存储。然后您将 openshift 存储库作为远程添加到您的克隆。您在为您添加的远程存储库显式使用别名的同时这样做 - 我在这里使用“openshift”作为别名:
git remote add openshift -f <openshift-git-repo-url>
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 存储库推送到 openshift,您首先必须将 openshift 存储库与本地 bitbucket 克隆合并。您可以通过在本地发布来做到这一点:
git merge openshift/master -s recursive -X ours
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.
使用此命令,您可以告诉 git 将 openshift git repo 中的 master 分支与您的本地 git repo 合并。您告诉它使用递归合并策略进行合并,并在出现冲突时选择您的(“我们的”)版本。
Once the merge is executed you're ready to push your git repo to openshift. You do that by doing:
执行合并后,您就可以将 git 存储库推送到 openshift。你这样做:
git push openshift HEAD
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).
您告诉 git 将您的本地代码推送到名为“openshift”的远程存储库上的 HEAD 分支(我们将 openshift git 存储库存储在该别名,更进一步的一些段落)。
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".
顺便提一句。几个月前,我写了一篇 jboss 工具博客,演示了如何使用 openshift-java-client:https://community.jboss.org/wiki/Enable-openshift-ciFullExampleUsingOpenshift-java-client 。您将在最后一段“我们快到了”中看到上述步骤。
回答by Sithu
I know the question is 2-year old and the @adietisheim's answerhas 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.
我知道这个问题已有2 年历史,@adietisheim 的回答已被接受。我个人不喜欢将 openshift 存储库合并到我的本地克隆中,因为我不想将 OpenShift 存储库混合到我的公共存储库的主分支中。
Assuming you have added the remote using git remote add openshift <openshift-git-repo-url>
, here is what I would do:
假设您已经使用添加了遥控器git remote add openshift <openshift-git-repo-url>
,这就是我要做的:
Create a new local branch openshift
based on the master
branch.
openshift
根据分支创建一个新的本地master
分支。
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.
您可以在分支上进行一些提交,openshift
例如您的应用程序部署配置。然后,使用标志将当前分支推送到 OpenShift 存储库中与 master 匹配的远程 ref-f
以覆盖远程master
分支中的所有内容。
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:
每当我想将我的应用程序部署到 OpenShift 时,我都会检查本地openshift
分支并master
与之合并分支,然后强制推送到 OpenShift,但是-f
下一次推送可能不需要:
git checkout openshift
git merge --no-ff master
git push openshift master -f
回答by Mohannd
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 repositoryand Changing git remote origin.
回答by stefankolb
You should be able to pass in an existing Git repository into the asset pipeline via
您应该能够通过以下方式将现有的 Git 存储库传递到资产管道中
rhc create-app $APPNAME ruby-1.9 --from-code $GIT_LOCATION
The remote Git repository then delivers the initial application for OpenShift.
然后远程 Git 存储库交付 OpenShift 的初始应用程序。
As a second possibility, you can skip the creation of the local OpenSHift Git repository via
作为第二种可能性,您可以通过以下方式跳过本地 OpenSHIft Git 存储库的创建
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.
然后使用上述步骤将 OpenShift 远程 Git 存储库合并到您的本地 Git 存储库中。
回答by Akram Ben Aissi
Mohannd's answer is perfect, but I would like to sum up the complete solution, in case some else needs it:
Mohannd 的回答是完美的,但我想总结一下完整的解决方案,以防其他人需要它:
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.
要将您的 github 存储库用作 Openshift 存储库,现在没有完美的解决方案,因为 Openshfit 使用 git hooks 根据您的提交触发部署或重新部署。但是,最聪明的方法是使用 2 个 repos(openshift 的一个和您的 github 的一个)同时将代码推送到。
To do this: Add a remote named "all" and add 2 push urls to it.
要做到这一点:添加一个名为“all”的遥控器并向其添加 2 个推送 url。
git remote add all ssh://[email protected]/~/git/yourapp.git
git remote set-url openshift-git-repo --push --add ssh://[email protected]/~/git/yourapp.git
git remote set-url github-repo --push --add [email protected]:youruser/yourapp.git
Then set the remote named 'all' as the default push remote:
然后将名为“all”的远程设置为默认推送远程:
git push -u all
To commit and push your code, proceed as usual: It will push on the 2 remotes and deploy on OpenShift
要提交和推送您的代码,请照常进行:它将推送 2 个遥控器并部署在 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 [email protected]: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://[email protected]/~/git/myapp.git/
a036a44..3fc96b2 master -> master
MyLaptop:myapp User$
Hope this helps
希望这可以帮助
回答by Axel
There is a way to do what you want, i.e. skip Openshift's repo. What you need to do is set up a jenkins, and have it poll your own repository.
有一种方法可以做你想做的,即跳过 Openshift 的 repo。您需要做的是设置一个 jenkins,并让它轮询您自己的存储库。
There's a link here that explains how to set it up from scratch: http://blog.anthavio.net/2014/01/deploy-to-openshift-from-github.html
这里有一个链接解释了如何从头开始设置:http: //blog.antavio.net/2014/01/deploy-to-openshift-from-github.html
回答by alexzm1
If you're using github you can configure travis to made the deployment each time you made a change in your github repository
如果您使用 github,则可以配置 travis 以在每次在 github 存储库中进行更改时进行部署
回答by Bram Luyten
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.
我在将预先存在的代码存储库部署到 Openshift 时遇到了问题。在我尝试部署 tomcat webapp 的特定环境中,.openshift 文件夹中包含的 Openshift tomcat 配置文件至关重要。
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.
为我修复的是在我现有的源代码树中包含 .openshift 文件夹,以及在我的 maven pom.xml 文件中包含 openshift 配置文件。
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:
这很可能与将您的存储库与新的 openshift 上游存储库合并时发生的情况相同。对我来说,这就是 adietisheim 的精彩回答中以下句子背后的“为什么”:
"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."
“为了能够将代码从本地 git 存储库推送到 openshift,您首先必须将 openshift 存储库与本地 bitbucket 克隆合并。”
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.
就我而言,需要此合并才能从 .openshift 目录中获取配置文件。我花了很长时间才弄清楚,因为在没有 .openshift 目录的情况下推送仍然使我的应用程序构建和部署成功。我看到的唯一行为是缺少jsp文件的报告,这让我认为问题与我自己的web.xml和servlet配置有关。
回答by adietisheim
If you are using java then there's is an alternative approach. But even in this approach you would still use the OpenShift git repository. The git repository provided by OpenShift is how you give OpenShift your code, your deployable(s):
如果您使用的是 java,则有另一种方法。但即使采用这种方法,您仍将使用 OpenShift git 存储库。OpenShift 提供的 git 存储库是您向 OpenShift 提供代码和可部署的方式:
You can - instead of committing your code to the OpenShift git repo - simply give it your war-file. You clone the OpenShift git repo to your local machine. You then build a war from your application source and put this war into the deployments folder within your OpenShift git repo (clone). You then add, commit and push your local clone to OpenShift. Once the push executed successfully, the JBoss AS7 will pick your war and deploy it.
您可以 - 而不是将您的代码提交到 OpenShift git repo - 只需将您的War文件提供给它。您将 OpenShift git 存储库克隆到本地计算机。然后,您从应用程序源构建一个War,并将这个War放入 OpenShift git 存储库(克隆)中的部署文件夹中。然后添加、提交本地克隆并将其推送到 OpenShift。一旦推送成功执行,JBoss AS7 将挑选您的War并部署它。
回答by Patricio Joaquin Labarca Guzma
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!
第 1 步:创建应用程序。使用您最喜欢的方法(来自 gitRepository、pre-maker Openshift 等)。如果您使用控制台方法
第 2 步:rhc git-clone nameApp
第 3rhc app-configure nameApp --auto-deploy
步:第 4步:享受!