2017-01-02 66 views
1

我試圖幾個小時,現在都留下不知道......也許你有一些:-)Herkoku節點部署與子文件夾

我用react-starter-kit作爲我的反應,應用程序和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慈內容:

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 

請幫幫我!謝謝!

UPDATE:

我的文件夾結構如下:

根的package.json的
├── /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 

內容是這樣的:

{ 
    "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" 
    } 
} 
+0

你可以分享你的文件夾結構和你的package.json嗎? –

+0

我已將您的請求數據更新爲我的帖子。希望它提前幫助和感謝。 – cqueiser

回答

1

因此,您可以在gitlab YAML文件中定義工件。這允許您從舞臺到舞臺傳遞構建的文件。

artifacts: 
    paths: 
    - node_modules/ 
    - build/ 

像這樣。然而,當你將它傳遞給heroku的dpl庫時,我發現它不會推送工件(仍然值得一提,因爲你可以將構建階段工件傳遞到測試階段等)。

我對節點應用程序所做的操作是將"postinstall"腳本添加到package.json npm在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 install你可以將多個在一起後,以及如果你願意的話。

「postinstall」:「npm run lint & & npm run build」如果linter返回問題,但您希望得到想法,不知道是否要在構建上保釋。

我目前正在努力與傳遞文物heroku角度。如果我解決這個問題,我會回來評論

+0

我得到它的工作原來,你可以添加多個圖像到每個階段。因此,例如,您可以在部署階段使用紅寶石圖像。我從構建階段部署工件的方式是刪除.gitignore,然後添加所有工件,提交然後推送到heroku,如https://gist.github.com/maxmckenzie/7b838d2acb4188d3129f4578bdf36a32 – xam