So I am new to Gitlab Autodevops having switched from Travis and Github. The issue I am currently facing is that when I make a push and the pipeline kicks in, it doesn't see any of my list environment variables. I set production, and testing environment variables for mongodb and redis, but during the pipeline, it's trying to connect to localhost for both, totally ignoring the environment variables set in CI/CD settings. See pictures below:
Dockerfile
WORKDIR /app
COPY package*.json ./
RUN apk add --update alpine-sdk nodejs npm python
RUN LD_LIBRARY_PATH=/usr/local/lib64/:$LD_LIBRARY_PATH && export LD_LIBRARY_PATH && npm i
COPY . .
RUN npm run build
EXPOSE 3000
CMD ["npm", "start"]docker-compose.yml
version: "3.7"
services:
  backend:
    container_name: dash-loan
    environment:
      MONGODB_PRODUCTION_URI: ${MONGODB_PRODUCTION_URI}
      MONGODB_TEST_URI: ${MONGODB_TEST_URI}
      REDIS_PRODUCTION_URL: ${REDIS_PRODUCTION_URL}
      REDIS_TEST_URL: ${REDIS_TEST_URL}
      PM2_SECRET_KEY:  ${PM2_SECRET_KEY}
      PM2_PUBLIC_KEY: ${PM2_PUBLIC_KEY}
      PM2_MACHINE_NAME: ${PM2_MACHINE_NAME}
      PORT: ${PORT}
      MODE_ENV: ${NODE_ENV}
    restart: always
    build: .
    ports:
      - "8080:3000"
    links:
      - mongodb
      - redis
  mongodb:
    container_name: mongo
    environment:
      MONGO_INITDB_DATABASE: dashloan
      MONGO_INITDB_ROOT_USERNAME: sampleUser
      MONGO_INITDB_ROOT_PASSWORD: samplePassword
    restart: always
    image: mongo
    ports:
      - "27017-27019:27017-27019"
    volumes:
      - ./src/database/init-mongo.js:/docker-entrypoint-point.initdb.d/init-mongo.js:ro
      - ./mongo-volume:/data/db
  redis:
    container_name: redis
    restart: always
    image: redis:5.0
    ports:
      - "6379:6379"
volumes:
  mongo-volume:.gitlab-ci.yml
image: node:latest
services:
  - mongo:latest
  - redis:latest
cache:
  paths:
    - node_modules/
job:
  script:
    - npm i
    - npm test
I need help on how to make sure the test pipeline is using the environment variables I set; and not trying to connect to localhost which fails.
You could use shell runner instead of docker runner and then just call docker-compose in before script.
cache:
  paths:
    - node_modules/
job:
  before_script:
    - docker-compose up -d
  script:
    - npm i
    - npm test
  after_script:
    - docker-compose down