Continuous Deployment of a Node.js app to Heroku using GitLab

后端 未结 2 1863
眼角桃花
眼角桃花 2021-02-05 17:27

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/t

相关标签:
2条回答
  • 2021-02-05 17:44

    I have found a detailed article for continuous integration on Heroku:

    https://medium.com/@seulkiro/deploy-node-js-app-with-gitlab-ci-cd-214d12bfeeb5

    Sample .gitlab-ci.yml file :

    https://gitlab.com/seulkiro/node-heroku-dpl

    0 讨论(0)
  • 2021-02-05 18:02
    1. create a project
     npm init -y
     npm i  #install dependencies 
    
    1. add the following lines in 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. create a heroku project

      1. select NEW -> Create new app
      2. set the App name & choose a region
      3. click on Create app
    2. Gitlab setup create new repo or add to exist project given on gitlab website

    3. 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
      
      
    4. Setting HEROKU_API_KEY
      1. Setting -> CI/CD -> Variable -> Expand
      2. Input Variable key -> variable name in .gitlab-ci.yml
      3. Input Variable value -> Heroku Api Key
    5. Get the Heroku Api Key

      1. Heroki Dashborad -> Account Settings
    6. set the Runner on Gitlab

      1. Setting -> CI/CD -> Variable -> Expand
        1. Specific Runners
          1. Install the gitlab-runner
          2. Windows
          3. Linux
          4. MacOS
          5. For setup steps here
        2. Shared Runners
          1. just click Disable shared Runners to enable the shared runner
    7. 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  
      
    0 讨论(0)
提交回复
热议问题