我正在为项目设置Gitlab CI docker-in-docker。不幸的是,该作业一直失败,因为在运行命令时似乎找不到已安装的NPM软件包。我收到的错误:
backend_1 |
backend_1 | > tacta-backend@0.0.1 build /app
backend_1 | > tsc
backend_1 |
backend_1 | sh: tsc: not found
backend_1 | npm ERR! file sh
backend_1 | npm ERR! code ELIFECYCLE
backend_1 | npm ERR! errno ENOENT
backend_1 | npm ERR! syscall spawn
backend_1 | npm ERR! tacta-backend@0.0.1 build: `tsc`
backend_1 | npm ERR! spawn ENOENT
backend_1 | npm ERR!
backend_1 | npm ERR! Failed at the tacta-backend@0.0.1 build script.
backend_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
backend_1 |
backend_1 | npm ERR! A complete log of this run can be found in:
backend_1 | npm ERR! /root/.npm/_logs/2019-08-02T04_46_04_881Z-debug.log
奇怪的是,当我手动运行docker-compose而不使用Gitlab CI时,它确实起作用。这是我的.gitlab-ci.yml的样子:
build:
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
image: docker:18
stage: build
services:
- docker:18-dind
before_script:
- docker info
- apk add python-dev libffi-dev openssl-dev gcc libc-dev make
- apk add py-pip
- pip install docker-compose
script:
- docker-compose -f docker-compose.yml -f docker-compose.prod.yml up
这是我的docker-compose.yml:
version: '3'
services:
frontend:
build:
context: ./frontend
args:
NODE_ENV: production
PGUSER: ${PGUSER}
PGHOST: ${PGHOST}
PGPASSWORD: ${PGPASSWORD}
PGDATABASE: ${PGDATABASE}
PGPORT: ${PGPORT}
DATABASE_URL: ${DATABASE_URL}
command: npm run build
ports:
- "9000:9000"
volumes:
- /app/node_modules
- ./frontend:/app
backend:
build:
context: ./backend
args:
NODE_ENV: production
command: npm run build
ports:
- "3000:3000"
volumes:
- /app/node_modules
- ./backend:/app
这是Dockerfile:
FROM node:11.10.1-alpine
ARG NODE_ENV
ARG PGUSER
ARG PGHOST
ARG PGPASSWORD
ARG PGDATABASE
ARG PGPORT
ARG DATABASE_URL
ENV NODE_ENV ${NODE_ENV}
ENV PGUSER ${PGUSER}
ENV PGHOST ${PGHOST}
ENV PGPASSWORD ${PGPASSWORD}
ENV PGDATABASE ${PGDATABASE}
ENV PGPORT ${PGPORT}
ENV DATABASE_URL ${DATABASE_URL}
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY ./ ./
我希望已安装的软件包及其命令在docker容器中可用。在某些时候它们可以工作,我不知道配置中的更改会导致此问题。
我期望你们不会提供复制/粘贴解决方案,但我希望您能指出正确的方向,以正确解决此问题的根源。
答案 0 :(得分:0)
问题是我从NODE_ENV: development
切换到NODE_ENV: production
。在我的package.json中启用了生产devDependencies
的情况下,将不再安装json(不是我)。
我在常规dependencies
中添加了打字稿和webpack,现在又像魅力一样工作了。