Google Cloud Builder-vuejs,gulp构建失败

时间:2018-06-28 23:35:16

标签: vue.js gulp continuous-integration continuous-deployment google-container-registry

问题

我正在努力为当前的功能性构建流程添加几个附加的构建步骤。问题在于,在编译JavaScript时,gulp无法找到模块。在下面,您将找到我们cloudbuild.yaml的相关部分以及bash脚本。

预期结果

我需要处理Vue.js和SCSS,并准备将其部署到我们的生产环境中。总体而言,我们的目标是从Git存储库中删除已转译的JS和CSS,并且仅将与我们一起使用的源存储在仓库中。

支持代码

cloudbuild.yaml:

- name: 'gcr.io/cloud-builders/npm:node-9.10.0'
  id: npm-install
  entrypoint: 'bash'
  args:
    - '-c'
    - |
      sh nodeprep.sh
  waitFor: ['-']

- name: 'gcr.io/cloud-builders/npm:node-9.10.0'
  id: gulp-build
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
      sh gulpprep.sh
  waitFor: ['npm-install']

nodeprep.sh:

#!/bin/bash
npm install --production
npm rebuild node-sass --force # necessary to resolve architecture differences

gulpprep.sh

#!/bin/bash
node_modules/.bin/gulp deploy-build --production

错误

根据--production标志,我们会收到不同的错误。这是我们在--production中设置了nodeprep.sh标志的情况下收到的错误:

