Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
**/*.iml
**/*.so
**/*db2jcc4.jar
**/*mssql-jdbc-12.10.1.jre11.jar
**/*dxp-license-*.xml
**/*hotfix*.zip
**/.classpath
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile.helper
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ FROM busybox:latest

ARG DATA_DIRECTORY=data

USER 1000
COPY --chown=1000:1000 ${DATA_DIRECTORY} /container-data

COPY --chown=1000:1000 ${DATA_DIRECTORY} /container-data
RUN ([ -d /container-data/sqlserver ] && addgroup --gid 10001 mssql && adduser -S -s /usr/sbin/nologin -h /home/mssql --disabled-password -G mssql -u 10001 mssql) || echo

RUN ([ -d /container-data/sqlserver ] && chown -R 10001:10001 /container-data/sqlserver) || echo

USER 1000
22 changes: 22 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ To shut down the environment, run `./gradlew stop`.

- [Enable MySQL 8.4](#enable-mysql-84)
- [Enable PostgreSQL 16.3](#enable-postgresql-163)
- [Enable DB2 11.5](#enable-db2-115)
- [Enable Microsoft SQL Server 2022](#enable-microsoft-sql-server-2022)
- [Import a database dump](#import-a-database-dump)
- [Enable database partitioning (MySQL and PostgreSQL only)](#enable-database-partitioning-mysql-and-postgresql-only)
- [Configure database port](#configure-database-port)
Expand Down Expand Up @@ -228,6 +230,26 @@ Set the `lr.docker.environment.service.enabled[postgres]` property to `true` or
lr.docker.environment.service.enabled[postgres]=true
```

#### Enable DB2 11.5

Set the `lr.docker.environment.service.enabled[db2]` property to `true` or `1` in `gradle.properties`.

`gradle.properties`:

```properties
lr.docker.environment.service.enabled[db2]=true
```

#### Enable Microsoft SQL Server 2022

Set the `lr.docker.environment.service.enabled[sqlserver]` property to `true` or `1` in `gradle.properties`.

`gradle.properties`:

```properties
lr.docker.environment.service.enabled[sqlserver]=true
```

#### Import a database dump

Database dump files can be added to the `./dumps` directory at the root of the Workspace. They will automatically be copied into the database container.
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ buildDockerImage {
}

dependsOn ":checkForLiferayLicense"
dependsOn ":prepareDB2JDBCDriver"
dependsOn ":prepareJDBCDriver"

mustRunAfter ":importDatabaseDumps"
}

clean {
dependsOn ":cleanPrepareDB2JDBCDriver"
dependsOn ":cleanPrepareJDBCDriver"
dependsOn ":cleanPrepareHotfixes"
dependsOn ":cleanPrepareSelfSignedCert"
dependsOn ":cleanPrepareWebserverConfig"
Expand All @@ -144,7 +144,7 @@ clean {
}

dockerDeploy {
dependsOn ":prepareDB2JDBCDriver"
dependsOn ":prepareJDBCDriver"
dependsOn ":prepareHotfixes"
dependsOn ":prepareYourKitAgent"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,28 +169,40 @@ class Config {
this.useClustering = this.useLiferay && this.clusterNodes > 0

if (this.services.contains("db2")) {
this.databaseType = "db2"
this.useDatabase = true
this.useDatabaseDB2 = true
this.dockerContainerDatabase = "${this.namespace}-database-db2"
}

if (this.services.contains("mariadb")) {
this.databaseType = "db2"
this.useDatabase = true
this.useDatabaseMariaDB = true
this.dockerContainerDatabase = "${this.namespace}-database-mariadb"
}

if (this.services.contains("mysql")) {
this.databaseType = "mysql"
this.useDatabase = true
this.useDatabaseMySQL = true
this.dockerContainerDatabase = "${this.namespace}-database-mysql"
}

if (this.services.contains("postgres")) {
this.databaseType = "postgres"
this.useDatabase = true
this.useDatabasePostgreSQL = true
this.dockerContainerDatabase = "${this.namespace}-database-postgres"
}

if (this.services.contains("sqlserver")) {
this.databaseType = "sqlserver"
this.useDatabase = true
this.useDatabaseSQLServer = true
this.dockerContainerDatabase = "${this.namespace}-database-sqlserver"
}

if (this.services.contains("webserver_http") && this.services.contains("webserver_https")) {
throw new GradleException("Both HTTP and HTTPS are enabled for the webserver service. Only one protocol can be active at a time.")
}
Expand Down Expand Up @@ -277,6 +289,7 @@ class Config {
public List<Map<String, String>> companyVirtualHosts = null
public List<String> composeFiles = new ArrayList<String>()
public String databaseName = "lportal"
public String databaseType = ""
public boolean databasePartitioningEnabled = false
public String dataDirectory = "data"
public Map<String, String> defaultCompanyVirtualHost = null
Expand All @@ -300,6 +313,7 @@ class Config {
public boolean useDatabaseMariaDB = false
public boolean useDatabaseMySQL = false
public boolean useDatabasePostgreSQL = false
public boolean useDatabaseSQLServer = false
public boolean useLiferay = false
public boolean useWebserverHttp = false
public boolean useWebserverHttps = false
Expand Down
13 changes: 11 additions & 2 deletions buildSrc/src/main/groovy/docker-common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ext {
return toResultRows(results, /,/)
}

if (config.useDatabaseDB2) {
if (config.useDatabaseDB2 || config.useDatabaseSQLServer) {
List<String> results = waitForCommand("${getDatabaseAccessCommand(schema)} \"${sql}\"").split("\n").minus("")

results.removeLast()
Expand Down Expand Up @@ -98,7 +98,12 @@ ext {
return config.companyVirtualHosts
}

config.companyVirtualHosts = executeSQLQuery("select companyId, hostname, webId from VirtualHost inner join Company using (companyId) where layoutSetId = 0", config.databaseName)
if (config.useDatabaseSQLServer) {
config.companyVirtualHosts = executeSQLQuery("select VirtualHost.companyId, hostname, webId from VirtualHost inner join Company on (VirtualHost.companyId = Company.companyId) where layoutSetId = 0", config.databaseName)
}
else {
config.companyVirtualHosts = executeSQLQuery("select companyId, hostname, webId from VirtualHost inner join Company using (companyId) where layoutSetId = 0", config.databaseName)
}

return config.companyVirtualHosts
}
Expand Down Expand Up @@ -134,6 +139,10 @@ ext {
"docker compose exec --user db2admin -it database /opt/ibm/db2/V11.5/bin/db2"
].join("\n")
}

if (config.useDatabaseSQLServer) {
return "docker compose exec -it database /opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -C -P Liferay123 -d ${config.databaseName} -Q"
}
}

getCompanyDefaultWebId = {
Expand Down
14 changes: 10 additions & 4 deletions buildSrc/src/main/groovy/docker-liferay-bundle.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -190,15 +192,19 @@ tasks.register("checkForLiferayLicense") {
}
}

tasks.register("prepareDB2JDBCDriver", Copy) {
Configuration dbDriverConfiguration = configurations.findByName(config.databaseType)

tasks.register("prepareJDBCDriver", Copy) {
onlyIf("using the Liferay service") {
config.useLiferay
}
onlyIf("using the DB2 database") {
config.useDatabaseDB2
onlyIf("there is a database driver to install") {
dbDriverConfiguration != null
}

from configurations.db2
from {
dbDriverConfiguration
}
into "configs/common/tomcat/webapps/ROOT/WEB-INF/shielded-container-lib"
}

Expand Down
20 changes: 20 additions & 0 deletions compose-recipes/sqlserver/Dockerfile
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"]
7 changes: 7 additions & 0 deletions compose-recipes/sqlserver/clustering.sqlserver.yaml
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
69 changes: 69 additions & 0 deletions compose-recipes/sqlserver/entrypoint.sh
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
2 changes: 2 additions & 0 deletions compose-recipes/sqlserver/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CREATE DATABASE %DATABASE_NAME%
GO
10 changes: 10 additions & 0 deletions compose-recipes/sqlserver/liferay.sqlserver.yaml
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
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_URL=jdbc:sqlserver://database:1433;databaseName=lportal;Encrypt=True;TrustServerCertificate=True
- LIFERAY_JDBC_PERIOD_DEFAULT_PERIOD_USERNAME=sa
7 changes: 7 additions & 0 deletions compose-recipes/sqlserver/reinit.sql
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
5 changes: 5 additions & 0 deletions compose-recipes/sqlserver/restore.sql
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
30 changes: 30 additions & 0 deletions compose-recipes/sqlserver/service.sqlserver.yaml
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:
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ lr.docker.environment.service.enabled[mail]=false
lr.docker.environment.service.enabled[mariadb]=false
lr.docker.environment.service.enabled[mysql]=false
lr.docker.environment.service.enabled[postgres]=false
lr.docker.environment.service.enabled[sqlserver]=false
lr.docker.environment.service.enabled[webserver_http]=false
lr.docker.environment.service.enabled[webserver_https]=false

Expand Down