首页 > 解决方案 > 带有猫鼬的 GitLab CI Job NestJS 服务

问题描述

我正在尝试为 Gitlab Continuos 集成范围内的简单后端 NestJS 项目配置gitlab - ci.yml文件,该项目具有与 MongoDB 数据库保持一致的服务。

我也有一个角度客户端,之前我在 Gitlab 上正确安装了该客户端,我可以通过公共 GitLab 站点访问它。

在此处输入图像描述

我将这个gitlab-ci.yml文件用于后端项目。

image: node:14.15.0

stages:
  - install
  - test
  - build
  - deploy

install:
  stage: install
  script: 
- npm install
  artifacts:
expire_in: 1h
paths:
  - node_modules/
  cache:
paths:
  - node_modules/

tests:
  stage: test
  dependencies:
- install
  script:
- npm run test:ci
  coverage: '/Statements.*?(\d+(?:\.\d+)?)%/'

build:
  stage: build
  variables:
BUILD_CONFIG: 'production'
  dependencies:
- install
  script:
- npm run build
  artifacts:
expire_in: 1h
paths:
  - dist/
  only:
- master

pages:
  stage: deploy
  dependencies:
- build
  script:
- npm i -g @nestjs/cli
- npm install
- nest start
  artifacts:
paths:
  - public/
  environment:
name: production
  only:
- master

此文件成功执行“安装、测试和构建”阶段,但在部署阶段失败,请参见图像。

在此处输入图像描述

正如您在启动后看到的那样,它尝试连接到 MongoDB 数据库并失败。

部署阶段,我安装了NestJs模块并启动它,但我认为这不正确,正确的方法是为 NestJs 和 MongoDB 使用 Docker 映像,但我真的不知道如何在 GitLab 方面做到这一点。

所以我很感激任何帮助。

标签: dockercontinuous-integrationgitlabnestjspipeline

解决方案


推荐阅读