756 words
4 minutes
Creating Custom Debian Packages for OpenSearch Dashboards

Creating Custom Debian Packages for OpenSearch Dashboards#

Oh, you’re deploying OpenSearch Dashboards in enterprise environments? How delightfully original. Of course you need customizations—because heaven forbid you use anything “as is.” Well, since you insist on making your life complicated with specific plugins, custom themes, and specialized configurations, I suppose creating a custom Debian package is the least painful way to standardize your special snowflake modifications across your infrastructure.

This guide begrudgingly walks you through building a custom Debian package for OpenSearch Dashboards 2.18.0 with your inevitably over-engineered plugins and configurations.

Why Package Custom OpenSearch Dashboards?#

Before diving into the technical steps, let me enlighten you on why packaging is supposedly “better” than manual installation—as if you hadn’t already convinced yourself of this brilliant idea:

  1. Standardized deployments across multiple environments (because consistency is apparently too much to ask for otherwise)
  2. Simplified upgrades through package management (shocking that a package manager would manage packages)
  3. Dependency management handled by the package manager (revolutionary concept, truly)
  4. Configuration consistency across your infrastructure (imagine that!)
  5. Easier integration with CI/CD pipelines and configuration management tools (because making simple things complicated is the enterprise way)

Prerequisites#

Before starting this adventure in overcomplication, ensure your build system has:

  • A Debian-based Linux distribution (Ubuntu 20.04+ recommended—because apparently we’re picky about our suffering)
  • Sufficient RAM (at least 8GB) and disk space (20GB free)—yes, that’s right, this simple dashboard needs more resources than some entire operating systems
  • Internet connection to download dependencies (shocking requirement, I know)
  • Root or sudo access (because we’re about to break things systemically)

Step 1: Setting Up the Build Environment#

First, install the necessary dependencies for building OpenSearch Dashboards:

Terminal window
# Install system dependencies
sudo apt-get update
sudo apt-get install -y nodejs npm ruby ruby-dev build-essential rpm git curl
# Install Node Version Manager (nvm)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
# Install Yarn
npm install -g yarn

Step 2: Clone and Prepare the Source Code#

Clone the OpenSearch Dashboards repository and check out the specific version you want to package:

Terminal window
git clone https://github.com/opensearch-project/OpenSearch-Dashboards.git
cd OpenSearch-Dashboards
git checkout 2.18.0
# Set up the correct Node.js version
nvm install $(cat .nvmrc)
nvm use $(cat .nvmrc)

Step 3: Add Custom Plugins#

Now add your custom plugins to the build:

