嵌入mongodb的gitlab管道

问题描述 投票:5回答:2

我正在尝试为使用嵌入式mongo实例的gradle java应用程序构建管道。我已经构建了一个容器,其中包含java和mongo。但是,对于需要嵌入式mongo实例的所有测试,我一直收到以下错误。

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'embeddedMongoServer' 
defined in class path resource [org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.class]: 
Invocation of init method failed; nested exception is java.io.IOException: 
Cannot run program "/tmp/extract-f816c11c-614b-46d7-ad29-68923ca9d624extractmongod": error=2, No such file or directory

我的gitlab-ci.yml看起来像这样:

image: java:latest
services:
  - docker:dind

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"
  DOCKER_DRIVER: overlay
  SPRING_PROFILES_ACTIVE: gitlab-ci

stages:
  - build
  - test

build:
  stage: build
  script: ./gradlew --build-cache assemble
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - build
      - .gradle

test:
  stage: test
  image: registry.gitlab.com/path/to/explorer-ci:1.0.0
  script: ./gradlew check --debug
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: pull
    paths:
      - build
      - .gradle

构建作业正常,测试作业失败。我的explorer-ci容器是使用以下Dockerfile构建的

FROM openjdk:8-jdk-alpine

RUN apk update && \
    apk add --no-cache \
        mongodb \
        bash

VOLUME /data/db
VOLUME log

RUN ["mongod", "--smallfiles", "--fork", "--logpath", "log/mongodb.log"]

我用一堆不同的配置花了一个星期,但似乎无法破解它。请注意,构建/测试在我的本地计算机上运行良好。我做错了什么想法?

mongodb gitlab gitlab-ci
2个回答
2
投票

经过反思,当我使用嵌入式mongo实例时,我没有依赖mongodb来构建或测试。我现在使用以下gitlab-ci.yaml,它工作正常。

image: openjdk:8-jdk

variables:
  GRADLE_OPTS: "-Dorg.gradle.daemon=false"
  DOCKER_DRIVER: overlay
  SPRING_PROFILES_ACTIVE: gitlab-ci

stages:
  - build
  - test

build:
  stage: build
  script: ./gradlew --build-cache assemble
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: push
    paths:
      - build
      - .gradle

test:
  stage: test
  script: ./gradlew check
  cache:
    key: "$CI_COMMIT_REF_NAME"
    policy: pull
    paths:
      - build
      - .gradle

0
投票

只需更新依赖项即可解决:

<dependency>
    <groupId>de.flapdoodle.embed</groupId>
    <artifactId>de.flapdoodle.embed.mongo</artifactId>
    <version>2.2.0</version>
    <scope>test</scope>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.