Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub Action for plugin install #2239

Merged
126 changes: 126 additions & 0 deletions .github/actions/start-opensearch-with-one-plugin/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: 'Start OpenSearch with One Plugin'
description: 'Downloads latest build of OpenSearch, installs a plugin, executes and script and then starts OpenSearch on localhost:9200'
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

inputs:
opensearch-version:
description: 'The version of OpenSearch that should be used, e.g "3.0.0"'
required: true

plugin-name:
description: 'The the name of the plugin to use, such as security-dashboards-plugin'
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
required: true

plugin-start-script:
description: 'The file name for the configuration script for the plugin such as install_demo_configurations -- may not be needed for every plugin'
required: false

plugin-zip:
description: 'The name of the zip file for the plugin hosted on docker-host i.e. security-plugin.zip '
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
required: true

runs:
using: "composite"
steps:

# Configure longpath names if on Windows
- name: Enable Longpaths if on Windows
if: ${{ runner.os == 'Windows' }}
run: git config --system core.longpaths true
shell: pwsh

# Download OpenSearch
- uses: peternied/download-file@v1
if: ${{ runner.os == 'Windows' }}
with:
url: https://artifacts.opensearch.org/snapshots/core/opensearch/${{ inputs.opensearch-version }}-SNAPSHOT/opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-windows-x64-latest.zip

- uses: peternied/download-file@v1
if: ${{ runner.os == 'Linux' }}
with:
url: https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/${{ inputs.opensearch-version }}/latest/linux/x64/tar/builds/opensearch/dist/opensearch-min-${{ inputs.opensearch-version }}-linux-x64.tar.gz

# Extract downloaded zip
- name: Extract downloaded zip for Linux
if: ${{ runner.os == 'Linux' }}
run: |
tar -xzf opensearch-*.tar.gz
rm -f opensearch-*.tar.gz
shell: bash

- name: Extract downloaded zip for Windows
if: ${{ runner.os == 'Windows' }}
run: |
tar -xzf opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-windows-x64-latest.zip
del opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-windows-x64-latest.zip
shell: pwsh

# Move and rename the plugin for installation
- name: Move and rename the plugin for installation
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
run: mv ./build/distributions/${{ inputs.plugin-name }}-*.zip ${{ inputs.plugin-name }}.zip
shell: bash

# Install the plugin, runs its start-script, and start the OpenSearch server
- name: Install Plugin into OpenSearch for Linux
if: ${{ runner.os == 'Linux'}}
run: |
cat > os-ep.sh <<EOF
yes | opensearch-plugin install file:///docker-host/${{ inputs.plugin-zip }}.zip
chmod +x plugins/${{ inputs.plugin-name }}/tools/${{ inputs.plugin-start-script }}.sh
yes | plugins/${{ inputs.plugin-name }}/tools/${{ inputs.plugin-start-script }}.sh
chown 1001:1001 -R /opensearch
su -c "/opensearch/bin/opensearch" -s /bin/bash opensearch
EOF
docker build -t opensearch-test:latest -f- . <<EOF
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
FROM ubuntu:latest
COPY --chown=1001:1001 os-ep.sh /docker-host/
COPY --chown=1001:1001 ${{ inputs.plugin-name }}.zip /docker-host/${{ inputs.plugin-zip }}.zip
COPY --chown=1001:1001 opensearch* /opensearch/
RUN chmod +x /docker-host/os-ep.sh
RUN useradd -u 1001 -s /sbin/nologin opensearch
ENV PATH="/opensearch/bin:${PATH}"
WORKDIR /opensearch/
ENTRYPOINT /docker-host/os-ep.sh
EOF
shell: bash

- name: Install Plugin into OpenSearch for Windows
if: ${{ runner.os == 'Windows'}}
run: |
'y' | .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT\bin\opensearch-plugin.bat install file:$pwd\${{ inputs.plugin-name }}.zip
'y', 'y', 'N' | .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT\plugins\${{ inputs.plugin-name }}\tools\${{ inputs.plugin-start-script }}.bat
shell: pwsh

# Run OpenSearch
- name: Run OpenSearch with plugin on Linux
if: ${{ runner.os == 'Linux'}}
run: docker run --name ops -d -p 9200:9200 -p 9600:9600 -i opensearch-test:latest
shell: bash

- name: Run OpenSearch with plugin on Windows
if: ${{ runner.os == 'Windows'}}
run: start .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT\bin\opensearch.bat
shell: pwsh

# Give the OpenSearch process some time to boot up before sending any requires, might need to increase the default time!
- name: Sleep while OpenSearch starts
uses: peternied/action-sleep@v1
with:
seconds: 30

# Verify that the server is operational
- name: Check OpenSearch Running on Linux
if: ${{ runner.os != 'Windows'}}
run: |
docker logs ops
curl https://localhost:9200/_cat/plugins -u 'admin:admin' -k -v
shell: bash

- name: Check OpenSearch Running on Windows
if: ${{ runner.os == 'Windows'}}
run: |
$credentialBytes = [Text.Encoding]::ASCII.GetBytes("admin:admin")
$encodedCredentials = [Convert]::ToBase64String($credentialBytes)
$baseCredentials = "Basic $encodedCredentials"
$Headers = @{ Authorization = $baseCredentials }
Invoke-WebRequest -SkipCertificateCheck -Uri 'https://localhost:9200/_cat/plugins' -Headers $Headers;
shell: pwsh
127 changes: 20 additions & 107 deletions .github/workflows/plugin_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,120 +3,33 @@ name: Plugin Install
on: [push, pull_request, workflow_dispatch]