Terminal window
# Create plugins directory if it doesn't exist
mkdir -p plugins
# Copy your custom plugins
cp -r /path/to/your/custom/plugins/* plugins/
# Alternatively, you can clone plugin repositories directly
# git clone https://github.com/example/your-plugin.git plugins/your-plugin

Step 4: Build OpenSearch Dashboards#

Build the package with your custom plugins included:

Terminal window
# Bootstrap the project
yarn osd bootstrap
# Build OpenSearch Dashboards
yarn build --skip-os-packages

This process might take some time depending on your system resources—or more accurately, it will take forever because JavaScript build processes are apparently designed by people who have never heard of efficiency.

Step 5: Create the Debian Package Structure#

Create the directory structure for your Debian package:

Terminal window
# Create base package directory
mkdir -p opensearch-dashboards-2.18.0/DEBIAN
# Create installation directories
mkdir -p opensearch-dashboards-2.18.0/usr/share/opensearch-dashboards
mkdir -p opensearch-dashboards-2.18.0/etc/opensearch-dashboards
mkdir -p opensearch-dashboards-2.18.0/var/log/opensearch-dashboards
mkdir -p opensearch-dashboards-2.18.0/var/lib/opensearch-dashboards
mkdir -p opensearch-dashboards-2.18.0/lib/systemd/system

Step 6: Copy Build Artifacts#

Copy the built files to the appropriate locations in the package structure:

Terminal window
# Copy built OpenSearch Dashboards files
cp -r build/opensearch-dashboards/* opensearch-dashboards-2.18.0/usr/share/opensearch-dashboards/

Step 7: Create Debian Control Files#

Control File#

Create the main package control file:

Terminal window
cat > opensearch-dashboards-2.18.0/DEBIAN/control << EOL
Package: opensearch-dashboards
Version: 2.18.0
Section: web
Priority: optional
Architecture: amd64
Depends: libnss3
Maintainer: Your Name <your.email@domain.com>
Description: OpenSearch Dashboards with custom plugins
Custom build of OpenSearch Dashboards including specific plugins
EOL

Pre-installation Script#

Create the pre-installation script to set up the user and group:

cat > opensearch-dashboards-2.18.0/DEBIAN/preinst << EOL
#!/bin/bash
if ! getent group opensearch-dashboards >/dev/null; then
groupadd -r opensearch-dashboards
fi
if ! getent passwd opensearch-dashboards >/dev/null; then
useradd -r -g opensearch-dashboards -d /usr/share/opensearch-dashboards -s /sbin/nologin opensearch-dashboards
fi
EOL
chmod 755 opensearch-dashboards-2.18.0/DEBIAN/preinst

Post-installation Script#

Create the post-installation script to set permissions:

cat > opensearch-dashboards-2.18.0/DEBIAN/postinst << EOL
#!/bin/bash
chown -R opensearch-dashboards:opensearch-dashboards /usr/share/opensearch-dashboards
chown -R opensearch-dashboards:opensearch-dashboards /var/log/opensearch-dashboards
chown -R opensearch-dashboards:opensearch-dashboards /var/lib/opensearch-dashboards
chmod 750 /usr/share/opensearch-dashboards
chmod 750 /var/log/opensearch-dashboards
chmod 750 /var/lib/opensearch-dashboards
# Enable and start the service
systemctl daemon-reload
systemctl enable opensearch-dashboards.service
EOL
chmod 755 opensearch-dashboards-2.18.0/DEBIAN/postinst

Step 8: Create Configuration Files#

Configuration File#

Copy and modify the default configuration file:

Terminal window
cp config/opensearch_dashboards.yml opensearch-dashboards-2.18.0/etc/opensearch-dashboards/
# Add custom paths
cat >> opensearch-dashboards-2.18.0/etc/opensearch-dashboards/opensearch_dashboards.yml << EOL
# Custom paths
path.data: /var/lib/opensearch-dashboards
path.logs: /var/log/opensearch-dashboards
# Custom settings
server.host: "0.0.0.0"
server.port: 5601
opensearch.hosts: ["https://localhost:9200"]
opensearch.ssl.verificationMode: none
EOL

Systemd Service File#

Create a systemd service file for automatic startup:

Terminal window
cat > opensearch-dashboards-2.18.0/lib/systemd/system/opensearch-dashboards.service << EOL
[Unit]
Description=OpenSearch Dashboards
Documentation=https://opensearch.org/docs/dashboards
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=opensearch-dashboards
Group=opensearch-dashboards
Environment=NODE_ENV=production
Environment=CONFIG_PATH=/etc/opensearch-dashboards/opensearch_dashboards.yml
ExecStart=/usr/share/opensearch-dashboards/bin/opensearch-dashboards
Restart=always
WorkingDirectory=/usr/share/opensearch-dashboards
[Install]
WantedBy=multi-user.target
EOL

Step 9: Build the Debian Package#

Now build the Debian package:

Terminal window
dpkg-deb --build opensearch-dashboards-2.18.0

This will create a file named opensearch-dashboards-2.18.0.deb in your current directory.

Step 10: Installing the Package#

To install your custom package on a Debian/Ubuntu system:

Terminal window
sudo dpkg -i opensearch-dashboards-2.18.0.deb
# If there are dependency issues
sudo apt-get install -f
Creating Custom Debian Packages for OpenSearch Dashboards
https://mranv.pages.dev/posts/packaging-custom-opensearch-dashboards/
Author
Anubhav Gain
Published at
2024-05-01
License
CC BY-NC-SA 4.0