我一直在尝试使用共享跑步者设置 gitlab ci。我的 .gitlab-ci.yml 看起来像这样:
image: docker:latest
# When using dind, it's wise to use the overlayfs driver for
# improved performance.
variables:
DOCKER_DRIVER: overlay2
GCP_PROJECT_ID: example-12345
IMAGE_NAME: test
services:
- docker:dind
stages:
- publish
publish-image:
stage: publish
script:
# Create our image. Expected to create an image 'image_id'
- docker build -t $IMAGE_NAME .
# Tag our image for container registry
- docker tag $IMAGE_NAME eu.gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME
# Install CA certs, openssl to https downloads, python for gcloud sdk
- apk add --update make ca-certificates openssl python
- update-ca-certificates
# Download and install Google Cloud SDK
- wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz
- tar zxvf google-cloud-sdk.tar.gz && ./google-cloud-sdk/install.sh --usage-reporting=false --path-update=true
- google-cloud-sdk/bin/gcloud --quiet components install kubectl
- google-cloud-sdk/bin/gcloud --quiet components update
- google-cloud-sdk/bin/gcloud auth activate-service-account --key-file g.json
# Optionally tag the image with the commit short-sha
- docker tag $IMAGE_NAME eu.gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-8)
#- google-cloud-sdk/bin/gcloud docker -- push eu.gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME:latest
- google-cloud-sdk/bin/gcloud docker -- push eu.gcr.io/$GCP_PROJECT_ID/$IMAGE_NAME:$(echo $CI_COMMIT_SHA | cut -c1-8)
# Only run builds for these refs
only:
- master
我正在尝试构建的项目是应该在 kubernetes 集群中运行的 Meteor 应用程序(Meteor 版本 1.6.1)。为了创建容器,我使用https://github.com/jshimko/meteor-launchpad。当我在本地机器上使用 docker build 时,一切正常,但是在 CI 中出现此错误(在 build in stage 之后Running npm install in the server bundle...
):
> node-pre-gyp install --fallback-to-build
module.js:540
throw err;
^
Error: Cannot find module '../'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/opt/meteor/dist/bundle/programs/server/npm/node_modules/.bin/node-pre-gyp:15:20)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! bcrypt@1.0.3 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the bcrypt@1.0.3 install 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! /root/.npm/_logs/2018-03-08T13_29_09_532Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! meteor-dev-bundle@ install: `node npm-rebuild.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the meteor-dev-bundle@ install 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! /root/.npm/_logs/2018-03-08T13_29_09_574Z-debug.log
但我不相信这是一个实际的流星问题,因为我知道代码有效。另一个奇怪的事情是,在运行流星 1.5.2.2(新版本是 1.6.1)的旧版本代码中构建实际上是成功的,但是在 kubernetes 中运行时它会中断。来自 pod 的错误显示为:
=> Starting app on port 3000...
## There is an issue with `node-fibers` ##
`/opt/meteor/dist/bundle/programs/server/node_modules/fibers/bin/linux-x64-57/fibers.node` is missing.
Try running this to fix the issue: /opt/nodejs/bin/node /opt/meteor/dist/bundle/programs/server/node_modules/fibers/build
/opt/meteor/dist/bundle/programs/server/node_modules/fibers/fibers.js:20
throw new Error('Missing binary. See message above.');
^
Error: Missing binary. See message above.
at Object.<anonymous> (/opt/meteor/dist/bundle/programs/server/node_modules/fibers/fibers.js:20:8)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
忽略运行器状态的构建日志:
> fibers@1.0.15 install /opt/meteor/dist/bundle/programs/server/node_modules/fibers
> node build.js || nodejs build.js
`linux-x64-46` exists; testing
Binary is fine; exiting
因为我知道构建可以成功,所以我假设 docker-in-docker 在共享运行器上使用正确的设置运行。通过运行特权将外部 docker 套接字绑定到内部 och (如此处和此处所述)
那么为什么我的构建会在 CI 上损坏/失败?
编辑:我的本地构建是在 ubuntu 16 上完成的