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:
- Standardized deployments across multiple environments (because consistency is apparently too much to ask for otherwise)
- Simplified upgrades through package management (shocking that a package manager would manage packages)
- Dependency management handled by the package manager (revolutionary concept, truly)
- Configuration consistency across your infrastructure (imagine that!)
- 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:
# Install system dependenciessudo apt-get updatesudo 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 | bashsource ~/.bashrc
# Install Yarnnpm 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:
git clone https://github.com/opensearch-project/OpenSearch-Dashboards.gitcd OpenSearch-Dashboardsgit checkout 2.18.0
# Set up the correct Node.js versionnvm install $(cat .nvmrc)nvm use $(cat .nvmrc)
Step 3: Add Custom Plugins
Now add your custom plugins to the build:
# Create plugins directory if it doesn't existmkdir -p plugins
# Copy your custom pluginscp -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:
# Bootstrap the projectyarn osd bootstrap
# Build OpenSearch Dashboardsyarn 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:
# Create base package directorymkdir -p opensearch-dashboards-2.18.0/DEBIAN
# Create installation directoriesmkdir -p opensearch-dashboards-2.18.0/usr/share/opensearch-dashboardsmkdir -p opensearch-dashboards-2.18.0/etc/opensearch-dashboardsmkdir -p opensearch-dashboards-2.18.0/var/log/opensearch-dashboardsmkdir -p opensearch-dashboards-2.18.0/var/lib/opensearch-dashboardsmkdir -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:
# Copy built OpenSearch Dashboards filescp -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:
cat > opensearch-dashboards-2.18.0/DEBIAN/control << EOLPackage: opensearch-dashboardsVersion: 2.18.0Section: webPriority: optionalArchitecture: amd64Depends: libnss3Maintainer: Your Name <your.email@domain.com>Description: OpenSearch Dashboards with custom plugins Custom build of OpenSearch Dashboards including specific pluginsEOL
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/bashif ! getent group opensearch-dashboards >/dev/null; then groupadd -r opensearch-dashboardsfiif ! getent passwd opensearch-dashboards >/dev/null; then useradd -r -g opensearch-dashboards -d /usr/share/opensearch-dashboards -s /sbin/nologin opensearch-dashboardsfiEOL
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/bashchown -R opensearch-dashboards:opensearch-dashboards /usr/share/opensearch-dashboardschown -R opensearch-dashboards:opensearch-dashboards /var/log/opensearch-dashboardschown -R opensearch-dashboards:opensearch-dashboards /var/lib/opensearch-dashboardschmod 750 /usr/share/opensearch-dashboardschmod 750 /var/log/opensearch-dashboardschmod 750 /var/lib/opensearch-dashboards
# Enable and start the servicesystemctl daemon-reloadsystemctl enable opensearch-dashboards.serviceEOL
chmod 755 opensearch-dashboards-2.18.0/DEBIAN/postinst
Step 8: Create Configuration Files
Configuration File
Copy and modify the default configuration file:
cp config/opensearch_dashboards.yml opensearch-dashboards-2.18.0/etc/opensearch-dashboards/
# Add custom pathscat >> opensearch-dashboards-2.18.0/etc/opensearch-dashboards/opensearch_dashboards.yml << EOL
# Custom pathspath.data: /var/lib/opensearch-dashboardspath.logs: /var/log/opensearch-dashboards
# Custom settingsserver.host: "0.0.0.0"server.port: 5601opensearch.hosts: ["https://localhost:9200"]opensearch.ssl.verificationMode: noneEOL
Systemd Service File
Create a systemd service file for automatic startup:
cat > opensearch-dashboards-2.18.0/lib/systemd/system/opensearch-dashboards.service << EOL[Unit]Description=OpenSearch DashboardsDocumentation=https://opensearch.org/docs/dashboardsWants=network-online.targetAfter=network-online.target
[Service]Type=simpleUser=opensearch-dashboardsGroup=opensearch-dashboardsEnvironment=NODE_ENV=productionEnvironment=CONFIG_PATH=/etc/opensearch-dashboards/opensearch_dashboards.ymlExecStart=/usr/share/opensearch-dashboards/bin/opensearch-dashboardsRestart=alwaysWorkingDirectory=/usr/share/opensearch-dashboards
[Install]WantedBy=multi-user.targetEOL
Step 9: Build the Debian Package
Now build the Debian package:
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:
sudo dpkg -i opensearch-dashboards-2.18.0.deb
# If there are dependency issuessudo apt-get install -f