Skip to content

Commit

Permalink
refactor(docker-dev): set up elasticsearch using local mapping on doc…
Browse files Browse the repository at this point in the history
…ker-compose.dev (#2137)



Co-authored-by: Dexter Lee <[email protected]>
  • Loading branch information
dexter-mh-lee and Dexter Lee authored Feb 25, 2021
1 parent d2745ee commit e7c3fd8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
12 changes: 12 additions & 0 deletions docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@
# TODO mount + debug docker file for frontend
version: '3.8'
services:
# Pre-creates the search indices using local mapping/settings.json
elasticsearch-setup:
image: elasticsearch-setup:debug
build:
context: elasticsearch-setup
dockerfile: Dockerfile
args:
APP_ENV: dev
volumes:
- ./elasticsearch-setup/create-indices.sh:/create-indices.sh
- ../gms/impl/src/main/resources/index/:/index

datahub-gms:
image: linkedin/datahub-gms:debug
build:
Expand Down
15 changes: 13 additions & 2 deletions docker/elasticsearch-setup/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# This "container" is a workaround to pre-create search indices
FROM jwilder/dockerize:0.6.1

# Defining environment
ARG APP_ENV=prod

FROM jwilder/dockerize:0.6.1 AS base

RUN apk add --no-cache curl jq

FROM base AS prod-install

COPY docker/elasticsearch-setup/create-indices.sh /
RUN chmod 755 create-indices.sh
COPY gms/impl/src/main/resources/index /
COPY gms/impl/src/main/resources/index /index

FROM base AS dev-install
# Dummy stage for development. Use local files for setup
# See this excellent thread https://github.com/docker/cli/issues/1134

FROM ${APP_ENV}-install AS final
CMD dockerize -wait http://$ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT -timeout 120s /create-indices.sh
4 changes: 2 additions & 2 deletions docker/elasticsearch-setup/create-indices.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e

function create_index {
jq -n \
--slurpfile settings $2 \
--slurpfile mappings $3 \
--slurpfile settings index/$2 \
--slurpfile mappings index/$3 \
'.settings=$settings[0] | .mappings.doc=$mappings[0]' > /tmp/data

curl -XPUT $ELASTICSEARCH_HOST:$ELASTICSEARCH_PORT/$1 --data @/tmp/data
Expand Down

0 comments on commit e7c3fd8

Please sign in to comment.