I'm setting up Gitlab CI docker-in-docker for a project. Unfortunately the job keeps failing because installed NPM packages can't seem to be found when running commands. The error I'm getting:
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
The curious thing is that it does work when I run docker-compose manually without using the Gitlab CI. This is what my .gitlab-ci.yml looks like:
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
This is my 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
And this is the 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 ./ ./
I expect the installed packages and their commands to be available in the docker container. At some point they worked, and I have no clue what changed in the configuration to cause this issue.
I am not expecting a copy/paste solution from you guys, but I do hope you can point me in the right direction to properly get to the root of this issue.