Skip to content

Commit 0c2600a

Browse files
committed
initial commit
0 parents  commit 0c2600a

19 files changed

+673
-0
lines changed

Diff for: .env

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
STACK_VERSION=8.6.1

Diff for: README.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# python-cli-sqlserver-ssl-to-multi-node-elasticsearch-client-without-ssl-simple
2+
3+
## Description
4+
Reads a multi node cluster for data in `animal-demo` document.
5+
6+
Uses `dog` table then covverts it to json for
7+
elasticsearch to use.
8+
9+
Sql server uses self-signed ssl.
10+
11+
## Tech stack
12+
- python
13+
- pymssql
14+
- sqlalchemy
15+
- elasticsearch
16+
- kibana
17+
- mssql
18+
19+
## Docker stack
20+
- alpine:edge
21+
- python
22+
- elasticsearch
23+
- kibana
24+
- mcr.microsoft.com/mssql/server:2017-CU17-ubuntu
25+
26+
## To run
27+
`sudo ./install.sh -u`
28+
29+
## To stop (optional)
30+
`sudo ./install.sh -d`
31+
32+
## For help
33+
`sudo ./install.sh -h`
34+
35+
## Credit
36+
- [Docker setup](https://lynn-kwong.medium.com/all-you-need-to-know-about-using-elasticsearch-in-python-b9ed00e0fdf0)
37+
- [Search setup](https://www.elastic.co/guide/en/elasticsearch/client/python-api/master/examples.html)

Diff for: db/Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# We choose exact tag (not 'latest'), to be sure that new version won't break creating image
2+
FROM mcr.microsoft.com/mssql/server:2017-CU17-ubuntu
3+
4+
COPY conf /var/opt/mssql
5+
6+
COPY cert/server.crt /etc/ssl/certs
7+
COPY cert/server.key /etc/ssl/private
8+
9+
# Create app directory
10+
RUN mkdir -p /usr/src/app
11+
WORKDIR /usr/src/app
12+
13+
# Copy initialization scripts
14+
COPY . /usr/src/app
15+
# COPY sql /usr/src/app
16+
17+
# Grant permissions for the run-initialization script to be executable
18+
RUN chmod +x /usr/src/app/run-initialization.sh
19+
20+
# Set environment variables, not to have to write them with docker run command
21+
# Note: make sure that your password matches what is in the run-initialization script
22+
ENV SA_PASSWORD z!x<?oB1ab
23+
ENV ACCEPT_EULA Y
24+
ENV MSSQL_PID Express
25+
26+
# Expose port 1433 in case accesing from other container
27+
EXPOSE 1433
28+
29+
# Run Microsoft SQl Server and initialization script (at the same time)
30+
# Note: If you want to start MsSQL only (without initialization script) you can comment bellow line out, CMD entry from base image will be taken
31+
CMD /bin/bash ./entrypoint.sh

Diff for: db/conf/mssql.conf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[network]
2+
tlscert = /etc/ssl/certs/server.crt
3+
tlskey = /etc/ssl/private/server.key
4+
tlsprotocols = 1.2
5+
forceencryption = 1

Diff for: db/entrypoint.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/usr/src/app/run-initialization.sh & /opt/mssql/bin/sqlservr

Diff for: db/run-initialization.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function do-sql()
2+
{
3+
local cmd=/opt/mssql-tools/bin/sqlcmd
4+
local server="localhost"
5+
local user="sa"
6+
local password="z!x<?oB1ab"
7+
local sql_file=$1
8+
9+
$cmd -S $server -U $user -P $password -i $sql_file
10+
}
11+
# Wait to be sure that SQL Server came up
12+
sleep 90s
13+
14+
# Run the setup script to create the DB and the schema in the DB
15+
# Note: make sure that your password matches what is in the Dockerfile
16+
17+
echo "processing file /usr/src/app/schema.sql"
18+
do-sql /usr/src/app/schema.sql

Diff for: db/schema.sql

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
USE master;
2+
Go
3+
4+
CREATE DATABASE animal;
5+
Go
6+
7+
CREATE TABLE dbo.dog (
8+
id INT PRIMARY KEY IDENTITY(1,1),
9+
breed VARCHAR(20) NOT NULL,
10+
color VARCHAR(20) NOT NULL
11+
);
12+
Go
13+
14+
INSERT INTO dbo.dog (breed, color)
15+
VALUES
16+
('Am Bulldog', 'White'),
17+
('Blue Tick', 'Grey'),
18+
('Labrador', 'Black'),
19+
('Gr Shepard', 'Brown');
20+
Go

Diff for: docker-compose.yml

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
version: "3.4"
2+
3+
services:
4+
5+
db:
6+
build: db
7+
8+
py-srv:
9+
build: py-srv
10+
healthcheck:
11+
test: "exit 0"
12+
command: sh -c "/wait && python app.py"
13+
environment:
14+
- WAIT_HOSTS=db:1433,es1:9200,es2:9200,es3:9200
15+
- WAIT_HOSTS_TIMEOUT=300
16+
- WAIT_SLEEP_INTERVAL=30
17+
- WAIT_HOST_CONNECT_TIMEOUT=30
18+
depends_on:
19+
- db
20+
- es1
21+
- es2
22+
- es3
23+
- kibana
24+
links:
25+
- "db:db"
26+
- "es1:es1"
27+
- "es2:es2"
28+
- "es3:es3"
29+
30+
es1:
31+
image: elasticsearch:${STACK_VERSION}
32+
container_name: es1
33+
hostname: es1
34+
restart: unless-stopped
35+
healthcheck:
36+
test: "exit 0"
37+
environment:
38+
- "node.store.allow_mmap=false"
39+
- "node.name=es1"
40+
- "bootstrap.memory_lock=true"
41+
- "cluster.name=es-cluster"
42+
- "discovery.seed_hosts=es2,es3"
43+
- "cluster.initial_master_nodes=es1,es2,es3"
44+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.index.number_of_replicas=0"
45+
- "xpack.security.enabled=false"
46+
- "xpack.security.http.ssl.enabled=false"
47+
- "xpack.security.transport.ssl.enabled=false"
48+
- "xpack.ml.enabled=false"
49+
- "xpack.graph.enabled=false"
50+
- "xpack.watcher.enabled=false"
51+
ulimits:
52+
memlock:
53+
soft: -1
54+
hard: -1
55+
ports:
56+
- 9200:9200
57+
# volumes:
58+
# - ./es/es1/data:/usr/share/elasticsearch/data
59+
# - ./es/es1/log:/usr/share/elasticsearch/log
60+
61+
es2:
62+
image: elasticsearch:${STACK_VERSION}
63+
container_name: es2
64+
hostname: es2
65+
restart: unless-stopped
66+
healthcheck:
67+
test: "exit 0"
68+
environment:
69+
- "node.store.allow_mmap=false"
70+
- "node.name=es2"
71+
- "bootstrap.memory_lock=true"
72+
- "cluster.name=es-cluster"
73+
- "discovery.seed_hosts=es3,es1"
74+
- "cluster.initial_master_nodes=es1,es2,es3"
75+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.index.number_of_replicas=0"
76+
- "xpack.security.enabled=false"
77+
- "xpack.security.http.ssl.enabled=false"
78+
- "xpack.security.transport.ssl.enabled=false"
79+
- "xpack.ml.enabled=false"
80+
- "xpack.graph.enabled=false"
81+
- "xpack.watcher.enabled=false"
82+
ulimits:
83+
memlock:
84+
soft: -1
85+
hard: -1
86+
ports:
87+
- 9201:9200
88+
# volumes:
89+
# - ./es/es2/data:/usr/share/elasticsearch/data
90+
# - ./es/es2/log:/usr/share/elasticsearch/log
91+
92+
es3:
93+
image: elasticsearch:${STACK_VERSION}
94+
container_name: es3
95+
hostname: es3
96+
restart: unless-stopped
97+
healthcheck:
98+
test: "exit 0"
99+
environment:
100+
- "node.store.allow_mmap=false"
101+
- "node.name=es3"
102+
- "bootstrap.memory_lock=true"
103+
- "cluster.name=es-cluster"
104+
- "discovery.seed_hosts=es2,es1"
105+
- "cluster.initial_master_nodes=es1,es2,es3"
106+
- "ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.index.number_of_replicas=0"
107+
- "xpack.security.enabled=false"
108+
- "xpack.security.http.ssl.enabled=false"
109+
- "xpack.security.transport.ssl.enabled=false"
110+
- "xpack.ml.enabled=false"
111+
- "xpack.graph.enabled=false"
112+
- "xpack.watcher.enabled=false"
113+
ulimits:
114+
memlock:
115+
soft: -1
116+
hard: -1
117+
ports:
118+
- 9202:9200
119+
# volumes:
120+
# - ./es/es3/data:/usr/share/elasticsearch/data
121+
# - ./es/es3/log:/usr/share/elasticsearch/log
122+
123+
kibana:
124+
image: kibana:${STACK_VERSION}
125+
healthcheck:
126+
test: "exit 0"
127+
environment:
128+
- "ELASTICSEARCH_HOSTS=http://es1:9200"
129+
- "SERVER_NAME=127.0.0.1"
130+
ports:
131+
- 5601:5601
132+
depends_on:
133+
- es1
134+
- es2
135+
- es3

0 commit comments

Comments
 (0)