Init mocks on Docker startup#222
Conversation
|
This looks great. Any word on a review and merge status? |
|
Any updates on this or why it isn't considered? |
|
This would really be useful. Any updates on this? Thank you. |
|
Implemented in #331: the new # docker-compose
services:
smocker:
image: ghcr.io/smocker-dev/smocker
environment:
SMOCKER_INIT_MOCKS: /mocks/init.yml
volumes:
- ./mocks.yml:/mocks/init.yml:roIt's read-only (never written back) and mutually exclusive with Available in the next preview build. Closing as addressed. |
Purpose
There are a few active discussions on being able to initialize mocks or configure Smocker on startup (#217, #214) and this is another proposed approach.
This only applies to Docker-based workflows, but the implementation is more straightforward without touching the actual core codebase.
Approach
The main idea is using an Entrypoint script to start the server process in the background, run some configuration code, then restore the process to the foreground. This pattern is described in the official Docker docs. It's also used in practice in postgres, mysql, localstack etc.
Note:
bashneeds to be used instead of the default bourne shell in alpine because of some issues when attempting to work with background jobs. If you change the Entrypoint shebang to#!/bin/sh, there will be an error.