Skip to content

Commit d835ba9

Browse files
YANG-DBjoshuali925
andauthored
add docker-compose support (opensearch-project#575)
* add capability to build the plugin and add it into the docker of the Opensearch-Dashboard update the developer-guid to reflect the correct bootstraping process add docker-compose support and tutorial Signed-off-by: YANGDB <[email protected]> * Update Dockerfile * Update Dockerfile and adding .env * Update Using-Docker.md Co-authored-by: Joshua Li <[email protected]> Signed-off-by: YANGDB <[email protected]> --------- Signed-off-by: YANGDB <[email protected]> Co-authored-by: Joshua Li <[email protected]>
1 parent dbb4a8a commit d835ba9

File tree

5 files changed

+168
-13
lines changed

5 files changed

+168
-13
lines changed

.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# version for opensearch & opensearch-dashboards docker image
2+
VERSION=2.6.0
3+
# auth details - change according to your system
4+
USER=admin
5+
PASSWORD=admin

DEVELOPER_GUIDE.md

+11-13
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,10 @@ So you want to contribute code to this project? Excellent! We're glad you're her
44

55
### Setup
66

7-
1. Download OpenSearch for the version that matches the [OpenSearch Dashboards version specified in opensearch_dashboards.json](./dashboards-observability/opensearch_dashboards.json#L4) from [opensearch.org](https://opensearch.org/downloads.html).
8-
1. Download the OpenSearch Dashboards source code for the [version specified in opensearch_dashboards.json](./dashboards-observability/opensearch_dashboards.json#L4) you want to set up.
9-
1. Change your node version to the version specified in `.node-version` inside the OpenSearch Dashboards root directory.
10-
1. cd into `OpenSearch-Dashboards` and remove the `plugins` directory.
11-
1. Check out this package from version control as the `plugins/dashboards-observability` directory.
12-
```bash
13-
git clone https://github.com/opensearch-project/dashboards-observability plugins
14-
git checkout main
15-
```
16-
6. Run `yarn osd bootstrap` inside `OpenSearch-Dashboards`.
7+
1. Git clone OpenSearch-Dashboard for the version that matches the version you want to use [OpenSearch-Dashboards](https://github.com/opensearch-project/OpenSearch-Dashboards)
8+
2. Change your node version to the version specified in `.node-version` inside the OpenSearch Dashboards root directory. (using [nvm](https://github.com/nvm-sh/nvm) can help for that)
9+
3. Change directory into `OpenSearch-Dashboards` and git Clone the [Observability-Dashboard](https://github.com/opensearch-project/dashboards-observability) into the `plugins/` directory.
10+
4. Run `yarn osd bootstrap` inside `OpenSearch-Dashboards`.
1711

1812
Ultimately, your directory structure should look like this:
1913

@@ -28,11 +22,15 @@ Ultimately, your directory structure should look like this:
2822

2923
To build the plugin's distributable zip simply run `yarn build`.
3024

31-
Example output: `./build/observability*.zip`
25+
The output file : `./build/observabilityDashboards-?.?.?.zip` (`?.?.?` stands for the version number)
26+
27+
### Run Directly
28+
29+
Cd back to `OpenSearch-Dashboards` directory and run `yarn start` to start OpenSearch Dashboards including this plugin. OpenSearch Dashboards will be available on `localhost:5601`.
3230

33-
### Run
31+
### Run Docker
3432

35-
cd back to `OpenSearch-Dashboards` directory and run `yarn start` to start OpenSearch Dashboards including this plugin. OpenSearch Dashboards will be available on `localhost:5601`.
33+
Run `docker-compose up -d` after changing the [Dockerfile](Dockerfile) as described in this [tutorial](Using-Docker.md)
3634

3735
### Submitting Changes
3836

Dockerfile

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Declare a build argument for the version
2+
ARG VERSION
3+
4+
# Use OpenSearch image as base
5+
FROM opensearchproject/opensearch-dashboards:${VERSION}
6+
7+
# Copy plugin zip into image
8+
COPY ./build /tmp
9+
10+
USER root
11+
RUN mv /tmp/observabilityDashboards*.zip /tmp/observabilityDashboards.zip
12+
USER opensearch-dashboards
13+
14+
RUN /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin remove observabilityDashboards && \
15+
/usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin install file:///tmp/observabilityDashboards.zip
16+
17+
USER root
18+
RUN rm -r /tmp/observabilityDashboards.zip
19+
20+
# Switch back to opensearch user
21+
USER opensearch-dashboards

Using-Docker.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Using Docker
2+
Using docker as the runtime environment for testing and validating new developments is now available using the next commands:
3+
4+
## Build the plugin
5+
First the plugin must be build using the `yarn build` command.
6+
7+
Once this build was completed - the expected zip location of the plugin is `./build/observabilityDashboards-?.?.?.zip` where as the `?.?.?` represents the version of this dashboard plugin.
8+
9+
> Note that the plugin version must correspond to the OpenSearch-Dashboards version - this information appears [here](opensearch_dashboards.json)
10+
>
11+
12+
Once the build is completed, make sure to overide the [Dockerfile](Dockerfile) target zip file with the exact name
13+
```
14+
# Install updated plugin
15+
RUN /usr/share/opensearch-dashboards/bin/opensearch-dashboards-plugin install file:///tmp/observabilityDashboards-3.0.0.zip
16+
```
17+
18+
## Docker imageVersion
19+
The docker images used by this file are all referencing the [.env](.env) environment file that contains the version and user/password fields that need to be changed to match your own system.
20+
21+
## Run the docker image build
22+
To build the docker image use the next command:
23+
> `docker build --build-arg VERSION=$(grep VERSION .env | cut -d '=' -f2) -t your_image_name .`
24+
25+
## Run the docker compose
26+
The [docker-compose](docker-compose.yml) file represents a simple assembly of an OpenSearch cluster with two nodes and an opensearch dashboard that has the updated image with the latest changes in this plugin.
27+
28+
run `docker compose up -d` to start the services and once the service is up and running you can start testing the changes.
29+
30+
> Note that the OpenSearch version also must correspond to the OpenSearch-Dashboards version
31+
32+
## Accessing the Dashboard
33+
The dashboard service uses port `localhost:5601` for access and this was already exported in the docker-compose service definition
34+
```yaml
35+
ports:
36+
- 5601:5601 # Map host port 5601 to container port 5601
37+
```
38+
39+
## Security Notice
40+
The default User:Password for this demo test is embedded within the [.env](.env) environment file - pay attention not to use this configuration in a production or any environment that may contain
41+
confident or personal information without first changing the security definition for accessing the servers.

docker-compose.yml

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright The OpenTelemetry Authors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
5+
version: '3.9'
6+
x-default-logging: &logging
7+
driver: "json-file"
8+
options:
9+
max-size: "5m"
10+
max-file: "2"
11+
12+
volumes:
13+
opensearch-data1:
14+
opensearch-data2:
15+
16+
networks:
17+
default:
18+
name: opensearch-dashboards-demo
19+
driver: bridge
20+
21+
services:
22+
# OpenSearch store - node1
23+
opensearch-node1: # This is also the hostname of the container within the Docker network (i.e. https://opensearch-node1/)
24+
image: opensearchproject/opensearch:${VERSION} # Specifying the latest available image - modify if you want a specific version
25+
container_name: opensearch-node1
26+
environment:
27+
- cluster.name=opensearch-cluster # Name the cluster
28+
- node.name=opensearch-node1 # Name the node that will run in this container
29+
- discovery.seed_hosts=opensearch-node1,opensearch-node2 # Nodes to look for when discovering the cluster
30+
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2 # Nodes eligible to serve as cluster manager
31+
- bootstrap.memory_lock=true # Disable JVM heap memory swapping
32+
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m" # Set min and max JVM heap sizes to at least 50% of system RAM
33+
ulimits:
34+
memlock:
35+
soft: -1 # Set memlock to unlimited (no soft or hard limit)
36+
hard: -1
37+
nofile:
38+
soft: 65536 # Maximum number of open files for the opensearch user - set to at least 65536
39+
hard: 65536
40+
volumes:
41+
- opensearch-data1:/usr/share/opensearch/data # Creates volume called opensearch-data1 and mounts it to the container
42+
healthcheck:
43+
test: ["CMD", "curl", "-f", "https://opensearch-node1:9200/_cluster/health?wait_for_status=yellow", "-ku ${USER}:${PASSWORD}"]
44+
interval: 5s
45+
timeout: 25s
46+
retries: 4
47+
ports:
48+
- "9200:9200"
49+
- "9600:9600"
50+
51+
# OpenSearch store - node2
52+
opensearch-node2:
53+
image: opensearchproject/opensearch:${VERSION} # This should be the same image used for opensearch-node1 to avoid issues
54+
container_name: opensearch-node2
55+
environment:
56+
- cluster.name=opensearch-cluster
57+
- node.name=opensearch-node2
58+
- discovery.seed_hosts=opensearch-node1,opensearch-node2
59+
- cluster.initial_cluster_manager_nodes=opensearch-node1,opensearch-node2
60+
- bootstrap.memory_lock=true
61+
- "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
62+
ulimits:
63+
memlock:
64+
soft: -1
65+
hard: -1
66+
nofile:
67+
soft: 65536
68+
hard: 65536
69+
volumes:
70+
- opensearch-data2:/usr/share/opensearch/data
71+
72+
# OpenSearch store - dashboard
73+
opensearch-dashboards:
74+
container_name: opensearch-dashboards
75+
build:
76+
context: ./
77+
dockerfile: Dockerfile
78+
args:
79+
- VERSION=${VERSION}
80+
81+
ports:
82+
- 5601:5601 # Map host port 5601 to container port 5601
83+
expose:
84+
- "5601" # Expose port 5601 for web access to OpenSearch Dashboards
85+
environment:
86+
OPENSEARCH_HOSTS: '["https://opensearch-node1:9200","https://opensearch-node2:9200"]' # Define the OpenSearch nodes that OpenSearch Dashboards will query
87+
depends_on:
88+
- opensearch-node1
89+
- opensearch-node2
90+

0 commit comments

Comments
 (0)