-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction.yml
208 lines (180 loc) · 10 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
name: 'Launch OpenSearch with or without plugins'
description: 'Downloads latest build of OpenSearch, optionally installs plugins, and then starts OpenSearch on localhost:9200'
inputs:
opensearch-version:
description: 'The version of OpenSearch that should be used, e.g "3.0.0"'
required: true
plugins:
description: 'A comma separated list of plugins to install. Leave empty to not install any. Each entry should be a full path prefixed with `file: `, for example: `file:$(pwd)/my-plugin.zip`'
required: false
security-enabled:
description: 'Whether security is enabled'
required: true
admin-password:
description: 'The admin password uses for the cluster'
required: false
security_config_file:
description: 'Path to a security config file to replace the default. Leave empty if security is not enabled or using the default config'
required: false
port:
description: 'Port to run OpenSearch. Leave empty to use the default config (9200)'
required: false
default: '9200'
jdk-version:
description: 'The version of the JDK that should be used, e.g "21"'
required: false
default: '11'
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
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: ${{ inputs.jdk-version }}
# Download OpenSearch
- name: Download OpenSearch for Windows
uses: peternied/download-file@v2
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
- name: Download OpenSearch for Linux
uses: peternied/download-file@v2
if: ${{ runner.os == 'Linux' }}
with:
url: https://artifacts.opensearch.org/snapshots/core/opensearch/${{ inputs.opensearch-version }}-SNAPSHOT/opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-linux-x64-latest.tar.gz
# Extract downloaded zip
- name: Extract downloaded tar
if: ${{ runner.os == 'Linux' }}
run: |
tar -xzf opensearch-*.tar.gz && mv opensearch-${{ inputs.opensearch-version }}-SNAPSHOT opensearch-${{inputs.opensearch-version}}-SNAPSHOT${{ inputs.port }}
rm -f opensearch-*.tar.gz
shell: bash
- name: Extract downloaded zip
if: ${{ runner.os == 'Windows' }}
run: |
Expand-Archive -Path "opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-windows-x64-latest.zip" -DestinationPath "temp"
Move-Item -Path "temp/*" -Destination "opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}"
Remove-Item -Path "temp" -Recurse
Remove-Item -Path "opensearch-min-${{ inputs.opensearch-version }}-SNAPSHOT-windows-x64-latest.zip"
shell: pwsh
- name: Install plugin(s) into OpenSearch for Linux
if: ${{ runner.os == 'Linux'}}
run: |
chmod +x ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/bin/opensearch-plugin
plugins="${{ inputs.plugins }}"
if [ -n "$plugins" ]; then
echo "$plugins" | tr ',' '\n' | while read -r plugin; do
/bin/bash -c "yes | ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/bin/opensearch-plugin install ${plugin}"
done
fi
shell: bash
- name: Install plugin(s) into OpenSearch for Windows
if: ${{ runner.os == 'Windows' && inputs.plugins != '' }}
run: |
$pluginNames = "${{ inputs.plugins }}" -split ','
if ($pluginNames.Length -gt 0) {
foreach ($plugin in $pluginNames) {
'y' | .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}\bin\opensearch-plugin.bat install ${plugin}
}
}
shell: pwsh
- name: Replace security configuration file if applicable
if: ${{ inputs.security_config_file != '' }}
run: |
mv ${{ inputs.security_config_file }} ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch-security/config.yml
shell: bash
# Setup security if it's enabled
- name: Setup security demo configuration
if: ${{ runner.os == 'Linux' && inputs.security-enabled == 'true' }}
run: |
echo "running linux security demo configuration setup"
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=${{ inputs.admin-password }}
chmod +x ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh
opensearch_version="${{ inputs.opensearch-version }}"
opensearch_major_version=$(echo "$opensearch_version" | awk -F'.' '{print $1}')
opensearch_minor_version=$(echo "$opensearch_version" | awk -F'.' '{print $2}')
if [ "$opensearch_major_version" -lt 2 ] || ([ "$opensearch_major_version" -eq 2 ] && [ "$opensearch_minor_version" -lt 12 ]); then
echo "Running the command without -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh"
else
echo "Running the command with -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.sh -t"
fi
echo "plugins.security.unsupported.restapi.allow_securityconfig_modification: true" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
- name: Setup security demo configuration for Windows
if: ${{ runner.os == 'Windows' && inputs.security-enabled == 'true' }}
run: |
echo "running windows security demo configuration setup"
export OPENSEARCH_INITIAL_ADMIN_PASSWORD=${{ inputs.admin-password }}
chmod +x ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat
opensearch_version="${{ inputs.opensearch-version }}"
opensearch_major_version=$(echo "$opensearch_version" | cut -d'.' -f1)
opensearch_minor_version=$(echo "$opensearch_version" | cut -d'.' -f2)
if [ "$opensearch_major_version" -lt 2 ] || ([ "$opensearch_major_version" -eq 2 ] && [ "$opensearch_minor_version" -lt 12 ]); then
echo "Running the command without -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat"
else
echo "Running the command with -t option (OpenSearch version is $opensearch_version)"
/bin/bash -c "yes | ./opensearch-${opensearch_version}-SNAPSHOT${{ inputs.port }}/plugins/opensearch-security/tools/install_demo_configuration.bat -t"
fi
echo "plugins.security.unsupported.restapi.allow_securityconfig_modification: true" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
- name: Use more space
run: |
echo '' >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
echo "cluster.routing.allocation.disk.threshold_enabled: false" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
- name: Replace opensearch.yml file if applicable
if: ${{ inputs.port != '' }}
run: |
echo '' >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
echo "http.port: ${{ inputs.port }}" >> ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/config/opensearch.yml
shell: bash
# Run OpenSearch
- name: Run OpenSearch with plugin on Linux
if: ${{ runner.os == 'Linux'}}
run: /bin/bash -c "./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/bin/opensearch &"
shell: bash
- name: Run OpenSearch with plugin on Windows
if: ${{ runner.os == 'Windows'}}
run: start .\opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}\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: |
if [ "${{ inputs.security-enabled }}" == "true" ]; then
curl https://localhost:${{ inputs.port || 9200 }}/_cat/plugins -u 'admin:${{ inputs.admin-password }}' -k -v --fail-with-body
else
curl http://localhost:${{ inputs.port || 9200 }}/_cat/plugins -v
fi
shell: bash
- name: Check OpenSearch Running on Windows
if: ${{ runner.os == 'Windows'}}
run: |
if ("${{ inputs.security-enabled }}" -eq "true") {
$credentialBytes = [Text.Encoding]::ASCII.GetBytes("admin:${{ inputs.admin-password }}")
$encodedCredentials = [Convert]::ToBase64String($credentialBytes)
$baseCredentials = "Basic $encodedCredentials"
$Headers = @{ Authorization = $baseCredentials }
$url = 'https://localhost:${{ inputs.port || 9200 }}/_cat/plugins'
} else {
$Headers = @{ }
$url = 'http://localhost:${{ inputs.port || 9200 }}/_cat/plugins'
}
Invoke-WebRequest -SkipCertificateCheck -Uri $url -Headers $Headers;
shell: pwsh
- if: always()
run: cat ./opensearch-${{ inputs.opensearch-version }}-SNAPSHOT${{ inputs.port }}/logs/opensearch.log
shell: bash