使用 GitLab 将 Node.js 应用程序持续部署到 Heroku

2024-01-23

有涵盖 Ruby 和 Python 应用程序部署的教程,但我找不到 NodeJS 的良好文档或示例。

http://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html http://docs.gitlab.com/ce/ci/examples/test-and-deploy-python-application-to-heroku.html

http://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html http://docs.gitlab.com/ce/ci/examples/test-and-deploy-ruby-application-to-heroku.html

有谁有.gitlab-ci.yml分享?


  1. 创建一个项目
 npm init -y
 npm i  #install dependencies 
  1. 在 package.json 中添加以下行
    "engines": {
        "node": "8.12.0",  //node version
        "npm": "6.4.1"     //npm version
    },
    "scripts": {
        "start": "node app.js", //heroku will using the following script to run node app
    }
  1. 创建一个heroku项目

    1. select NEW -> 创建新应用程序
    2. set the App name & 选择一个地区
    3. 点击创建应用程序
  2. Gitlab 设置创建新的存储库或添加到 gitlab 网站上给出的现有项目

  3. 创建 .gitlab-ci.yml 文件

    image: node:latest
    stages:
    - production
    production:
    type: deploy
    stage: production
    image: ruby:latest
    script:
        - apt-get update -qy
        - apt-get install -y ruby-dev
        - gem install dpl
        - dpl --provider=heroku --app=APPNAME_OF_Heroku App --api-key=$HEROKU_API_KEY # security add the heroku api to CI/CD setting
    only:
        - master  #branch name to deploy on heroku
    
    
  4. Setting HEROKU_API_KEY
    1. 设置 -> CI/CD -> 变量 -> 展开
    2. 在 .gitlab-ci.yml 中输入变量键 -> 变量名称
    3. 输入变量值 -> Heroku Api Key
  5. 获取 Heroku Api 密钥

    1. Heroku 仪表板 -> 帐户设置
  6. 在Gitlab上设置Runner

    1. Setting -> CI/CD -> Variable -> Expand
      1. Specific Runners
        1. 安装 gitlab-runner
        2. Windows https://docs.gitlab.com/runner/install/windows.html
        3. Linux https://docs.gitlab.com/runner/install/linux-manually.html
        4. MacOS https://docs.gitlab.com/runner/install/osx.html
        5. 有关设置步骤here https://docs.gitlab.com/runner/register/index.html
      2. Shared Runners
        1. 只需点击禁用共享跑步者启用共享运行器
  7. 将文件推送到gitlab,它会自动部署到heroku上

    git add .                 #to add all the files)
    git commit -m "message"   #to commit files
    git push origin master  
    
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 GitLab 将 Node.js 应用程序持续部署到 Heroku 的相关文章

随机推荐