我现在已经尝试了几个小时并且不知道离开......也许你有一些:-)
我使用react-starter-kit作为我的react-app和gitlab作为我的存储库。我已启用gitlab-ci
部署并将我的应用发送到heroku。
好的,gitlab-ci
有效...... 是啊
但是react-starter-kit使用/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
root 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 :(得分:1)
因此,您可以在gitlab YAML文件中定义工件。这允许您将构建的文件从一个阶段传递到另一个阶段。
artifacts:
paths:
- node_modules/
- build/
像这样。但是,当你将它传递给doku库以获取heroku时,我发现它不会推送工件(仍然值得一提,因为你可以将构建阶段的工件传递到测试阶段等)。
我对节点应用程序的操作是在"postinstall"
之后添加package.json
脚本npm在npm install
完成后运行此脚本。
我不确定你为什么在build文件夹中有两个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"不知道你是否想要在建筑物上保释,如果这个问题可以解决问题,但你有希望得到这个想法。
我目前正在努力将过往的文物转移到heroku角度。如果我解决这个问题,我会回来发表评论