Build container then run tests with docker-compose & node

nodejs
docker
postgresql
circle.yml

#1

Hello,

I am trying to run tests on my project within a container through docker compose. However, after building my image with docker-compose build command if I run a command with docker-compose run the container seems empty. However, it works perfectly on my local computer.

I am new at circleci & docker maybe I am missing something?!

Thanks a lot!

Here is my Dockerfile:

FROM node:8

RUN mkdir -p /app
WORKDIR /app

COPY package.json /app/
COPY yarn.lock /app/
RUN yarn install

COPY . /app

EXPOSE 3000
CMD [ "yarn", "start" ]

my docker-compose-test.yml

version: '2'
services:
  postgres:
    image: "postgres:alpine"
    environment:
      POSTGRES_PASSWORD: pass
      POSTGRES_USER: postgres
  test:
    build: .
    ports:
      - "3000:3000"
    volumes:
      - .:/app
    depends_on:
      - postgres
    environment:
      DATABASE_URL: postgres://postgres:pass@postgres:5432/postgres
    command: 'true'

my cyrcleci config

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:latest
    working_directory: ~/app
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Install docker-compose
          command: |
            set -x
            curl -L https://github.com/docker/compose/releases/download/1.8.0/docker-compose-`uname -s`-`uname -m` > ~/docker-compose
            chmod +x ~/docker-compose
            sudo mv ~/docker-compose /usr/local/bin/docker-compose
      - run:
          name: Build image
          working_directory: ~/app/server
          command: |
            set -x
            docker-compose -f docker-compose-test.yml build
      - run:
          name: Run tests
          working_directory: ~/app/server
          command: |
            set -x
            docker-compose -f docker-compose-test.yml run test yarn run test

And here is the output of the last step

#!/bin/bash -eo pipefail
set -x
docker-compose -f docker-compose-test.yml run test yarn run test
+ docker-compose -f docker-compose-test.yml run test yarn run test
Creating network "server_default" with the default driver
Pulling postgres (postgres:alpine)...
alpine: Pulling from library/postgres
Digest: sha256:fff2f8260771e3e872f82e02d814a06fef6c0b844cd2a22affb49a61b2aa48c0

Status: Downloaded newer image for postgres:alpine

Creating server_postgres_1
yarn run v1.0.2
error Couldn't find a package.json file in "/app"
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Exited with code 1

#2

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.