: events.js:165
:       throw er; // Unhandled 'error' event
:       ^
: 
: Error: Cannot find module 'Axios' from '/workspace/js/vue-mini-apps/ha/src'
:     at /workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:46:17
:     at process (/workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:173:43)
:     at ondir (/workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:188:17)
:     at load (/workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
:     at onex (/workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
:     at /workspace/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
:     at FSReqWrap.oncomplete (fs.js:170:21)
: Emitted 'error' event at:
:     at Labeled.<anonymous> (/workspace/node_modules/read-only-stream/index.js:28:44)
:     at Labeled.emit (events.js:180:13)
:     at Labeled.<anonymous> (/workspace/node_modules/stream-splicer/index.js:130:18)
:     at Labeled.emit (events.js:180:13)
:     at Deps.<anonymous> (/workspace/node_modules/stream-splicer/index.js:130:18)
:     at Deps.emit (events.js:180:13)
:     at /workspace/node_modules/module-deps/index.js:361:30
:     at onresolve (/workspace/node_modules/module-deps/index.js:179:25)
:     at /workspace/node_modules/browserify/index.js:490:22
:     at /workspace/node_modules/browser-resolve/index.js:265:24
2018/06/28 14:39:32 status changed to "ERROR"
ERROR
ERROR: build step "gcr.io/cloud-builders/npm@sha256:43d8b9b86f899f5622a668c7d7ad7493a323740440cf79089953cddc17a4ad2a" failed: exit status 1
2018/06/28 14:39:35 Build finished with ERROR status

这是删除--production时的输出:

Step #1 - "gulp-build": Already have image (with digest): gcr.io/cloud-builders/npm:node-9.10.0
Starting Step #1 - "gulp-build"
Step #1 - "gulp-build": module.js:545
Step #1 - "gulp-build":     throw err;
Step #1 - "gulp-build":     ^
Step #1 - "gulp-build": 
Step #1 - "gulp-build": Error: Cannot find module '../lib/completion'
Step #1 - "gulp-build":     at Function.Module._resolveFilename (module.js:543:15)
Step #1 - "gulp-build":     at Function.Module._load (module.js:470:25)
Step #1 - "gulp-build":     at Module.require (module.js:593:17)
Step #1 - "gulp-build":     at require (internal/module.js:11:18)
Step #1 - "gulp-build":     at Object.<anonymous> (/workspace/node_modules/.bin/gulp:13:18)
Step #1 - "gulp-build":     at Module._compile (module.js:649:30)
Step #1 - "gulp-build":     at Object.Module._extensions..js (module.js:660:10)
Step #1 - "gulp-build":     at Module.load (module.js:561:32)
Step #1 - "gulp-build":     at tryModuleLoad (module.js:501:12)
Step #1 - "gulp-build":     at Function.Module._load (module.js:493:3)
Finished Step #1 - "gulp-build"
2018/06/28 16:24:44 status changed to "ERROR"
ERROR
ERROR: build step "gcr.io/cloud-builders/npm@sha256:43d8b9b86f899f5622a668c7d7ad7493a323740440cf79089953cddc17a4ad2a" failed: exit status 1

node_modules移出目录将返回以下错误:

: 
: > proj@ build /workspace
: > cross-env NODE_ENV=production browserify -g envify js/vue-mini-apps/materials/app.js | uglifyjs -c warnings=false -m > js/vue-mini-apps/dist/materials.js
: 
: module.js:545
:     throw err;
:     ^
: 
: Error: Cannot find module '../dist'
:     at Function.Module._resolveFilename (module.js:543:15)
:     at Function.Module._load (module.js:470:25)
:     at Module.require (module.js:593:17)
:     at require (internal/module.js:11:18)
:     at Object.<anonymous> (/workspace/node_modules/.bin/cross-env:3:1)
:     at Module._compile (module.js:649:30)
:     at Object.Module._extensions..js (module.js:660:10)
:     at Module.load (module.js:561:32)
:     at tryModuleLoad (module.js:501:12)
:     at Function.Module._load (module.js:493:3)
: module.js:545
:     throw err;
:     ^
: 
: Error: Cannot find module '../tools/node'
:     at Function.Module._resolveFilename (module.js:543:15)
:     at Function.Module._load (module.js:470:25)
:     at Module.require (module.js:593:17)
:     at require (internal/module.js:11:18)
:     at Object.<anonymous> (/workspace/node_modules/.bin/uglifyjs:6:16)
:     at Module._compile (module.js:649:30)
:     at Object.Module._extensions..js (module.js:660:10)
:     at Module.load (module.js:561:32)
:     at tryModuleLoad (module.js:501:12)
:     at Function.Module._load (module.js:493:3)
: npm ERR! code ELIFECYCLE
: npm
:  ERR! 
: errno 1
: npm ERR! proj@ build: `cross-env NODE_ENV=production browserify -g envify js/vue-mini-apps/materials/app.js | uglifyjs -c warnings=false -m > js/vue-mini-apps/dist/materials.js`
: npm ERR! Exit status 1
: npm ERR!
:  
: npm ERR! Failed at the proj@ build script.
: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
: 
: npm ERR! A complete log of this run can be found in:
: npm ERR!     /builder/home/.npm/_logs/2018-06-28T22_33_47_659Z-debug.log

在localhost上构建成功,并且在运行以下命令时失败:

container-builder-local --config=cloudbuild.yaml --dryrun=false .

尝试(且完全失败)的解决方案

一旦此功能与container-builder-local配合使用,我将能够在GCP上对其进行测试。现在,我已经做好了一切准备工作,包括:

  • rm -rf node_modules作为nodeprep.sh
  • 中的第一个命令
  • npm cache clear只是为了确定(npm抱怨并建议npm cache verify仍然没有效果)
  • 添加npm run-script build(运行cross-env NODE_ENV=production browserify -g envify js/vue-mini-apps/materials/app.js | uglifyjs -c warnings=false -m > js/vue-mini-apps/dist/materials.js)。
  • 我什至尝试将node_modules移出项目目录,所以 npm install别无选择,只能创建一个新的node_modules目录-这导致运行npm install时根本不会安装gulp。

我对下一步该做什么感到困惑。看来我越深入这个兔子洞,这些构建步骤就越容易被破坏。

0 个答案:

没有答案