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

查看:99
本文介绍了使用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吗?

推荐答案

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

  • Gitlab安装程序创建新的仓库或添加到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键

  • 获取Heroku Api密钥

  • Get the Heroku Api Key

    1. Heroki Dashborad->帐户设置

  • 在Gitlab上设置跑步者

  • set the Runner on Gitlab

    1. 设置-> CI/CD->变量->展开
    1. Setting -> CI/CD -> Variable -> Expand
    1. 特定跑步者
    1. Specific Runners
    1. 安装gitlab-runner
    2. Windows
    3. Linux
    4. MacOS
    5. 有关设置步骤,请此处
    1. Install the gitlab-runner
    2. Windows
    3. Linux
    4. MacOS
    5. For setup steps here

  • 共享跑步者

  • 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天全站免登陆