jobs:

linux-install:

runs-on: ubuntu-latest

plugin-install:
strategy:
matrix:
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
os: [windows-latest, ubuntu-latest]
jdk: [11, 17]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
java-version: ${{ matrix.jdk }}

- name: Build
run: ./gradlew clean assemble -Dbuild.snapshot=false

- name: Download OpenSearch Core
run: |
opensearch_version=`./gradlew properties -q | grep "opensearch_version:" | awk '{print $2}' | sed 's/-SNAPSHOT//g'`
wget https://ci.opensearch.org/ci/dbc/distribution-build-opensearch/$opensearch_version/latest/linux/x64/tar/builds/opensearch/dist/opensearch-min-$opensearch_version-linux-x64.tar.gz
tar -xzf opensearch-*.tar.gz
rm -f opensearch-*.tar.gz

- name: Move and rename security plugin for installation
run: mv build/distributions/opensearch-security-*.zip opensearch-security.zip
- name: Checkout Branch
uses: actions/checkout@v2

- name: Run OpenSearch with plugin
run: |
cat > os-ep.sh <<EOF
yes | opensearch-plugin install file:///docker-host/security-plugin.zip
chmod +x plugins/opensearch-security/tools/install_demo_configuration.sh
yes | plugins/opensearch-security/tools/install_demo_configuration.sh
chown 1001:1001 -R /opensearch
su -c "/opensearch/bin/opensearch" -s /bin/bash opensearch
EOF
docker build -t opensearch-test:latest -f- . <<EOF
FROM ubuntu:latest
COPY --chown=1001:1001 os-ep.sh /docker-host/
COPY --chown=1001:1001 opensearch-security.zip /docker-host/security-plugin.zip
COPY --chown=1001:1001 opensearch* /opensearch/
RUN chmod +x /docker-host/os-ep.sh
RUN useradd -u 1001 -s /sbin/nologin opensearch
ENV PATH="/opensearch/bin:${PATH}"
WORKDIR /opensearch/
ENTRYPOINT /docker-host/os-ep.sh
EOF
docker run --name ops -d -p 9200:9200 -p 9600:9600 -i opensearch-test:latest
- name: Assemble target plugin
run: ./gradlew assemble
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

- name: Sleep while OpenSearch finishes starting up
uses: whatnick/wait-action@v0.1.2
- name: Run Opensearch with A Single Plugin
uses: ./.github/actions/start-opensearch-with-one-plugin
with:
time: '30s'
opensearch-version: 3.0.0
plugin-name: opensearch-security
plugin-start-script: install_demo_configuration
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved
plugin-zip: security-plugin.zip

- name: Check OpenSearch Running
run: curl -XGET https://localhost:9200 -u 'admin:admin' -k -v

- name: Get Docker Logs
if: always()
run: docker logs ops

- name: Run sanity tests
run: ./gradlew integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="opensearch" -Dhttps=true -Duser=admin -Dpassword=admin
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved

windows-install:

runs-on: windows-latest

steps:
- name: Enable longer filenames for Windows
run: git config --system core.longpaths true

- name: Checkout Plugin
uses: actions/checkout@v2

- name: Set up JDK
uses: actions/setup-java@v1
- name: Run sanity tests on Linux
uses: gradle/gradle-build-action@v2
with:
java-version: 11

- name: Download OpenSearch Core
run: |
cd ..
Invoke-WebRequest https://artifacts.opensearch.org/snapshots/core/opensearch/3.0.0-SNAPSHOT/opensearch-min-3.0.0-SNAPSHOT-windows-x64-latest.zip -Outfile opensearch-3.0.0.zip
tar -xzf opensearch-3.0.0.zip
del opensearch-3.0.0.zip
Rename-Item opensearch-* Opensearch

- name: Build Security Plugin with Gradle
run: |
.\gradlew.bat assemble
env:
_JAVA_OPTIONS: -Xmx4096M

- name: Move and rename security plugin
run: move build\distributions\opensearch-security-*.zip ..\opensearch-security.zip

- name: Install the plugin
run: |
cd ..
'y' | .\Opensearch\bin\opensearch-plugin.bat install file:\a\security\opensearch-security.zip
'y', 'y', 'N' | .\Opensearch\plugins\opensearch-security\tools\install_demo_configuration.bat

- name: Run OpenSearch with plugin
run: |
cd ..
start .\Opensearch\bin\opensearch.bat

- name: Sleep while OpenSearch finishes starting up
run: Start-Sleep -s 30

- name: Check OpenSearch Running
run: |
$credentialBytes = [Text.Encoding]::ASCII.GetBytes("admin:admin")
$encodedCredentials = [Convert]::ToBase64String($credentialBytes)
$baseCredentials = "Basic $encodedCredentials"
$Headers = @{ Authorization = $baseCredentials }
Invoke-WebRequest -SkipCertificateCheck -Uri 'https://localhost:9200' -Headers $Headers
arguements: integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername="opensearch" -Dhttps=true -Duser=admin -Dpassword=admin
stephen-crawford marked this conversation as resolved.
Show resolved Hide resolved