mocks-server / main

Node.js mock server running live, interactive mocks in place of real APIs
https://www.mocks-server.org
Apache License 2.0
288 stars 16 forks source link

Configure mocks-server as a gitlab "service" #460

Closed EmreCihanbeyoglu closed 1 year ago

EmreCihanbeyoglu commented 1 year ago

Hi,

This is a question, not a bug or feature. I want to run mocks server independent from application as an image in a container without having to install it as a dependency.

So I need to pass arguments (like port and volume) by means of commands instead of docker arguments.

A sample usage of services in gitlab:

services:
  - name: postgres:11.7
    alias: db
    entrypoint: ["docker-entrypoint.sh"]
    command: ["postgres"]

image:
  name: ruby:2.6
  entrypoint: ["/bin/bash"]

I am wondering how to convert docker run command

docker run -ti -p 3100:3100 -p 3110:3110 \
  -v /Users/foo/project:/input \
  mocksserver/main

into a format which fits gitlab services functionality.

Resource: https://docs.gitlab.com/ee/ci/services/#available-settings-for-services

Could you please help me with this?

EmreCihanbeyoglu commented 1 year ago

I have found a solution for this. :)

I have noticed that we are able to define environment variables specific to a service in gitlab. So configuration can be given by means of this:

  services:
    - name: mocksserver/main
      alias: mocks
      variables:
        #MOCKS_CONFIG_FILE_SEARCH_FROM: "$CI_PROJECT_DIR"
        MOCKS_SERVER_PORT: 3500
        #MOCKS_CONFIG_FILE_SEARCH_PLACES: ".mocksrc.json"
        MOCKS_FILES_PATH: "$CI_PROJECT_DIR/mocks/"
  before_script:
    - curl "http://mocks:3500/api/users"
    - curl "http://mocks:3500/api/users" | grep -q "Emre Cihan"
    - npm install
javierbrea commented 1 year ago

Hi @EmreCihanbeyoglu , thanks for sharing! 😃

And sorry for the delay in my response, I was on holidays.