diff --git a/Dockerfile b/Dockerfile index 499e72de..0b4720d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,9 +12,12 @@ ARG ONLYOFFICE_VALUE=onlyoffice RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d && \ apt-get -y update && \ apt-get -yq install wget apt-transport-https gnupg locales lsb-release && \ + wget -q -O /etc/apt/sources.list.d/mssql-release.list https://packages.microsoft.com/config/ubuntu/22.04/prod.list && \ + wget -q -O - https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \ + apt-get -y update && \ locale-gen en_US.UTF-8 && \ echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula select true | debconf-set-selections && \ - apt-get -yq install \ + ACCEPT_EULA=Y apt-get -yq install \ adduser \ apt-utils \ bomstrip \ @@ -22,6 +25,7 @@ RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d && \ cron \ curl \ htop \ + libaio1 \ libasound2 \ libboost-regex-dev \ libcairo2 \ @@ -34,6 +38,7 @@ RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d && \ libxml2 \ libxss1 \ libxtst6 \ + mssql-tools18 \ mysql-client \ nano \ net-tools \ @@ -48,6 +53,7 @@ RUN echo "#!/bin/sh\nexit 0" > /usr/sbin/policy-rc.d && \ sudo \ supervisor \ ttf-mscorefonts-installer \ + unixodbc-dev \ xvfb \ zlib1g && \ if [ $(ls -l /usr/share/fonts/truetype/msttcorefonts | wc -l) -ne 61 ]; \ @@ -94,6 +100,8 @@ RUN PACKAGE_FILE="${COMPANY_NAME}-${PRODUCT_NAME}${PRODUCT_EDITION}${PACKAGE_VER sed "s/COMPANY_NAME/${COMPANY_NAME}/g" -i /etc/supervisor/conf.d/*.conf && \ service supervisor stop && \ chmod 755 /app/ds/*.sh && \ + printf "\nGO" >> /var/www/onlyoffice/documentserver/server/schema/mssql/createdb.sql && \ + printf "\nGO" >> /var/www/onlyoffice/documentserver/server/schema/mssql/removetbl.sql && \ rm -f /tmp/$PACKAGE_FILE && \ rm -rf /var/log/$COMPANY_NAME && \ rm -rf /var/lib/apt/lists/* diff --git a/README.md b/README.md index f55ae07b..07addf2f 100644 --- a/README.md +++ b/README.md @@ -179,7 +179,7 @@ Below is the complete list of parameters that can be set using environment varia - **SSL_DHPARAM_PATH**: The path to the Diffie-Hellman parameter. Defaults to `/var/www/onlyoffice/Data/certs/dhparam.pem`. - **SSL_VERIFY_CLIENT**: Enable verification of client certificates using the `CA_CERTIFICATES_PATH` file. Defaults to `false` - **NODE_EXTRA_CA_CERTS**: The [NODE_EXTRA_CA_CERTS](https://nodejs.org/api/cli.html#node_extra_ca_certsfile "Node.js documentation") to extend CAs with the extra certificates for Node.js. Defaults to `/var/www/onlyoffice/Data/certs/extra-ca-certs.pem`. -- **DB_TYPE**: The database type. Supported values are `postgres`, `mariadb` or `mysql`. Defaults to `postgres`. +- **DB_TYPE**: The database type. Supported values are `postgres`, `mariadb`, `mysql` or `mssql`. Defaults to `postgres`. - **DB_HOST**: The IP address or the name of the host where the database server is running. - **DB_PORT**: The database server port number. - **DB_NAME**: The name of a database to use. Should be existing on container startup. diff --git a/run-document-server.sh b/run-document-server.sh index 57336196..feb7e95e 100644 --- a/run-document-server.sh +++ b/run-document-server.sh @@ -177,6 +177,9 @@ read_setting(){ "dameng") DB_PORT=${DB_PORT:-"5236"} ;; + "mssql") + DB_PORT=${DB_PORT:-"1433"} + ;; "") DB_PORT=${DB_PORT:-${POSTGRESQL_SERVER_PORT:-$(${JSON} services.CoAuthoring.sql.dbPort)}} ;; @@ -397,6 +400,12 @@ create_postgresql_db(){ sudo -u postgres psql -c "CREATE DATABASE $DB_NAME OWNER $DB_USER;" } +create_mssql_db(){ + MSSQL="/opt/mssql-tools18/bin/sqlcmd -S $DB_HOST,$DB_PORT" + + $MSSQL -U $DB_USER -P "$DB_PWD" -C -Q "IF NOT EXISTS (SELECT * FROM sys.databases WHERE name = '$DB_NAME') BEGIN CREATE DATABASE $DB_NAME; END" +} + create_db_tbl() { case $DB_TYPE in "postgres") @@ -405,6 +414,9 @@ create_db_tbl() { "mariadb"|"mysql") create_mysql_tbl ;; + "mssql") + create_mssql_tbl + ;; esac } @@ -416,6 +428,9 @@ upgrade_db_tbl() { "mariadb"|"mysql") upgrade_mysql_tbl ;; + "mssql") + upgrade_mssql_tbl + ;; esac } @@ -438,6 +453,14 @@ upgrade_mysql_tbl() { $MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/createdb.sql" >/dev/null 2>&1 } +upgrade_mssql_tbl() { + CONN_PARAMS="-U $DB_USER -P "$DB_PWD" -C" + MSSQL="/opt/mssql-tools18/bin/sqlcmd -S $DB_HOST,$DB_PORT $CONN_PARAMS" + + $MSSQL < "$APP_DIR/server/schema/mssql/removetbl.sql" >/dev/null 2>&1 + $MSSQL < "$APP_DIR/server/schema/mssql/createdb.sql" >/dev/null 2>&1 +} + create_postgresql_tbl() { if [ -n "$DB_PWD" ]; then export PGPASSWORD=$DB_PWD @@ -457,6 +480,15 @@ create_mysql_tbl() { $MYSQL $DB_NAME < "$APP_DIR/server/schema/mysql/createdb.sql" >/dev/null 2>&1 } +create_mssql_tbl() { + create_mssql_db + + CONN_PARAMS="-U $DB_USER -P "$DB_PWD" -C" + MSSQL="/opt/mssql-tools18/bin/sqlcmd -S $DB_HOST,$DB_PORT $CONN_PARAMS" + + $MSSQL < "$APP_DIR/server/schema/mssql/createdb.sql" >/dev/null 2>&1 +} + update_welcome_page() { WELCOME_PAGE="${APP_DIR}-example/welcome/docker.html" if [[ -e $WELCOME_PAGE ]]; then diff --git a/tests/mssql/README.md b/tests/mssql/README.md new file mode 100644 index 00000000..3db562ff --- /dev/null +++ b/tests/mssql/README.md @@ -0,0 +1,17 @@ +## Stand Documentserver with mssql + +### How it works + +For deploy stand: + +**STEP 1**: Build you own images: + +```bash +sudo docker-compose build +``` + +**STEP 2**: Wait build complete and when: + +```bash +sudo docker-compose up -d +``` diff --git a/tests/mssql/create_db_user.sh b/tests/mssql/create_db_user.sh new file mode 100755 index 00000000..cbe4c4e0 --- /dev/null +++ b/tests/mssql/create_db_user.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +#generate SA password +SYMBOLS='!#$%&*+,-.:;=?@^_~' +for (( i=1; i <= 20; i++ )); do + PASS=$(tr -dc "A-Za-z0-9$SYMBOLS" /dev/null | grep "affected" | wc -l) + if [ "$RES" -eq "1" ]; then + echo "Database is ready" + break + fi + sleep 10 +done + +#create new db user +$CONNECTION_STR "IF NOT EXISTS (SELECT * FROM sys.sql_logins WHERE name = '$MSSQL_USER') BEGIN CREATE LOGIN $MSSQL_USER WITH PASSWORD = '$MSSQL_PASSWORD' , CHECK_POLICY = OFF; ALTER SERVER ROLE [dbcreator] ADD MEMBER [$MSSQL_USER]; END" diff --git a/tests/mssql/docker-compose.yml b/tests/mssql/docker-compose.yml new file mode 100644 index 00000000..036bbe5f --- /dev/null +++ b/tests/mssql/docker-compose.yml @@ -0,0 +1,38 @@ +version: '2.1' +services: + onlyoffice-documentserver: + container_name: onlyoffice-documentserver + build: + context: ../../. + dockerfile: Dockerfile + depends_on: + - onlyoffice-mssql + environment: + - DB_TYPE=${DB_TYPE:-mssql} + - DB_HOST=${DB_HOST:-onlyoffice-mssql} + - DB_PORT=${DB_PORT:-1433} + - DB_NAME=${DB_NAME:-onlyoffice} + - DB_USER=${DB_USER:-onlyoffice} + - DB_PWD=${DB_PWD:-onlyoffice} + stdin_open: true + restart: always + ports: + - '80:80' + + onlyoffice-mssql: + container_name: onlyoffice-mssql + build: + context: . + dockerfile: mssql.Dockerfile + args: + - MSSQL_DATABASE=${DB_NAME:-onlyoffice} + - MSSQL_USER=${DB_USER:-onlyoffice} + - MSSQL_PASSWORD=${DB_PWD:-onlyoffice} + restart: always + volumes: + - mssql_data:/var/opt/mssql + expose: + - '1433' + +volumes: + mssql_data: diff --git a/tests/mssql/mssql.Dockerfile b/tests/mssql/mssql.Dockerfile new file mode 100644 index 00000000..f6dddc60 --- /dev/null +++ b/tests/mssql/mssql.Dockerfile @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/mssql/server:2022-latest as onlyoffice-mssql + +ENV ACCEPT_EULA=Y + +SHELL ["/bin/bash", "-c"] + +COPY create_db_user.sh /tmp/create_db_user.sh + +RUN bash /tmp/create_db_user.sh