Skip to content
Open
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
18 changes: 17 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
**/.gitkeep
**/.gitkeep
.github/
.gradle/
build/
buildSrc/
data/
dumps/
exported_data/
build.gradle
gradle.properties
gradle-local.properties
gradlew
gradlew.bat
README.markdown
settings.gradle
source-formatter-suppressions.xml
source-formatter.properties
11 changes: 0 additions & 11 deletions Dockerfile.helper

This file was deleted.

139 changes: 96 additions & 43 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.bmuschko.gradle.docker.tasks.container.DockerCopyFileFromContainer

import com.liferay.docker.workspace.environments.Util

import groovy.json.JsonSlurper
Expand Down Expand Up @@ -32,26 +30,76 @@ withZone(ZoneId.systemDefault())

String timestamp = formatter.format(now)

tasks.register("exportContainerData", DockerCopyFileFromContainer) {
containerId = "${config.namespace}-data-helper"

tasks.register("exportContainerData") {
doFirst {
mkdir hostPath.get()
String hostPath = projectDir.relativePath(file("exported_data/data_${config.namespace}_${timestamp}"))

waitForCommand("docker compose create data-helper")
}
getExistingVolumeNames().each {
String volumeName ->

doLast {
updateGradleLocalProperties(["lr.docker.environment.data.directory" : hostPath.get()])
String backupFileName = "${volumeName.substring(config.namespace.length() + 1)}.tar"

logger.lifecycle("\nUpdated gradle-local.properties with the new value:\nlr.docker.environment.data.directory=${hostPath.get()}")
}
if (backupFileName.equals("dumps.tar")) {
return
}

println "Creating backup of volume ${volumeName} in ${hostPath}/${backupFileName}"
waitForCommand("docker run --rm -v ${volumeName}:/source -v ${hostPath}:/target busybox:latest tar --create --file=/target/${backupFileName} --directory=/source .")
println "Created backup of volume ${volumeName} in ${hostPath}/${backupFileName}"
}

hostPath = provider {
"exported_data/data_${config.namespace}_${timestamp}"
updateGradleLocalProperties(["lr.docker.environment.data.directory" : hostPath])

logger.lifecycle("\nUpdated gradle-local.properties with the new value:\nlr.docker.environment.data.directory=${hostPath}")
}
}

tasks.register("importContainerData") {
mustRunAfter ":buildDockerImage"

doFirst {
List<String> previousVolumeNames = getExistingVolumeNames()

waitForCommand("docker compose build")
waitForCommand("docker compose create")

List<String> currentVolumeNames = getExistingVolumeNames()

project.file(config.dataDirectory).listFiles().each {
File backupFile ->

if (backupFile.isFile() && !backupFile.name.endsWith(".tar")) {
return
}

String volumeName = "${config.namespace}_${backupFile.name}"

if (backupFile.isFile()) {
volumeName = volumeName.substring(0, volumeName.length() - 4)
}

remotePath = "/container-data"
if (!currentVolumeNames.contains(volumeName)) {
return
}

if (previousVolumeNames.contains(volumeName)) {
return
}

println "Restoring backup of volume ${volumeName} using ${backupFile.absolutePath}"

if (backupFile.isFile()) {
waitForCommand("docker run --rm -v ${volumeName}:/target -v ${backupFile.absolutePath}:/source.tar busybox:latest tar --extract --file=/source.tar --directory=/target/")
}
else {
waitForCommand("docker run --rm -v ${volumeName}:/target -v ${backupFile.absolutePath}:/source busybox:latest sh -c 'cp --update --recursive /source/* /target/'")
}

println "Restored backup of volume ${volumeName} using ${backupFile.absolutePath}"

println waitForCommand("docker run --rm -v ${volumeName}:/${volumeName} busybox:latest du -sh /${volumeName}/")
}
}
}

tasks.register("importDocumentLibraryStructure") {
Expand All @@ -74,38 +122,42 @@ tasks.register("importDocumentLibraryStructure") {
}
}

tasks.register("shareWorkspace", Zip) {
archiveFileName = provider {
"workspace_${config.namespace}_${timestamp}.zip"
}

destinationDirectory = file 'shared_workspaces'

tasks.register("shareWorkspace") {
doLast {
logger.lifecycle "\nWorkspace zip: ${archiveFile.get()}\n"
}

exclude ".gitkeep"
exclude ".gitignore"
exclude ".git"
exclude ".gradle"
exclude "binds"
exclude "dumps/*"
exclude "shared_workspaces"
exclude {
FileTreeElement fileTreeElement ->

fileTreeElement.relativePath.pathString.startsWith("exported_data/") &&
!fileTreeElement.relativePath.pathString.startsWith(config.dataDirectory)
}
String fileListFileName = "shared_workspaces/workspace_${config.namespace}_${timestamp}.txt"
String archiveFileName = "shared_workspaces/workspace_${config.namespace}_${timestamp}.7z"

file(fileListFileName).text = fileTree('.') {
exclude ".gitkeep"
exclude ".gitignore"
exclude ".git"
exclude ".gradle"
exclude "binds"
exclude "buildSrc/build"
exclude "buildSrc/.gradle"
exclude "dumps/*"
exclude "shared_workspaces"
exclude {
FileTreeElement fileTreeElement ->

fileTreeElement.relativePath.pathString.startsWith("exported_data/") &&
!fileTreeElement.relativePath.pathString.startsWith(config.dataDirectory)
}

from '.'
include "${config.dataDirectory}/**"
include "**/*"
}.files.collect {
File file ->

include "${config.dataDirectory}/**"
include "**/*"
project.relativePath(file)
}.join("\n")

outputs.upToDateWhen {
false
try {
waitForCommand("7z a -m0=lzma2 -mx=1 -bsp2 ${archiveFileName} -i@${fileListFileName}")
}
finally {
file(fileListFileName).delete()
}
}
}

Expand Down Expand Up @@ -164,6 +216,7 @@ composeUp {
}

dependsOn ":buildDockerImage"
dependsOn ":importContainerData"
dependsOn ":importDatabaseDumps"

doFirst {
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/db2/service.db2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- db2:/container-data/db2
database:
build: ./compose-recipes/db2
container_name: ${NAMESPACE}-database-db2
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/elasticsearch/service.elasticsearch.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- elasticsearch:/container-data/elasticsearch
elasticsearch:
build: ./compose-recipes/elasticsearch
container_name: ${NAMESPACE}-elasticsearch
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/liferay/service.liferay.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- liferay:/container-data/liferay
liferay:
container_name: ${NAMESPACE}-liferay
env_file:
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/mariadb/service.mariadb.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- mariadb:/container-data/mariadb
database:
build: ./compose-recipes/mariadb
container_name: ${NAMESPACE}-database-mariadb
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/mysql/service.mysql.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- mysql:/container-data/mysql
database:
build: ./compose-recipes/mysql
container_name: ${NAMESPACE}-database-mysql
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/postgres/service.postgres.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- postgres:/container-data/postgres
database:
build: ./compose-recipes/postgres
container_name: ${NAMESPACE}-database-postgres
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/sqlserver/service.sqlserver.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- sqlserver:/container-data/sqlserver
database:
build: ./compose-recipes/sqlserver
container_name: ${NAMESPACE}-database-sqlserver
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/webserver-http/service.webserver_http.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- webserver-http:/container-data/webserver-http
webserver:
build: ./compose-recipes/webserver-http
container_name: ${NAMESPACE}-webserver-http
Expand Down
3 changes: 0 additions & 3 deletions compose-recipes/webserver-https/service.webserver_https.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
services:
data-helper:
volumes:
- webserver-https:/container-data/webserver-https
webserver:
build: ./compose-recipes/webserver-https
container_name: ${NAMESPACE}-webserver-https
Expand Down
8 changes: 0 additions & 8 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
name: ${NAMESPACE}
services:
data-helper:
build:
args:
DATA_DIRECTORY: ${DATA_DIRECTORY}
context: .
dockerfile: Dockerfile.helper
container_name: ${NAMESPACE}-data-helper
volumes:
dumps: