GitLab AutoDevops环境问题

时间:2019-12-23 17:59:31

标签: gitlab google-kubernetes-engine devops gitlab-ci pipeline

因此,我刚从Travis和Github转到Gitlab Autodevops。我当前面临的问题是,当我进行推送并启动管道时,它看不到任何列表环境变量。我设置了生产,并测试了mongodb和redis的环境变量,但是在管道中,它试图同时连接到localhost,而完全忽略了CI / CD设置中设置的环境变量。参见下面的图片:

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

我需要有关如何确保测试管道正在使用我设置的环境变量的帮助;并且不尝试连接失败的本地主机。

Error on gitlab pipeline

Variables in Gitlab

GKE which is running fine

1 个答案:

答案 0 :(得分:0)

您可以使用shell runner代替dockerRunner,然后在脚本之前调用docker-compose。

cache:
  paths:
    - node_modules/

job:
  before_script:
    - docker-compose up -d
  script:
    - npm i
    - npm test
  after_script:
    - docker-compose down