将CircleCI更改部署到Heroku

问题描述 投票:1回答:1

我对Git和自动部署很陌生,我正在尝试将作为CI的一部分完成的更改部署到Heroku。

高层次的想法:

  1. 将我的代码发送给GitHub
  2. CircleCI选择它并进行一些缩小
  3. CircleCI运行一些测试
  4. CircleCI将我的文件(包括我对它们所做的更改)部署到Heroku

一切都运行良好,除了我在Heroku上获得的文件似乎是来自Git的文件,而不是修改/缩小的文件。

我想这个问题来自我的YAML:

... build steps

deploy:
  docker:
    - image: buildpack-deps:trusty
  steps:
    - checkout
    - run:
        name: Deploy to Heroku
        command: |
            git push https://heroku:[email protected]/$HEROKU_APP_NAME.git master

但是,我不确定如何改变它。

  • 将修改过的文件直接发送给Heroku是不好的做法吗?我应该先将它们提交到特殊版本文件夹中的GitHub,然后将其发送给Heroku吗?怎么样?
  • 这只是我YAML中缺少的东西吗?

完成YAML作为参考:

version: 2
jobs:
build:
    docker:
    # https://circleci.com/docs/2.0/circleci-images/
    - image: circleci/node:10.10
    - image: circleci/postgres:10.5-alpine-postgis
        environment:
        POSTGRES_USER: myproject
        POSTGRES_DB: myproject

    working_directory: ~/repo

    steps:
    - checkout

    - restore_cache:
        keys:
        - v1-dependencies-{{ checksum "package.json" }}
        - v1-dependencies-

    - run: npm install

    ..........

    - save_cache:
        paths:
            - node_modules
        key: v1-dependencies-{{ checksum "package.json" }}

    - run:
        name: Unit Testing
        command: npm run test_unit

    - run:
        name: Build client files
        command: npm run build

    - run:
        name: API Testing
        command: |
            npm start &
            npm run test_api

deploy:
    docker:
    - image: buildpack-deps:trusty
    steps:
    - checkout
    - run:
        name: Deploy to Heroku
        command: |
            git push https://heroku:[email protected]/$HEROKU_APP_NAME.git master

workflows:
version: 2
build-deploy:
    jobs:
    - build
    - deploy:
        requires:
            - build
        filters:
            branches:
            only: master
git heroku deployment continuous-deployment circleci
1个回答
1
投票

您的CI工具不应该为Heroku构建您的应用程序。 (当然,它可以构建它来运行测试。)

Heroku将自己构建您的应用程序。推送你的源文件,让它做它的事情。使用Node.js buildpack你可以使用Heroku will run your postinstall script, if provided,它是运行构建命令的好地方:

"scripts": {
  "start": "node index.js",
  "test": "mocha",
  "postinstall": "npm rum build"
}

针对缩小文件(与未经文明的文件)运行测试可能会让您感觉更安全,但您正在有效地测试缩小工具以及您自己的代码。理想情况下,您应该使用已经过充分测试的工具,并将自己的测试集中在自己的代码上。 (如果你仍然喜欢对缩小的代码进行操作,那么它不会造成太大的伤害。)

如果您想确保测试针对Heroku上的代码的逐位精确副本运行(即,仅构建一次),请考虑通过Docker container构建和部署应用程序。

© www.soinside.com 2019 - 2024. All rights reserved.