Autotesting docker images with docker-compose.test : missing environment variables

Viewed 174

I have a Node/Express app and I am using https://www.npmjs.com/package/dotenv-safe to include environment variables for dev and testing. I am pushing my Docker repository to https://cloud.docker.com/app/gkatsanos/ and during AutoTesting (I have a docker-compose.test.yml), It seems that the environment variables are not found:

 Successfully built 69f35563f12e
Successfully tagged gkatsanos/server:latest
Starting Test in docker-compose.test.yml...
Building sut
Step 1/10 : FROM node:8-alpine
---> 4db2697ce114
Step 2/10 : EXPOSE 3000
---> Using cache
---> ef9e0a8a09e1
Step 3/10 : ARG NODE_ENV
---> Using cache
---> cc6143bf9bee
Step 4/10 : ENV NODE_ENV $NODE_ENV
---> Using cache
---> 6477a9e9657f
Step 5/10 : RUN mkdir /app
---> Using cache
---> e9fff66cf3da
Step 6/10 : WORKDIR /app
---> Using cache
---> da82362255c6
Step 7/10 : ADD package.json yarn.lock seed.js /app/
---> Using cache
---> 97a842faeb2a
Step 8/10 : RUN yarn --pure-lockfile
---> Using cache
---> 6745c0d8c64c
Step 9/10 : ADD . /app
---> Using cache
---> 06d46eb4a57b
Step 10/10 : CMD yarn start
---> Using cache
---> 69f35563f12e
Successfully built 69f35563f12e
Successfully tagged b5wqkysdhyuqf8uz4kyreyn_sut:latest
Creating network "b5wqkysdhyuqf8uz4kyreyn_default" with the default driver
Creating b5wqkysdhyuqf8uz4kyreyn_sut_1 ...
Creating b5wqkysdhyuqf8uz4kyreyn_sut_1
Creating b5wqkysdhyuqf8uz4kyreyn_sut_1 ... done
yarn run v1.3.2
$ NODE_ENV=test nyc --reporter=html --reporter=text mocha --timeout 20000 --recursive src/tests
/app/node_modules/dotenv-safe/index.js:37
throw new MissingEnvVarsError(allowEmptyValues, options.path || '.env', sample, missing, dotenvResult.error);

Locally the docker building and running works.

That's my dockerfile:

FROM node:8-alpine

EXPOSE 3000

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

RUN mkdir /app
WORKDIR /app
ADD package.json yarn.lock seed.js /app/
RUN yarn --pure-lockfile
ADD . /app

CMD ["yarn", "start"]

and my docker-compose.test.yml:

version: "3"
services:
  sut:
    build: .
    command: yarn test

By the way, cloud.docker.com has a place in its UI that allows for environment variables to be added:

enter image description here

0 Answers
Related