-
Notifications
You must be signed in to change notification settings - Fork 1
Find the nicer way to initialize off-the-shelf system in microservice architecture #236
Comments
@nutjob4life @tdddblog @ramesh-maddegoda can you write your inputs on this topics as comment in the ticket ? |
Multi-stage builds can be helpful here, letting you make an image that has not just the service but also the pre-configured data (database schema, expected records, etc.). Here's an example # Stage 1
# =======
#
# We start with the database image, in this case a hypothetical database
# called "persistence"
FROM persistenece:1.2.3 AS initialization
# Set up some defaults for this database
ENV PERSISTENCE_USERNAME="db"
ENV PERSISTENCE_PASSWORD="p455w0rd"
# This database expects initial schema to be in /var/persistence/init.d and
# initial data in /var/persistence/load.d
COPY etc/product-schema.sql etc/label-schema.sql /var/persistence/init.d/
COPY data/*.sql /var/persistence/load.d/
COPY data/blobs/ /var/persistence/load.d/lobs/
# This database has a special command-line option that tells it not to start
# up as a daemon process. Other databases may require you to modify the
# Docker entrypoint script with /usr/bin/sed or by forcing us to provde
# an alternative starutp scrupt (this turns out to be fairly common):
RUN : &&\
/usr/local/bin/persistence-entrypoint.sh --load-only /tmp/dump &&\
:
# For example, if this were Postgres, we'd do
#
# RUN : &&\
# sed --in-place --expression='s/exec \"$@\"//' /usr/local/bin/docker-entrypoint.sh &&\
# /usr/local/bin/docker-entrypoint.sh postgres &&\
# :
#
# Solr has a special command-line option like `solr-create` which does
# something similar.
# Stage 2
# =======
#
# We go back to "persistence" again
FROM persistence:1.2.3
# But this time we can copy over the service's database files
COPY --from=initialization /tmp/dump /var/persistence/db
# There's no need for `RUN rm -rf/ /tmp/dump`. It doesn't exist in this layer!
# It's only in the `initialization` layer. There's no special syntax needed to build this image; a single build command does it:
|
These are 2 approaches that I currently use to initialize Elasticsearch and RabbitMQ in docker compose. To initialize Elasticsearch,
After that, in the
With above approach, we can wait for any service (which has a post to be opened) and execute a script once the service is available. To initialize RabbitMQ,
I think similar approaches can be used to initialize any micro-service, when there is a port number to wait for available. |
Thanks @nutjob4life @ramesh-maddegoda , What @nutjob4life proposes makes us create/maintain specific images... that might be what we need, I don't know. |
We could also think of using a message broker to make the components aware of their status. But for a general approach we decide to use specialized docker images as proposed by Sean (option 2). |
@nutjob4life wrote on slack: |
That will not be fixed for this build, no conclusion from our team of experts. |
💪 Motivation
...so we can have a strategy for future developments
📖 Additional Details
As a use case, we want a consistent way to initialize rabbitmq and elasticsearch for the registry application.
⚙️ Engineering Details
The options (to be investigated and extended) are:
A good example of initialization we want to manage is the creation of a database schema and users.
The text was updated successfully, but these errors were encountered: