Skip to content

Commit

Permalink
feature: dotenv support - allow to change the used OpenSearch version…
Browse files Browse the repository at this point in the history
… (ddev 1.23.5) (#7)

Co-authored-by: Christian Münch <[email protected]>
Co-authored-by: Stanislav Zhuk <[email protected]>
  • Loading branch information
3 people authored Oct 19, 2024
1 parent e856a27 commit 8925265
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,40 @@ Update the file `.ddev/docker-compose.opensearch.yaml` for a compatible Dashboar

## Installation

1. Run `ddev get ddev/ddev-opensearch` to install the addon in your exiting DDEV project.
1. Run `ddev add-on get ddev/ddev-opensearch` to install the addon in your exiting DDEV project.
2. `ddev restart` to restart your project.

## Configuration

To modify the build of the used OpenSearch image for the container there are dotenv variables available.

- `OPENSEARCH_TAG` - The version of the OpenSearch image to use. Default: `latest`
- `OPENSEARCH_DASHBOARDS_TAG` - The version of the OpenSearch Dashboards image to use. Default: `latest`
- `INSTALL_PLUGIN_ANALYSIS_PHONETIC` - Install the analysis-phonetic plugin. Default: `true`
- `INSTALL_PLUGIN_ANALYSIS_ICU` - Install the analysis-icu plugin. Default: `true`

Use the `ddev dotenv` command to set these variables.

Example:

```bash
ddev dotenv set .ddev/.env.opensearch \
--opensearch-tag=2.15.0 \
--opensearch-dashboards-tag=2.15.0 \
--install-plugin-analytics-phonetic=false \
--install-plugin-analytics-icu=false

# rebuild opensearch image (required step)
ddev debug rebuild -s opensearch

# remove old opensearch volume (if this is downgrade)
ddev stop
docker volume rm ddev-$(ddev status -j | docker run -i --rm ddev/ddev-utilities jq -r '.raw.name')_opensearch

# and restart the project
ddev restart
```

## Usage

After installation, you can access the OpenSearch instance by visiting `https://<yourname>.ddev.site:9201` (encrypted) or `http://<yourname>.ddev.site:9200`.
Expand Down
10 changes: 8 additions & 2 deletions docker-compose.opensearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
services:
opensearch:
container_name: ddev-${DDEV_SITENAME}-opensearch
build: ./opensearch
build:
context: ./opensearch
dockerfile: Dockerfile
args:
OPENSEARCH_TAG: ${OPENSEARCH_TAG:-latest}
INSTALL_PLUGIN_ANALYSIS_PHONETIC: ${INSTALL_PLUGIN_ANALYSIS_PHONETIC:-true}
INSTALL_PLUGIN_ANALYSIS_ICU: ${INSTALL_PLUGIN_ANALYSIS_ICU:-true}
expose:
- 9200
environment:
Expand Down Expand Up @@ -30,7 +36,7 @@ services:
test: ["CMD-SHELL", "curl --fail -s localhost:9200"]

opensearch-dashboards:
image: opensearchproject/opensearch-dashboards:latest
image: opensearchproject/opensearch-dashboards:${OPENSEARCH_DASHBOARDS_TAG:-latest}
container_name: 'ddev-${DDEV_SITENAME}-opensearch-dashboards'
environment:
- VIRTUAL_HOST=$DDEV_HOSTNAME
Expand Down
15 changes: 11 additions & 4 deletions opensearch/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#ddev-generated
FROM opensearchproject/opensearch:latest
ARG OPENSEARCH_TAG=latest

FROM opensearchproject/opensearch:${OPENSEARCH_TAG}

ARG INSTALL_PLUGIN_ANALYSIS_PHONETIC=true
ARG INSTALL_PLUGIN_ANALYSIS_ICU=true

WORKDIR /usr/share/opensearch

RUN bin/opensearch-plugin install analysis-phonetic
RUN bin/opensearch-plugin install analysis-icu

# Install plugins
RUN if [ "${INSTALL_PLUGIN_ANALYSIS_PHONETIC}" = "true" ]; then bin/opensearch-plugin install analysis-phonetic; fi
RUN if [ "${INSTALL_PLUGIN_ANALYSIS_ICU}" = "true" ]; then bin/opensearch-plugin install analysis-icu; fi
9 changes: 5 additions & 4 deletions tests/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setup() {

health_checks() {
set +u # bats-assert has unset variables so turn off unset check
# ddev restart is required because we have done `ddev get` on a new service
# ddev restart is required because we have done `ddev add-on get` on a new service
ddev restart

# For debugging purposes
Expand All @@ -43,15 +43,16 @@ teardown() {
@test "install from directory" {
set -eu -o pipefail
cd ${TESTDIR}
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${DIR}
echo "# ddev add-on get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev add-on get ${DIR}
health_checks
}

# bats test_tags=release
@test "install from release" {
set -eu -o pipefail
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
echo "# ddev get ${ADDON_PATH} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
echo "# ddev add-on get ${ADDON_PATH} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
ddev get ${ADDON_PATH}
health_checks
}

0 comments on commit 8925265

Please sign in to comment.