I’ve got a vanilla Node.js project using docker-compose, and I’m trying to run my tests via mocha in the container. This works fine for me locally, but fails on CircleCI.
Relevant files:
Dockerfile:
FROM node:10.10.0-alpine
RUN apk update && apk add --no-cache build-base postgresql-dev
RUN mkdir -p /opt/my-service
WORKDIR /opt/my-service
COPY package*.json ./
RUN npm install
COPY . ./
CMD npm start
docker-compose.yml:
version: '3'
services:
my-service-postgres:
image: 'postgres:9.6-alpine'
environment:
POSTGRES_DB: 'postgres'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
volumes:
- './initdb.sql:/docker-entrypoint-initdb.d/initdb.sql'
- './db/data:/var/lib/postgresql/data'
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 10s
retries: 6
my-service-redis:
image: 'redis:4.0-alpine'
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 10s
timeout: 10s
retries: 6
my-service-api:
image: node:10.10.0-alpine
depends_on:
- my-service-postgres
- my-service-redis
build: .
ports:
- '3000:3000'
volumes:
- '.:/opt/my-service'
env_file:
- '.env'
restart: on-failure
.circleci/config.yml:
version: 2
jobs:
build:
machine:
image: circleci/classic:201711-01
working_directory: ~/my-service
steps:
- run:
name: Install required software
command: |
sudo apt-get install -y git python3 curl python-pip
- checkout
- run:
name: Install awscli
command: |
pip install awscli --upgrade --user
- run:
name: Run tests
command: |
$(~/.local/bin/aws ecr get-login --no-include-email)
docker-compose -p tests run -e "NODE_ENV=test" my-service-api npm test
When I run locally:
docker-compose -p tests run -e "NODE_ENV=test" my-service-api npm test
Starting tests_my-service-redis_1 ... done
Starting tests_my-service-postgres_1 ... done
> my-service@1.0.0 test /opt/my-service
> mocha
GET /health
✓ responds with a 200 status (40ms)
✓ responds with "application/json; charset=utf-8" content type
✓ responds with a json response body
3 passing (65ms)
When run in CircleCI build:
> my-service@1.0.0 test /opt/my-service
> mocha
sh: mocha: not found
npm ERR! Test failed. See above for more details.
Exited with code 1
What am I doing wrong?