Skip to content

Commit

Permalink
persist docker compose migration
Browse files Browse the repository at this point in the history
  • Loading branch information
shalom938 committed Dec 26, 2024
1 parent 5f4d2ee commit 7e57699
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class ComposeFileProvider {

private val composeFile: File = File(COMPOSE_FILE_DIR, COMPOSE_FILE_NAME)

//used top mark if the custom compose file was already downloaded in this IDE session.
// needs to be downloaded only once per IDE session. after IDE restart, a new one will be downloaded and override the old one if it exists.
//customComposeFileDownloaded is used to mark if the custom compose file was already downloaded in this IDE session.
// it needs to be downloaded only once per IDE session. after IDE restart, a new one will be downloaded and override the old one if it exists.
// it may be that a new session has another custom compose file url so need to override the old one.
private var customComposeFileDownloaded = false
private val customComposeFile: File = File(CUSTOM_COMPOSE_FILE_DIR, COMPOSE_FILE_NAME)
Expand All @@ -41,7 +41,7 @@ class ComposeFileProvider {
}

/*
Using a custom compose file is only for development purposes only and not for users.
Using a custom compose file is for development purposes only and not for users.
After using it, it is necessary to remove the local engine and remove the property.
Then install local engine regularly.
Upgrade should not be invoked when using a custom compose file. it will not work, it will always use the same custom url.
Expand All @@ -52,7 +52,12 @@ class ComposeFileProvider {
}


//this method should not be used to get the file itself, it is mainly for logging and debugging.
//use the method getComposeFile() to get the file for running docker operations
fun getComposeFilePath(): String {
if(usingCustomComposeFile()) {
return customComposeFile.absolutePath
}
return composeFile.absolutePath
}

Expand Down Expand Up @@ -94,28 +99,6 @@ class ComposeFileProvider {
}


fun downloadLatestComposeFile(): Boolean {

try {
//try to delete the current file, don't fail if delete fails
deleteFile()
} catch (e: Throwable) {
Log.warnWithException(logger, e, "could not delete compose file")
ErrorReporter.getInstance().reportError("ComposeFileProvider.downloadLatestComposeFile", e)
}

try {
ensureDirectoryExist()
downloadAndCopyFile(URI(COMPOSE_FILE_URL).toURL(), composeFile)
return composeFile.exists()
} catch (e: Throwable) {
Log.warnWithException(logger, e, "could not download latest compose file")
ErrorReporter.getInstance().reportError("ComposeFileProvider.downloadLatestComposeFile", e)
return false
}
}


private fun ensureCustomComposeFileExists(): Boolean {

if (customComposeFileDownloaded && customComposeFile.exists()) {
Expand Down Expand Up @@ -183,6 +166,31 @@ class ComposeFileProvider {
}



//downloadLatestComposeFile is used only for upgrading the local engine
fun downloadLatestComposeFile(): Boolean {

try {
//try to delete the current file, don't fail if delete fails
deleteFile()
} catch (e: Throwable) {
Log.warnWithException(logger, e, "could not delete compose file")
ErrorReporter.getInstance().reportError("ComposeFileProvider.downloadLatestComposeFile", e)
}

try {
ensureDirectoryExist()
downloadAndCopyFile(URI(COMPOSE_FILE_URL).toURL(), composeFile)
return composeFile.exists()
} catch (e: Throwable) {
Log.warnWithException(logger, e, "could not download latest compose file")
ErrorReporter.getInstance().reportError("ComposeFileProvider.downloadLatestComposeFile", e)
return false
}
}



private fun downloadAndCopyFile(url: URL, toFile: File) {

val tempFile = kotlin.io.path.createTempFile("tempComposeFile", ".yml")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class DockerService {
}


//this method should not be used to get the file itself, it is mainly for logging and debugging.
fun getComposeFilePath(): String {
return composeFileProvider.getComposeFilePath()
}
Expand Down

0 comments on commit 7e57699

Please sign in to comment.