docker - 在构建期间安装 NPM 失败 Docker 构建
问题描述
我正在尝试让 GitLab CI 运行程序从 Docker 映像构建我的项目并在构建过程中安装 NPM 包。我的.gitlab-ci.yml
文件受到这个主题Gitlab CI with Docker and NPM的启发,其中 PO 正在处理相同的问题:
image: docker:stable
services:
- docker:dind
stages:
- build
cache:
paths:
- node_modules/
before_script:
- export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1
compile:
image: node:8
stage: build
script:
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
- docker-compose up -d
- docker-compose exec -T users python manage.py recreate_db
- docker-compose exec -T users python manage.py seed_db
- npm install
- bash test.sh
after_script:
- docker-compose down
可悲的是,该解决方案效果不佳,但我觉得我现在更接近实际解决方案。我在构建过程中遇到两个错误:
/bin/bash: line 89: apk: command not found
Running after script...
$ docker-compose down
/bin/bash: line 88: docker-compose: command not found
我该如何解决这个问题?
编辑:
image: docker:stable
services:
- docker:dind
stages:
- build
- test
before_script:
- export REACT_APP_USERS_SERVICE_URL=http://127.0.0.1
compile:
stage: build
script:
- apk add --no-cache py-pip python-dev libffi-dev openssl-dev gcc libc-dev make
- pip install docker-compose
- docker-compose up -d
- docker-compose exec -T users python manage.py recreate_db
- docker-compose exec -T users python manage.py seed_db
testing:
image: node:alpine
stage: test
script:
- npm install
- bash test.sh
after_script:
- docker-compose down
我将测试移到testing
了无论如何我都应该完成的单独阶段,并且我认为我已经在那里定义了图像以将其与构建阶段分开。没变。找不到 Docker,也无法运行 bash 测试:
$ bash test.sh
/bin/sh: eval: line 87: bash: not found
Running after script...
$ docker-compose down
/bin/sh: eval: line 84: docker-compose: not found
解决方案
image: node:8
此图像不是基于 alpine,因此,您得到了错误
apk:找不到命令
node:<version>
这些是Debian 发行版的套件代码名称,并指示映像基于哪个发行版。如果您的映像需要安装映像附带的任何其他软件包,您可能需要明确指定其中之一,以在有新版本Debian时最大限度地减少损坏。
只需将图像替换为
node:alpine
它应该可以工作。
第二个错误是因为未安装 docker-compose。
您可以查看此答案以获取有关作曲家的更多详细信息。
推荐阅读
- simulink - 在 Simulink 中,使用 inport 为楼梯生成器输入数据,以便作为 FMU 模块执行
- python-requests - 拉格朗日多项式
- ios - 如何在 IOS Swift 上实现画中画 Webview?
- java - 如何在不破坏当前代码的情况下修复错误“此方法必须返回 int 类型的结果”?
- azure - 如何通过 Azure 应用程序的网关将密钥传递给服务应用程序?
- node.js - 在 Google 帐户上使用“不太安全的应用程序”是否有限制?
- java - OpenCSV:读取 CSV 时方法返回 null
- android - 在 MainActivity 中创建和访问 BroadcastReceiver 的正确方法?(科特林)
- java - 错误:您是否在 AndroidManifest.xml 中声明了此活动?尝试上课时
- c++ - 将任何基数(2-9)转换为十进制的 C++ 程序