使用 GitLab 将 Node.js 应用程序持续部署到 Heroku [英] Continuous Deployment of a Node.js app to Heroku using GitLab

查看:22
本文介绍了使用 GitLab 将 Node.js 应用程序持续部署到 Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一些教程涵盖了 Ruby 和 Python 应用程序的部署,但我找不到很好的 NodeJS 文档或示例.

There are tutorials covering the deployment of Ruby and Python apps but I can't find good documentation or examples for 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-ruby-application-to-heroku.html

有人有 .gitlab-ci.yml 可以分享吗?

Does anyone have a .gitlab-ci.yml to share?

推荐答案

  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. create a heroku project

  1. 选择 -> 创建新应用
  2. 设置应用名称 &选择一个地区
  3. 点击创建应用
  1. select NEW -> Create new app
  2. set the App name & choose a region
  3. click on Create app

  • Gitlab setup 创建新的 repo 或添加到 gitlab 网站上给出的现有项目

  • Gitlab setup create new repo or add to exist project given on gitlab website

    创建一个 .gitlab-ci.yml 文件

    create a .gitlab-ci.yml file

    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
    
    

  • 设置HEROKU_API_KEY

    1. 设置 -> CI/CD -> 变量 -> 展开
    2. 输入变量键 -> .gitlab-ci.yml 中的变量名
    3. 输入变量值 -> Heroku Api Key

  • 获取 Heroku Api 密钥

  • Get the Heroku Api Key

    1. Heroki Dashborad -> 账户设置

  • 在 Gitlab 上设置 Runner

  • set the Runner on Gitlab

    1. 设置 -> CI/CD -> 变量 -> 展开
    1. Setting -> CI/CD -> Variable -> Expand
    1. 特定跑步者
    1. 安装 gitlab-runner
    2. Windows
    3. Linux
    4. MacOS
    5. 设置步骤这里

  • 共享跑步者

  • Shared Runners

    1. 只需点击禁用共享运行器即可启用共享运行器
    1. just click Disable shared Runners to enable the shared runner

  • 将文件推送到 gitlab 它将自动部署在 heroku 上

  • push the files to gitlab it will automatically deploy on heroku

    git add .                 #to add all the files)
    git commit -m "message"   #to commit files
    git push origin master  
    

  • 这篇关于使用 GitLab 将 Node.js 应用程序持续部署到 Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