在 bitbucket 上使用 git 部署到 Heroku

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13240227/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:53:12  来源:igfitidea点击:

Deploying to Heroku using git on bitbucket

githerokugithubbitbucketheroku-toolbelt

提问by Wasswa Samuel

I want to host my source on bitbucket using git because I obviously get a free private repo and I want to host my app on heroku using the source code from bitbucket.

我想使用 git 在 bitbucket 上托管我的源代码,因为我显然得到了一个免费的私有仓库,而且我想使用 bitbucket 的源代码在 heroku 上托管我的应用程序。

Can i do it using the github client and heroku toolbelt. Will it work? Github is great but i dont want everyone seeing my code and I dont want to pay for a private repo because its a small project.

我可以使用 github 客户端和 heroku 工具带来做到这一点。它会起作用吗?Github 很棒,但我不想让每个人都看到我的代码,我也不想为私人回购付费,因为它是一个小项目。

采纳答案by Xavier

Deploying to Heroku should work regardless of where you host your code as the Heroku CLI adds it's own git remote for the sake of deployments. In fact, you can even git pullfrom Heroku, so you could technically use Heroku as a private git repository instead (though not recommended). As for using the GitHub client to connect to bitbucket, simply change the repository remote to the URL provided by bitbucket in the settings tab of the client.

无论您在何处托管代码,部署到 Heroku 都应该有效,因为 Heroku CLI 为部署添加了它自己的 git remote。实际上,您甚至可以git pull从 Heroku 中使用,因此从技术上讲,您可以将 Heroku 用作私有 git 存储库(尽管不推荐)。至于使用GitHub客户端连接bitbucket,只需在客户端的设置选项卡中将repository remote改为bitbucket提供的URL即可。

回答by Stefan

Just to add to zeiv's answer who said it should work: I can confirm that it does. We use bitbucket for git hosting and deploy to heroku. What you can't seem to do is add your bitbucket repo to your heroku account to have commit history show up, this feature seems to be currently limited to github (heroku's fault ;-)

只是为了补充 zeiv 的回答,谁说它应该有效:我可以确认它确实有效。我们使用 bitbucket 进行 git 托管并部署到 heroku。您似乎无法做的是将您的 bitbucket 存储库添加到您的 heroku 帐户以显示提交历史记录,此功能目前似乎仅限于 github(heroku 的错;-)

回答by handwovensole

Chiming in with Stefan - this works perfectly. Here's what I did:

与 Stefan 合作 - 这非常有效。这是我所做的:

  1. Got really frustrated with the way my WP blog was resetting daily, presenting anyone who navigated to http://blog.example.comwith a setup screen, because there was no wp-config.php.
  2. Logged into bitbucket.org.
  3. Linked my bitbucket & github accounts.
  4. Forked my "wp-blog" repo from github, which I had previously linked to my heroku remote.
  5. Cloned into this new fork ("git clone https://[email protected]/myname/wp-blog_config.git") .
  6. Added a proper wp-config.php.
  7. Added my heroku remote from within this new fork ("git remote add heroku [email protected]:adjective-noun-1234.git")
  8. Committed & deployed to heroku ("git push heroku master:master")
  1. 对我的 WP 博客每天重置的方式感到非常沮丧,向导航到http://blog.example.com 的任何人展示设置屏幕,因为没有 wp-config.php。
  2. 登录到 bitbucket.org。
  3. 链接了我的 bitbucket 和 github 帐户。
  4. 从 github 分叉出我的“wp-blog”存储库,我之前已将其链接到我的 heroku 遥控器。
  5. 克隆到这个新分支 ("git clone https://[email protected]/myname/wp-blog_config.git") 。
  6. 添加了适当的 wp-config.php。
  7. 在这个新分支中添加了我的 heroku 遥控器(“git remote add heroku [email protected]:adjective-noun-1234.git”)
  8. 提交并部署到 heroku ("git push heroku master:master")

回答by Karl Adler

Bitbucket supports now Pipelines, which should make it pretty easy to deploy on Heroku. Just follow this tutorial: https://confluence.atlassian.com/bitbucket/deploy-to-heroku-872013667.html

Bitbucket 现在支持Pipelines,这应该可以很容易地在 Heroku 上部署。只需按照本教程:https: //confluence.atlassian.com/bitbucket/deploy-to-heroku-872013667.html

My bitbucket-pipelines.ymlto just push the master branch to Heroku looks like this:

bitbucket-pipelines.yml只是将主分支推送到 Heroku 看起来像这样:

image: node:6
clone:
  depth: full
pipelines:
  branches:
    master:
      - step:
          script:
            - git push -f https://heroku:[email protected]/$HEROKU_APP_NAME.git $BITBUCKET_BRANCH

回答by Pieter Venter

If you dont want to work in the command line and push to heroku the whole time and worry about maintaining SSH keys (quite annoying if you work on different boxes), then follow this guide on how to setup continuous integration using codeship. Its a free plugin on heroku.

如果你不想在命令行中工作并一直推送到 heroku 并且担心维护 SSH 密钥(如果你在不同的机器上工作很烦人),那么请按照本指南了解如何使用 codeship 设置持续集成。它是 heroku 上的免费插件。

http://blog.codeship.io/2014/04/29/continuous-deployment-heroku-bitbucket-nodejs.html

http://blog.codeship.io/2014/04/29/continuous-deployment-heroku-bitbucket-nodejs.html

回答by Karim Samir

I found this Pagehelpful

我发现这个页面很有帮助

Install Heroku Toolbelt

安装Heroku 工具带

If you haven't already, log in to your Heroku account and follow the prompts to create a new SSH public key.

如果您还没有,请登录您的 Heroku 帐户并按照提示创建一个新的 SSH 公钥。

$ heroku login

Create a new Git repository

创建一个新的 Git 存储库

Initialize a git repository in a new or existing directory

在新目录或现有目录中初始化 git 存储库

$ cd my-project/
$ git init
$ heroku git:remote -a PROJECTNAME

Deploy your application

部署您的应用程序

Commit your code to the repository and deploy it to Heroku using Git.

将您的代码提交到存储库并使用 Git 将其部署到 Heroku。

$ git add .
$ git commit -am "make it better"
$ git push heroku master

Existing Git repository

现有的 Git 存储库

For existing repositories, simply add the heroku remote

对于现有的存储库,只需添加 heroku 远程

$ heroku git:remote -a PROJECTNAME