Project Icon

heroku-deploy

GitHub到Heroku的自动化部署Action

该Action通过简单的配置实现GitHub项目到Heroku的自动部署。支持Docker和自定义buildpack,提供健康检查、环境变量管理等功能。适用于个人和团队项目,支持多地区部署,优化了开发者的持续部署工作流。

Heroku Deploy

Join the chat at https://gitter.im/akhileshns-heroku-deploy/community

GitHub issues GitHub Tests

This is a very simple GitHub action that allows you to deploy to Heroku. The action works by running the following commands in shell via NodeJS:-

Table of Contents

  1. Getting Started
  2. Important Note
  3. Options
  4. Examples
  5. Health Check
  6. Environment Variables
  7. Procfile Passing
  8. Deploying to a team
  9. Just Login
  10. Important Notes
  11. License

Getting Started

To get started using the action, just make sure to have a Procfile or a Dockerfile in your project and then create a folder called .github and inside it, create another folder called workflows. Finally inside the workflows folder, create a file called main.yml with the following contents:

.github/workflows/main.yml

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/heroku-deploy@v3.13.15 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
          heroku_email: "YOUR EMAIL"

Now go to your Heroku account and go to Account Settings. Scroll to the bottom until you see API Key. Copy this key and go to your project's repository on GitHub.

In your Repo, go to Settings -> Secrets and click on "New Secret". Then enter HEROKU_API_KEY as the name and paste the copied API Key as the value.

You can now push your project to GitHub and it will be automatically deployed to Heroku henceforth.

You learn more about GitHub Secrets here and GitHub Actions here

Important Note

Please Note: Git has recently announced that it is planning to switch the default branch's name from "master" to "main". For this reason, the Action also pushes to the "main" branch in the heroku origin by default and if your Heroku App is still using the "master" branch, then the Action will automatically switch your Heroku remote to use "main" as the default branch. There is No Action Needed from you, just keep in mind that this change is occurring as you continue to use the App and if you ever need to manually deploy the App, you can do so using the following command:

git push heroku YOUR_BRANCH:refs/heads/main

Also the remote_branch property no longer exists in the latest release of the Action. If you still have this as part of the 3.10.9 release. Please remove it as it may cause problems in your workflow

Please Note: While creating a new project on Heroku, do not enable the option for Automatic Deployments as this would result in an error when the GitHub Action is triggered.

Options

The action comes with additional options that you can use to configure your project's behavior on Heroku. You can setup these options under the "with" object as presented above:

NameRequiredDescriptionExample
heroku_api_keytrueThis will be used for authentication. You can find it in your heroku homepage account settings***
heroku_emailtrueEmail that you use with herokunsakhilesh02@gmail.com
heroku_app_nametrueThe appname to use for deploying/updatingdemo-rest-api
buildpackfalseAn optional buildpack to use when creating the heroku applicationhttps://github.com/heroku/heroku-buildpack-static.git
branchfalseThe branch that you would like to deploy to Heroku. Defaults to "HEAD"master, dev, test
dontautocreatefalseSet this to true if you don't want to automatically create the Heroku apptrue or false
dontuseforcefalseSet this to true if you don't want to use --force when switching branchestrue or false
usedockerfalseWill deploy using Dockerfile in project roottrue or false
docker_heroku_process_typefalseType of heroku process (web, worker, etc). This option only makes sense when usedocker enabled. Defaults to "web" (Thanks to singleton11 for adding this feature)web, worker
docker_build_argsfalseA list of args to pass into the Docker build. This option only makes sense when usedocker enabled.NODE_ENV
appdirfalseSet if your app is located in a subdirectoryapi, apis/python
healthcheckfalseA URL to which a healthcheck is performed (checks for 200 request)https://demo-rest-api.herokuapp.com
checkstringfalseValue to check for when conducting healthcheck requestsok
delayfalseTime (in seconds) to wait before performing healthcheck. Defaults to 0 seconds5
procfilefalseContents of the Procfile to save and deployweb: npm start
rollbackonhealthcheckfailedfalseWhen set to true this will attempt to rollback to the previous release if the healthcheck failstrue or false
env_filefalsepath to an env file (with respect to appdir)/.env
justloginfalseSet to true if you want the action to just login to Heroku and nothing elsetrue or false
regionfalseThe region in which you would like to deploy a servereu or dublin
stackfalseSet stack of your heroku app if you need to change. Default: heroku-20container
teamfalseIf deploying to an organization, then specify the name of the team or organization hereteam-xyz

Examples

Deploy with Docker

Heroku now allows users to deploy docker containers. To use this feature, simply add a Dockerfile to your project and add a CMD command at the end of the Dockerfile. This is the command used by heroku to start the webserver inside the container. Finally make sure to set the usedocker flag to true before deploying.

.github/workflows/main.yml

name: Deploy

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: akhileshns/heroku-deploy@v3.13.15 # This is the action
        with:
          heroku_api_key: ${{secrets.HEROKU_API_KEY}}
          heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
          heroku_email: "YOUR EMAIL"
          usedocker: true

Keep in mind that if you deploy once using docker,

项目侧边栏1项目侧边栏2
推荐项目
Project Cover

豆包MarsCode

豆包 MarsCode 是一款革命性的编程助手,通过AI技术提供代码补全、单测生成、代码解释和智能问答等功能,支持100+编程语言,与主流编辑器无缝集成,显著提升开发效率和代码质量。

Project Cover

AI写歌

Suno AI是一个革命性的AI音乐创作平台,能在短短30秒内帮助用户创作出一首完整的歌曲。无论是寻找创作灵感还是需要快速制作音乐,Suno AI都是音乐爱好者和专业人士的理想选择。

Project Cover

白日梦AI

白日梦AI提供专注于AI视频生成的多样化功能,包括文生视频、动态画面和形象生成等,帮助用户快速上手,创造专业级内容。

Project Cover

有言AI

有言平台提供一站式AIGC视频创作解决方案,通过智能技术简化视频制作流程。无论是企业宣传还是个人分享,有言都能帮助用户快速、轻松地制作出专业级别的视频内容。

Project Cover

Kimi

Kimi AI助手提供多语言对话支持,能够阅读和理解用户上传的文件内容,解析网页信息,并结合搜索结果为用户提供详尽的答案。无论是日常咨询还是专业问题,Kimi都能以友好、专业的方式提供帮助。

Project Cover

讯飞绘镜

讯飞绘镜是一个支持从创意到完整视频创作的智能平台,用户可以快速生成视频素材并创作独特的音乐视频和故事。平台提供多样化的主题和精选作品,帮助用户探索创意灵感。

Project Cover

讯飞文书

讯飞文书依托讯飞星火大模型,为文书写作者提供从素材筹备到稿件撰写及审稿的全程支持。通过录音智记和以稿写稿等功能,满足事务性工作的高频需求,帮助撰稿人节省精力,提高效率,优化工作与生活。

Project Cover

阿里绘蛙

绘蛙是阿里巴巴集团推出的革命性AI电商营销平台。利用尖端人工智能技术,为商家提供一键生成商品图和营销文案的服务,显著提升内容创作效率和营销效果。适用于淘宝、天猫等电商平台,让商品第一时间被种草。

Project Cover

AIWritePaper论文写作

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

投诉举报邮箱: service@vectorlightyear.com
@2024 懂AI·鲁ICP备2024100362号-6·鲁公网安备37021002001498号