Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab pipeline with embedded mongodb

I'm trying to build a pipeline for a gradle java app which is using an embedded mongo instance. I have built a container to which has java and mongo. However, I keep getting the following error for all my test that require the embedded mongo instance.

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

My gitlab-ci.yml looks like this:

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

The build job works fine, the test job fails. My explorer-ci container is built using the following 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"]

I've spent a week with a bunch of different configs but can't seem to hack it. Just to note, builds/tests run fine on my local machine. Any ideas of what I'm doing wrong?

like image 865
I. Kirilov Avatar asked Mar 26 '18 13:03

I. Kirilov


1 Answers

On reflection, as I am using an embedded mongo instance, I do not have a dependency on mongodb to build or test. I am now using the following gitlab-ci.yaml and it works fine.

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
like image 74
I. Kirilov Avatar answered Sep 18 '22 18:09

I. Kirilov