Skip to content

Commit bc4c95c

Browse files
authored
RANGER-5080: Add docker support for MS SQL Server database (#483)
1 parent 9617503 commit bc4c95c

File tree

15 files changed

+576
-13
lines changed

15 files changed

+576
-13
lines changed

.github/workflows/maven.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
run: |
106106
cp ranger-*.tar.gz dev-support/ranger-docker/dist
107107
cp version dev-support/ranger-docker/dist
108-
108+
109109
- name: Cache downloaded archives
110110
uses: actions/cache@v4
111111
with:
@@ -159,8 +159,9 @@ jobs:
159159
-f docker-compose.ranger-hive.yml \
160160
-f docker-compose.ranger-knox.yml \
161161
-f docker-compose.ranger-ozone.yml up -d
162+
162163
- name: Check status of containers and remove them
163-
run: |
164+
run: |
164165
sleep 60
165166
containers=(ranger ranger-zk ranger-solr ranger-postgres ranger-usersync ranger-tagsync ranger-kms ranger-hadoop ranger-hbase ranger-kafka ranger-hive ranger-knox ozone-om ozone-scm ozone-datanode);
166167
flag=true;

dev-support/ranger-docker/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ UBI_VERSION=latest
3636
MARIADB_VERSION=10.7.3
3737
POSTGRES_VERSION=12
3838
ORACLE_VERSION=23.6
39+
SQLSERVER_VERSION=2019-latest
3940
ENABLE_DB_MOUNT=true
4041
ZK_VERSION=3.9.2
4142
SOLR_VERSION=8.11.3

dev-support/ranger-docker/Dockerfile.ranger

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ FROM ranger AS ranger_oracle
5858
COPY ./downloads/ojdbc8.jar /home/ranger/dist/
5959
RUN mv /home/ranger/dist/ojdbc8.jar /usr/share/java/oracle.jar
6060

61+
FROM ranger AS ranger_sqlserver
62+
COPY ./downloads/mssql-jdbc-12.8.1.jre8.jar /home/ranger/dist/
63+
RUN mv /home/ranger/dist/mssql-jdbc-12.8.1.jre8.jar /usr/share/java/mssql.jar
64+
6165
FROM ranger_${RANGER_DB_TYPE}
6266

6367
USER ranger

dev-support/ranger-docker/Dockerfile.ranger-kms

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ FROM ranger-kms AS ranger_oracle
5858
COPY ./downloads/ojdbc8.jar /home/ranger/dist/
5959
RUN mv /home/ranger/dist/ojdbc8.jar /usr/share/java/oracle.jar
6060

61+
FROM ranger-kms AS ranger_sqlserver
62+
COPY ./downloads/mssql-jdbc-12.8.1.jre8.jar /home/ranger/dist/
63+
RUN mv /home/ranger/dist/mssql-jdbc-12.8.1.jre8.jar /usr/share/java/mssql.jar
64+
6165
FROM ranger_${RANGER_DB_TYPE}
6266

6367
ENTRYPOINT [ "/home/ranger/scripts/ranger-kms.sh" ]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
ARG SQLSERVER_VERSION
18+
19+
FROM mcr.microsoft.com/mssql/server:${SQLSERVER_VERSION}
20+
21+
ENV ACCEPT_EULA=Y
22+
ENV MSSQL_SA_PASSWORD=rangerR0cks!
23+
24+
EXPOSE 1433
25+
26+
USER root
27+
28+
RUN mkdir -p /docker-entrypoint-initdb.d
29+
COPY config/init_mssql.sh /docker-entrypoint-initdb.d/
30+
RUN chown -R mssql /docker-entrypoint-initdb.d/
31+
RUN chmod +x /docker-entrypoint-initdb.d/init_mssql.sh
32+
33+
USER mssql
34+
35+
ENTRYPOINT ["/docker-entrypoint-initdb.d/init_mssql.sh"]
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
/opt/mssql/bin/sqlservr &
20+
21+
# Wait for SQL Server to be ready
22+
echo "Waiting for SQL Server to start..."
23+
RETRIES=30 # Number of retries
24+
SLEEP_INTERVAL=5 # Seconds to wait between retries
25+
for i in $(seq 1 $RETRIES); do
26+
# Try to connect to SQL Server
27+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P "rangerR0cks!" -Q "SELECT 1" -C > /dev/null 2>&1
28+
if [ $? -eq 0 ]; then
29+
echo "SQL Server is ready!"
30+
break
31+
else
32+
echo "SQL Server is not ready yet. Waiting..."
33+
sleep $SLEEP_INTERVAL
34+
fi
35+
done
36+
37+
if [ $i -eq $RETRIES ]; then
38+
echo "SQL Server did not become ready in time. Exiting."
39+
exit 1
40+
fi
41+
42+
/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'rangerR0cks!' -Q "
43+
44+
-- Set the database context
45+
USE master;
46+
47+
-- Create databases
48+
CREATE DATABASE ranger;
49+
CREATE DATABASE rangerkms;
50+
CREATE DATABASE hive;
51+
GO
52+
53+
-- Create users and assign permissions
54+
USE ranger;
55+
CREATE LOGIN rangeradmin WITH PASSWORD = 'rangerR0cks!';
56+
CREATE USER rangeradmin FOR LOGIN rangeradmin;
57+
ALTER ROLE db_owner ADD MEMBER rangeradmin; -- Grant equivalent high-level permissions
58+
GO
59+
60+
USE rangerkms;
61+
CREATE LOGIN rangerkms WITH PASSWORD = 'rangerR0cks!';
62+
CREATE USER rangerkms FOR LOGIN rangerkms;
63+
ALTER ROLE db_owner ADD MEMBER rangerkms; -- Grant equivalent high-level permissions
64+
GO
65+
66+
USE hive;
67+
CREATE LOGIN hive WITH PASSWORD = 'rangerR0cks!';
68+
CREATE USER hive FOR LOGIN hive;
69+
ALTER ROLE db_owner ADD MEMBER hive; -- Grant equivalent high-level permissions
70+
GO
71+
" -C
72+
73+
# Bring SQL Server to the foreground
74+
wait -n
75+
exec /opt/mssql/bin/sqlservr
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
services:
2+
ranger-db:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile.ranger-sqlserver
6+
args:
7+
- SQLSERVER_VERSION=${SQLSERVER_VERSION}
8+
image: ranger-sqlserver
9+
container_name: ranger-sqlserver
10+
hostname: ranger-db.example.com
11+
networks:
12+
- ranger
13+
healthcheck:
14+
test: [
15+
"CMD-SHELL",
16+
"/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P rangerR0cks! -Q \"SELECT 1\" -C" # -C bypasses SSL validation
17+
]
18+
interval: 15s
19+
timeout: 10s
20+
retries: 3
21+
start_period: 10s
22+
23+
networks:
24+
ranger:
25+
name: rangernw

dev-support/ranger-docker/download-archives.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ downloadIfNotPresent() {
4444
downloadIfNotPresent postgresql-42.2.16.jre7.jar "https://search.maven.org/remotecontent?filepath=org/postgresql/postgresql/42.2.16.jre7"
4545
downloadIfNotPresent mysql-connector-java-8.0.28.jar "https://search.maven.org/remotecontent?filepath=mysql/mysql-connector-java/8.0.28"
4646
downloadIfNotPresent ojdbc8.jar https://download.oracle.com/otn-pub/otn_software/jdbc/236
47+
downloadIfNotPresent mssql-jdbc-12.8.1.jre8.jar https://repo1.maven.org/maven2/com/microsoft/sqlserver/mssql-jdbc/12.8.1.jre8
4748
downloadIfNotPresent log4jdbc-1.2.jar https://repo1.maven.org/maven2/com/googlecode/log4jdbc/log4jdbc/1.2
4849

4950
if [[ $# -eq 0 ]]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
-->
21+
<configuration>
22+
<property>
23+
<name>javax.jdo.option.ConnectionURL</name>
24+
<value>jdbc:sqlserver://ranger-db/hive</value>
25+
</property>
26+
<property>
27+
<name>javax.jdo.option.ConnectionDriverName</name>
28+
<value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value>
29+
</property>
30+
<property>
31+
<name>javax.jdo.option.ConnectionUserName</name>
32+
<value>hive</value>
33+
</property>
34+
<property>
35+
<name>javax.jdo.option.ConnectionPassword</name>
36+
<value>rangerR0cks!</value>
37+
</property>
38+
<property>
39+
<name>hive.server2.enable.doAs</name>
40+
<value>false</value>
41+
</property>
42+
<property>
43+
<name>hive.zookeeper.quorum</name>
44+
<value>ranger-zk.example.com</value>
45+
</property>
46+
<property>
47+
<name>hive.zookeeper.client.port</name>
48+
<value>2181</value>
49+
</property>
50+
</configuration>
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
#
17+
# This file provides a list of the deployment variables for the Policy Manager Web Application
18+
#
19+
20+
PYTHON_COMMAND_INVOKER=python3
21+
RANGER_ADMIN_LOG_DIR=/var/log/ranger
22+
RANGER_PID_DIR_PATH=/var/run/ranger
23+
DB_FLAVOR=MSSQL
24+
SQL_CONNECTOR_JAR=/usr/share/java/mssql.jar
25+
CONNECTION_STRING_ADDITIONAL_PARAMS="trustServerCertificate=true;"
26+
RANGER_ADMIN_LOGBACK_CONF_FILE=/opt/ranger/admin/ews/webapp/WEB-INF/classes/conf/logback.xml
27+
28+
db_root_user=sa
29+
db_root_password=rangerR0cks!
30+
db_host=ranger-db
31+
32+
db_name=ranger
33+
db_user=rangeradmin
34+
db_password=rangerR0cks!
35+
36+
postgres_core_file=db/postgres/optimized/current/ranger_core_db_postgres.sql
37+
postgres_audit_file=db/postgres/xa_audit_db_postgres.sql
38+
mysql_core_file=db/mysql/optimized/current/ranger_core_db_mysql.sql
39+
mysql_audit_file=db/mysql/xa_audit_db.sql
40+
oracle_core_file=db/oracle/optimized/current/ranger_core_db_oracle.sql
41+
oracle_audit_file=db/oracle/xa_audit_db_oracle.sql
42+
sqlserver_core_file=db/sqlserver/optimized/current/ranger_core_db_sqlserver.sql
43+
sqlserver_audit_file=db/sqlserver/xa_audit_db_sqlserver.sql
44+
45+
# For over-riding the jdbc url
46+
is_override_db_connection_string=true
47+
db_override_jdbc_connection_string="jdbc:sqlserver://ranger-db;databaseName=ranger;trustServerCertificate=true;"
48+
49+
rangerAdmin_password=rangerR0cks!
50+
rangerTagsync_password=rangerR0cks!
51+
rangerUsersync_password=rangerR0cks!
52+
keyadmin_password=rangerR0cks!
53+
54+
55+
audit_store=solr
56+
audit_solr_urls=http://ranger-solr:8983/solr/ranger_audits
57+
audit_solr_collection_name=ranger_audits
58+
59+
# audit_store=elasticsearch
60+
audit_elasticsearch_urls=
61+
audit_elasticsearch_port=9200
62+
audit_elasticsearch_protocol=http
63+
audit_elasticsearch_user=elastic
64+
audit_elasticsearch_password=elasticsearch
65+
audit_elasticsearch_index=ranger_audits
66+
audit_elasticsearch_bootstrap_enabled=true
67+
68+
policymgr_external_url=http://ranger-admin:6080
69+
policymgr_http_enabled=true
70+
71+
unix_user=ranger
72+
unix_user_pwd=ranger
73+
unix_group=ranger
74+
75+
# Following variables are referenced in db_setup.py. Do not remove these
76+
sqlanywhere_core_file=
77+
cred_keystore_filename=
78+
79+
# ################# DO NOT MODIFY ANY VARIABLES BELOW #########################
80+
#
81+
# --- These deployment variables are not to be modified unless you understand the full impact of the changes
82+
#
83+
################################################################################
84+
XAPOLICYMGR_DIR=$PWD
85+
app_home=$PWD/ews/webapp
86+
TMPFILE=$PWD/.fi_tmp
87+
LOGFILE=$PWD/logfile
88+
LOGFILES="$LOGFILE"
89+
90+
JAVA_BIN='java'
91+
JAVA_VERSION_REQUIRED='1.8'
92+
93+
ranger_admin_max_heap_size=1g
94+
#retry DB and Java patches after the given time in seconds.
95+
PATCH_RETRY_INTERVAL=120
96+
STALE_PATCH_ENTRY_HOLD_TIME=10
97+
98+
hadoop_conf=
99+
authentication_method=UNIX

0 commit comments

Comments
 (0)