-
Notifications
You must be signed in to change notification settings - Fork 22
LPD-62912 Add support for SQL Server #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4ed2a10
08a5ba4
3eaa959
4be3ac9
b264352
9e8d61c
34528f6
bcdf2e5
6e1a882
a4755a7
54389b9
d42d056
1c57262
6123e7b
b95ad14
2af9aaf
55cb71b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,10 +12,12 @@ project.plugins.apply "docker-common" | |
|
|
||
| configurations { | ||
| db2 | ||
| sqlserver | ||
| } | ||
|
|
||
| dependencies { | ||
| db2 group: "com.ibm.db2.jcc", name: "db2jcc", version: "db2jcc4" | ||
| sqlserver group: "com.microsoft.sqlserver", name: "mssql-jdbc", version: "12.10.1.jre11" | ||
| } | ||
|
|
||
| Closure<Boolean> isValidLicenseFile = { | ||
|
|
@@ -190,16 +192,18 @@ tasks.register("checkForLiferayLicense") { | |
| } | ||
| } | ||
|
|
||
| tasks.register("prepareDB2JDBCDriver", Copy) { | ||
| tasks.register("prepareJDBCDriver", Copy) { | ||
| onlyIf("using the Liferay service") { | ||
| config.useLiferay | ||
| } | ||
| onlyIf("using the DB2 database") { | ||
| config.useDatabaseDB2 | ||
| onlyIf("not using MySQL or PostgreSQL") { | ||
| config.useDatabaseDB2 || config.useDatabaseSQLServer | ||
| } | ||
|
|
||
| from configurations.db2 | ||
| into "configs/common/tomcat/webapps/ROOT/WEB-INF/shielded-container-lib" | ||
| if (config.databaseType) { | ||
| from configurations.(config.databaseType) | ||
| into "configs/common/tomcat/webapps/ROOT/WEB-INF/shielded-container-lib" | ||
| } | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Parameterize the existing driver task to accept a configuration |
||
| tasks.register("validateHotfixURLs") { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| FROM mcr.microsoft.com/mssql/server:2022-CU21-ubuntu-22.04 | ||
|
|
||
| USER root | ||
|
|
||
| RUN mkdir -p /var/opt/mssql/backups /var/opt/mssql/data | ||
| RUN chown -R mssql:mssql /var/opt/mssql/ | ||
| RUN touch /startup_log.txt | ||
| RUN chown mssql:mssql /startup_log.txt | ||
|
|
||
| COPY entrypoint.sh /init/ | ||
| COPY init.sql /init/ | ||
| COPY reinit.sql /init | ||
| COPY restore.sql /init | ||
|
|
||
| RUN chown -R mssql:mssql /init && \ | ||
| chmod a+x /init/entrypoint.sh | ||
|
|
||
| USER mssql | ||
|
|
||
| ENTRYPOINT ["/bin/bash", "/init/entrypoint.sh"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| services: | ||
| liferay-cluster-node: | ||
| environment: | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=com.microsoft.sqlserver.jdbc.SQLServerDriver | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=Liferay123 | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL=jdbc:sqlserver://database:1433;databaseName=lportal;Encrypt=True;TrustServerCertificate=True | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=sa |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #!/bin/bash | ||
|
|
||
| _sqlcmd="/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P ${MSSQL_SA_PASSWORD}" | ||
|
|
||
| _has_backup_file() { | ||
| if [[ $(find /var/opt/mssql/backups -type f -iname "*.bak") ]]; then | ||
| echo true | ||
| fi | ||
| } | ||
|
|
||
| _has_database_files() { | ||
| local database_name=${1} | ||
|
|
||
| if [[ $(find /var/opt/mssql/backups -type f -iname "${database_name}.*") ]]; then | ||
| echo true | ||
| fi | ||
| } | ||
|
|
||
| _is_database_present() { | ||
| local database_name=${1} | ||
|
|
||
| if [[ $(${_sqlcmd} -Q "select name from sys.databases" | grep "${database_name}") ]]; then | ||
|
|
||
| echo true | ||
| fi | ||
| } | ||
|
|
||
| create_database() { | ||
| local database_name=${1} | ||
|
|
||
| if [[ $(_is_database_present ${database_name}) ]]; then | ||
| echo "Database ${database_name} is present; skipping database creation" | ||
| elif [[ $(_has_backup_file) ]]; then | ||
| echo "Database backup found; restoring database ${database_name}..." | ||
|
|
||
| sed -i "s,%DATABASE_NAME%,${database_name},g" /init/restore.sql | ||
|
|
||
| local backup_file=$(find /opt/var/mssql/backups -type f -iname "*.bak") | ||
|
|
||
| sed -i "s,%BACKUP_FILE%,${backup_file},g" /init/restore.sql | ||
|
|
||
| ${_sqlcmd} -i /init/restore.sql | ||
| elif [[ $(_has_database_files ${database_name}) ]]; then | ||
| echo "Database files found; reattaching database ${database_name}..." | ||
|
|
||
| sed -i "s,%DATABASE_NAME%,${database_name},g" /init/reinit.sql | ||
|
|
||
| ${_sqlcmd} -i /init/reinit.sql | ||
| else | ||
| echo "Could not find database ${database_name}; creating database..." | ||
|
|
||
| sed -i "s,%DATABASE_NAME%,${database_name},g" /init/init.sql | ||
|
|
||
| ${_sqlcmd} -i /init/init.sql | ||
| fi | ||
| } | ||
|
|
||
| main() { | ||
| until ${_sqlcmd} -Q "SELECT 1"; do | ||
| sleep 1 | ||
| echo "[entrypoint] Waiting for SQL Server to be available..." | ||
| done | ||
|
|
||
| create_database ${COMPOSER_DATABASE_NAME} | ||
| } | ||
|
|
||
| main & /opt/mssql/bin/sqlservr | ||
|
|
||
| wait | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Take one more look at the SQLServer image to make sure that we can't use something they already provide for us. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to Microsoft's documentation, we can only use the UI (which we don't have in this case) or the SQL statements (which we have via SQL files). |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| CREATE DATABASE %DATABASE_NAME% | ||
| GO |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| services: | ||
| liferay: | ||
| depends_on: | ||
| database: | ||
| condition: service_healthy | ||
| environment: | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_DRIVER_UPPERCASEC_LASS_UPPERCASEN_AME=com.microsoft.sqlserver.jdbc.SQLServerDriver | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_PASSWORD=Liferay123 | ||
drewbrokke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL=jdbc:sqlserver://database:1433;databaseName=lportal;Encrypt=True;TrustServerCertificate=True | ||
| - LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=sa | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| USE master | ||
| GO | ||
| CREATE DATABASE %DATABASE_NAME% | ||
| ON (FILENAME = /var/opt/mssql/data/%DATABASE_NAME%.mdf), | ||
| (FILENAME = /var/opt/mssql/data/%DATABASE_NAME%.ldf) | ||
| FOR ATTACH | ||
| GO |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| USE master | ||
| GO | ||
| RESTORE DATABASE %DATABASE_NAME% | ||
| FROM DISK = N'%BACKUP_FILE%' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 5 | ||
| GO |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| services: | ||
| data-helper: | ||
| volumes: | ||
| - sqlserver:/container-data/sqlserver | ||
| database: | ||
| build: ./compose-recipes/sqlserver | ||
| container_name: ${NAMESPACE}-database-sqlserver | ||
| deploy: | ||
| resources: | ||
| limits: | ||
| memory: 2G | ||
| reservations: | ||
| memory: 2G | ||
| environment: | ||
| - ACCEPT_EULA=Y | ||
| - COMPOSER_DATABASE_NAME=${DATABASE_NAME} | ||
| - MSSQL_SA_PASSWORD=Liferay123 | ||
| healthcheck: | ||
| interval: 5s | ||
| retries: 50 | ||
| start_period: 30s | ||
| test: /opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P Liferay123 -Q "select name from sys.databases where name = ${DATABASE_NAME}" | ||
| timeout: 5s | ||
| ports: | ||
| - "1433:1433" | ||
| volumes: | ||
| - dumps:/var/opt/mssql/backups | ||
| - sqlserver:/var/opt/mssql/data | ||
| volumes: | ||
| sqlserver: |
Uh oh!
There was an error while loading. Please reload this page.