Herkoku节点部署与子文件夹

我正在尝试几个小时,并没有想法离开…也许你有一些:-)

我正在使用react-starter-kit作为我的react-app和gitlab作为我的存储库。 我已经启用gitlab-ci部署和运送我的应用程序到heroku。

好吧, gitlab-ci作品… 是的

但是使用/build文件夹来处理所有的资源和缩小的等应用程序。

我如何能够通过gitlab-ci获得heroku上的可运行应用程序? 我添加了这个内容的Procfile: web: node ./build/server.js

heroku日志输出如下:

 2017-01-02T16:57:54.655686+00:00 heroku[web.1]: State changed from crashed to starting 2017-01-02T16:57:58.721166+00:00 heroku[web.1]: Starting process with command `node ./build/server.js` 2017-01-02T16:58:00.987643+00:00 heroku[web.1]: Process exited with status 1 2017-01-02T16:58:00.995852+00:00 heroku[web.1]: State changed from starting to crashed 2017-01-02T16:58:00.997060+00:00 heroku[web.1]: State changed from crashed to starting 2017-01-02T16:58:00.833548+00:00 app[web.1]: module.js:471 2017-01-02T16:58:00.833561+00:00 app[web.1]: throw err; 2017-01-02T16:58:00.833562+00:00 app[web.1]: ^ 2017-01-02T16:58:00.833563+00:00 app[web.1]: 2017-01-02T16:58:00.833564+00:00 app[web.1]: Error: Cannot find module '/app/build/server.js' 2017-01-02T16:58:00.833565+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15) 2017-01-02T16:58:00.833566+00:00 app[web.1]: at Function.Module._load (module.js:417:25) 2017-01-02T16:58:00.833567+00:00 app[web.1]: at Module.runMain (module.js:604:10) 2017-01-02T16:58:00.833567+00:00 app[web.1]: at run (bootstrap_node.js:394:7) 2017-01-02T16:58:00.833568+00:00 app[web.1]: at startup (bootstrap_node.js:149:9) 2017-01-02T16:58:00.833569+00:00 app[web.1]: at bootstrap_node.js:509:3 2017-01-02T16:58:07.230342+00:00 heroku[web.1]: Starting process with command `node ./build/server.js` 2017-01-02T16:58:10.416437+00:00 heroku[web.1]: State changed from starting to crashed 2017-01-02T16:58:10.398239+00:00 heroku[web.1]: Process exited with status 1 2017-01-02T16:58:10.271567+00:00 app[web.1]: module.js:471 2017-01-02T16:58:10.271583+00:00 app[web.1]: throw err; 2017-01-02T16:58:10.271584+00:00 app[web.1]: ^ 2017-01-02T16:58:10.271584+00:00 app[web.1]: 2017-01-02T16:58:10.271585+00:00 app[web.1]: Error: Cannot find module '/app/build/server.js' 2017-01-02T16:58:10.271586+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:469:15) 2017-01-02T16:58:10.271586+00:00 app[web.1]: at Function.Module._load (module.js:417:25) 2017-01-02T16:58:10.271587+00:00 app[web.1]: at Module.runMain (module.js:604:10) 2017-01-02T16:58:10.271588+00:00 app[web.1]: at run (bootstrap_node.js:394:7) 2017-01-02T16:58:10.271588+00:00 app[web.1]: at startup (bootstrap_node.js:149:9) 2017-01-02T16:58:10.271588+00:00 app[web.1]: at bootstrap_node.js:509:3 

要完成所有的信息,我的gitlab-ci内容:

 image: node:latest stages: - deploy before_script: - npm install deploy: stage: deploy only: - master script: - npm run build -- --release - apt-get update -yq - apt-get install ruby-dev rubygems -y - gem install dpl - dpl --provider=heroku --app=nice-app --api-key=$HEROKU_API_KEY 

请帮帮我! 谢谢!

更新:

我的文件夹结构如下所示:

 ├── /build/ │ ├── /content/ │ ├── /public/ │ ├── /assets.js │ ├── /package.json │ ├── /server.js ├── /docs/ ├── /node_modules/ ├── /public/ ├── /src/ │ ├── /components/ │ ├── /core/ │ ├── /data/ │ ├── /routes/ │ ├── /client.js │ ├── /config.js │ └── /server.js ├── /test/ ├── /tools/ └── package.json 

根package.json的内容如下所示:

 { "private": true, "engines": { "node": ">=6.5", "npm": ">=3.10" }, "dependencies": { ... }, "devDependencies": { ... }, "babel": { "presets": [ "react", "node5", "stage-0" ], "env": { "test": { "plugins": [ "rewire" ] } } }, "eslintConfig": { "parser": "babel-eslint", "extends": "airbnb", "globals": { "__DEV__": true }, "env": { "browser": true }, "rules": { "arrow-parens": "off", "generator-star-spacing": "off", "import/extensions": "off", "import/no-extraneous-dependencies": "off", "react/forbid-prop-types": "off", "react/jsx-filename-extension": "off", "react/no-danger": "off", "react/no-unused-prop-types": "off" } }, "stylelint": { "extends": "stylelint-config-standard", "rules": { "string-quotes": "single", "property-no-unknown": [ true, { "ignoreProperties": [ "composes" ] } ], "selector-pseudo-class-no-unknown": [ true, { "ignorePseudoClasses": [ "global", "local" ] } ] } }, "scripts": { "lint:js": "eslint src tools", "lint:css": "stylelint \"src/**/*.{css,less,scss,sss}\"", "lint": "npm run lint:js && npm run lint:css", "test": "mocha \"src/**/*.test.js\" --require test/setup.js --compilers js:babel-register", "test:watch": "npm run test -- --reporter min --watch", "clean": "babel-node tools/run clean", "copy": "babel-node tools/run copy", "bundle": "babel-node tools/run bundle", "build": "babel-node tools/run build", "deploy": "babel-node tools/run deploy", "render": "babel-node tools/run render", "start": "babel-node tools/run start" } } 

而build文件夹中的package.json如下所示:

 { "private": true, "engines": { "node": ">=6.5", "npm": ">=3.10" }, "dependencies": { ... }, "scripts": { "start": "node server.js" } } 

所以你可以在gitlab YAML文件中定义工件。 这允许您从构build阶段传递构build的文件。

 artifacts: paths: - node_modules/ - build/ 

像这样。 然而,当你把它传递给heroku的dpl库的时候,我发现它不会推送工件(仍然值得一提,因为你可以把构build阶段工件传递给testing阶段等)。

我使用节点应用程序做的事情是在package.json添加一个"postinstall"脚本npm install完成后, npm install运行这个脚本。

我不知道为什么你有两个package.json文件与你的生成文件夹中的一个。 您只能使用项目根目录中的一个,并添加这些脚本

 "scripts": { "start": "node build/server.js", "postinstall": "npm run build" "dev": "babel-node tools/run start", "build": "babel-node tools/run build" } 

Heroku会在运行npm run build后自动运行npm run build ,如果你愿意,你可以在postinstall中链接多个。

“postinstall”:“npm run lint && npm run build”不知道你是否想在build中保留,如果linter返回一个问题,但你希望得到的想法。

我目前正在努力与传递文物herokuangular度。 如果我解决这个问题,我会回来评论