generated from caltechlibrary/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opensearch-init.yaml
323 lines (300 loc) · 9.42 KB
/
opensearch-init.yaml
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#cloud-config
#
# opensearch-init.yaml provides a development environemt for building
# web applications based on PostgreSQL 16, PostgREST 12, Pandoc 3.1,
# and using Python 3's http.server to emulate a front end web server.
#
# This cloud init target Ubuntu's Multipass and assume the image
# available is Jammy (22.04 LTS). Here's an example creating a VM
# with Multipass call "opensearch-machine" and accessing it via Multipass's
# shell.
#
# You need more than the default disk image size for fit all the stuff.
# When you initialize your VM use the following command
#
# ~~~
# multipass launch --name opensearch-machine \
# --memory 4G \
# --disk 50G \
# --cloud-init opensearch-init.yaml
# ~~~
#
# When you're done you can stop the VM with
#
# ~~~
# multipass stop opensearch-machine
# ~~~
#
# You can remove opensearch-machine completely with
#
# ~~~
# multipass stop opensearch-machine
# multipass delete opensearch-machine
# multipass purge opensearch-machine
# ~~~
#
# The first time you run your VM you will need to run the following
# additional setup bash scripts. Then you can choose to install
# to install Haskell (GHCup) so you can compile the latest Pandoc and PostgREST
# and OpenSearch/OpenSearch Dashboard.
#
# 1. 01-setup-scripts.bash, creates "$HOME/bin" and "$HOME/sbin" and adds things ito your .bashrc
# 2. 02-add-python-packages.bash, adds commonly used Python packages to the system
# 3. 03-add-go-and-caltechlibrary-tools.bash, builds and install DLD Go based tools
# 4. 04-ghcup-install.bash, installs Haskell toolchain and manager
# 5. 05-pandoc-build.bash, downloads the latest Pandoc and builds it
# 6. 06-postgrest-build.bash, downloads the latest PostgREST and builds it.
# 7. 07-add-opensearch.bash, downloads the OpenSearch/OpenSearch Dashbaord debs and installs them
#
write_files:
### - content: |
### You are now ready to start working with your OpenSearch Machine. Run
### You then need to run following to configure this virtual machine for
### development.
###
### bash ./sbin/01-setup-scripts.bash
###
### Your may wish to run other scripts in the `$HOME/sbin` directory
### depending on your development needs.
### Finnally remember to resource your `.bashrc` file after you install
### any software to pickup the environment changes defined in it.
###
### . .bashrc
###
### path: /home/ubuntu/README.1st
### owner: ubuntu:ubuntu
### permissions: '0664'
- content: |
#!/bin/bash
APP_NAME="$(basename "$0")"
if [ "$1" = "" ]; then
cat <<EOT
${APP_NAME}(1) user manual | version 0
# NAME
${APP_NAME}
# SYNOPSIS
${APP_NAME} METHOD URL_PATH
# DESCRIPTION
${APP_NAME} provides a thin wrapper around curl to create
a simple OpenSearch client. It requires you to supply a
HTTP method (i.e. GET, PUT, POST, DELETE) and path part of the
URL to access the OpenSearch REST API.
If you are doing a PUT or POST then data will be read from standard
input. This means you can easily type in the JSON or read it from a
file using redirection.
# EXAMPLE
Retrieve the settings for our OpenSearch instance running in our
Multipass VM.
~~~shell
${APP_NAME} GET _settings
~~~
Create an index called content-type
~~~shell
${APP_NAME} PUT content-type
~~~
Add a JSON document to the index (i.e. mydata.json with the id "01")
~~~shell
${APP_NAME} PUT content-type/_doc/01 <mydata.json
~~~
EOT
fi
#
# OpenSearch Client
#
METHOD="$1"
URL_PATH="$2"
CONTENT_TYPE="application/json"
case "${METHOD}" in
put|PUT|post|POST)
echo "Reading data from standard input"
curl -k --user admin:admin \
-H "Content-Type: ${CONTENT_TYPE}" \
-X "${METHOD}" \
-d @- \
"https://localhost:9200/$URL_PATH" | jq .
;;
*)
curl -k --user admin:admin \
-X "${METHOD}" \
-H "Content-Type: ${CONTENT_TYPE}" \
"https://localhost:9200/$URL_PATH" | jq .
esac
owner: root:root
path: /usr/local/bin/os_client.bash
permissions: '0775'
- content: |
#!/bin/bash
mkdir -p $HOME/bin
mkdir -p $HOME/sbin
echo 'export PATH="$HOME/bin:$HOME/sbin:$PATH"' >>"${HOME}/.bashrc"
cat <<EOT
You have added ${HOME}/bin to the PATH in your .bashrc
file. To update the path without logging out and in
do
. .bashrc
EOT
path: /usr/local/sbin/01-setup-scripts.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
python3 -m pip install idutils
python3 -m pip install sqlfluff
python3 -m pip install pylint
python3 -m pip install progressbar2
python3 -m pip install pybtex
python3 -m pip install feedgen
python3 -m pip install python-dateutil
cat <<EOT >$HOME/bin/ws
#!/bin/bash
echo "Enter Ctlr-c to exit web server"
if [ "$1" != "" ]; then
python3 -m http.server "$1"
else
python3 -m http.server
fi
EOT
chmod 775 $HOME/bin/ws
path: /usr/local/sbin/02-add-python-packages.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
cd
sudo snap install go --classic
export GOPATH=$HOME
mkdir -p "${HOME}/bin"
mkdir -p "${HOME}/src/github.com/caltechlibrary"
for REPO in irdmtools datatools dataset newt; do
cd "${HOME}/src/github.com/caltechlibrary"
git clone "https://github.com/caltechlibrary/${REPO}"
cd "${REPO}"
make
make install
cd "${HOME}/src/github.com/caltechlibrary"
done
cd
path: /usr/local/sbin/03-add-go-and-caltechlibrary-tools.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
path: /usr/local/sbin/04-ghcup-install.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
PATH=$HOME/.ghcup/bin:$PATH
export PATH
cd
git clone https://github.com/jgm/pandoc src/pandoc
cd src/pandoc
make
cp -v $(find . -type f -name pandoc) "${HOME}/bin"
cp -v $(find . -type f -name pandoc) "${HOME}/bin/pandoc-server"
path: /usr/local/sbin/05-pandoc-build.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
cd
git clone https://github.com/PostgREST/postgrest src/postgrest
cd src/postgres
stack build --install-ghc --copy-bins --local-bin-path $HOME/bin
cd
path: /usr/local/sbin/06-postgrest-build.bash
owner: root:root
permissions: '0775'
- content: |
#!/bin/bash
cd
sudo apt update && sudo apt upgrade -y
sudo apt -y install curl lsb-release gnupg2 ca-certificates
curl -fsSL https://artifacts.opensearch.org/publickeys/opensearch.pgp| \
sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/opensearch.gpg
echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch/2.x/apt stable main" | \
sudo tee /etc/apt/sources.list.d/opensearch-2.x.list
echo "deb https://artifacts.opensearch.org/releases/bundle/opensearch-dashboards/2.x/apt stable main" |\
sudo tee -a /etc/apt/sources.list.d/opensearch-2.x.list
sudo apt update
sudo apt list -a opensearch
sudo apt install opensearch=2.5.0
sudo systemctl enable opensearch
sudo systemctl restart opensearch
sudo systemctl status opensearch
cat <<EOT
Connect to opensearch on port 9200. By default it is configured with
SSL and a self signed cert. You need to access v2.5.0 with the default
credentials of 'admin:admin'.
curl -k --user admin:admin https://localhost:9200/_settings
EOT
# Now install elasticdump to dump and restore indexes
sudo apt install nodejs npm
sudo npm install n -g
sudo n latest
sudo npm install elasticdump -g
elasticdump --version
if [ -e /var/run/reboot-required ]; then echo "Rebooting VM"; sudo reboot; fi
path: /usr/local/sbin/07-add-opensearch.bash
owner: root:root
permissions: '0775'
package_upgrade: true
# Install additional packages on first boot
#
# Default: none
#
# if packages are specified, then package_update will be set to true
#
# packages may be supplied as a single package name or as a list
# with the format [<package>, <version>] wherein the specific
# package version will be installed.
packages:
# - ubuntu-desktop
- curl
- openjdk-11-jdk
- lsb-release
- gnupg2
- ca-certificates
- aptitude
- tmux
- micro
- vim
- emacs
- tcsh
- build-essential
- autotools-dev
- autoconf
- automake
- git
- curl
- lynx
- make
- pkg-config
- postgresql-16
- postgresql-16-postgis
- postgresql-16-postgis-scripts
- postgresql-16-mysql-fdw
- postgresql-plpython3-16
- postgresql-16-pllua
- postgresql-16-plpgsql-check
- postgresql-16-semver
- pgloader
- pgtop
- libncurses-dev
- libffi-dev
- libgmp-dev
- libncurses5
- zlib1g-dev
- shellcheck
- python3
- python3-pip
- libffi-dev
- libffi6
- libgmp-dev
- libgmp10
- libncurses-dev
- libncurses5
- libtinfo5
- npm
- jq