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 53d3a71 commit 7f6c2ed
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,11 @@ private static JBLabel createBackendVersionLabel() {
if (someProject != null) {
var about = BackendInfoHolder.getInstance(someProject).getAbout();
if (about != null) {
backendVersionLabel.setText(about.getApplicationVersion() + " (" + DockerService.getInstance().getComposeFilePath() + ")");
if (LocalInstallationFacade.getInstance().isLocalEngineInstalled()) {
backendVersionLabel.setText(about.getApplicationVersion() + " (" + DockerService.getInstance().getComposeFilePath() + ")");
}else{
backendVersionLabel.setText(about.getApplicationVersion());
}
}
}
return backendVersionLabel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ class BackendInfoHolder(val project: Project) : DisposableAdaptor {
}


//do not call this method unless it is really necessary to update on current thread.
//never call it on EDT.
fun updateOnCurrentThread() {
update()
}


fun getAbout(): AboutResult? {
if (aboutRef.get() == null) {
return getAboutInBackgroundNow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class ComposeFileProvider {
}


fun getComposeFilePath(): String {
return composeFile.absolutePath
}



//this method should return a file, if the file does not exist, the docker operation will fail
fun getComposeFile(): File {
ensureComposeFileExists()
Expand Down Expand Up @@ -234,4 +240,5 @@ class ComposeFileProvider {
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package org.digma.intellij.plugin.docker

import com.intellij.openapi.diagnostic.Logger
import org.digma.intellij.plugin.common.findActiveProject
import org.digma.intellij.plugin.errorreporting.ErrorReporter
import org.digma.intellij.plugin.log.Log
import org.digma.intellij.plugin.persistence.PersistenceService
import org.digma.intellij.plugin.posthog.ActivityMonitor
import java.io.File


fun migrateDockerComposeFile(newDockerComposeFilePath: String, logger: Logger) {

/*
in version 2.0.404 of the plugin we changed the location of the docker-conmpose.yml file.
from $TEMP/digma-docker/docker-compose.yml
to
${DigmaPathManager.getLocalFilesDirectoryPath()}/digma-docker/docker-compose.yml
when this plugin version is installed we try to find the old compose file and just copy it to the new location.
after that local engine will continue to work as usual.
if the old file does not exist:
- if local engine is not installed, nothing to do.
- if local engine is installed and not running:
the next time user starts the engine the new file that is bundled with this plugin version will be used.
this may be an update to the engine if the previous engine was older than the compose file that is bundled with this plugin version.
- if local engine is installed and running:
the next time user will try to stop the engine the new file that is bundled with this plugin version will be used.
this may not succeed if the engine was installed with a much older version than what is bundled with this plugin version.
if the steps above succeed local engine will continue to work as usual.
*/

// this is a one time operation, if it fails we don't want to try again.
// this code will run once after the installation of plugin version that contains this code.

try {
//check if this is the first time this plugin version is running
val isFirstRunAfterPersistDockerCompose = PersistenceService.getInstance().isFirstRunAfterPersistDockerCompose()
if (isFirstRunAfterPersistDockerCompose) {
Log.log(logger::info, "first run after persist docker compose")
PersistenceService.getInstance().setIsFirstRunAfterPersistDockerComposeDone()

if (!PersistenceService.getInstance().isLocalEngineInstalled()) {
Log.log(logger::info, "local engine not installed, nothing to do")
return
}

val oldDockerComposeDir = File(System.getProperty("java.io.tmpdir"), COMPOSE_FILE_DIR_NAME)
val oldDockerComposeFile = File(oldDockerComposeDir, COMPOSE_FILE_NAME)
if (oldDockerComposeFile.exists()) {
val newDockerComposeFile = File(newDockerComposeFilePath)
Log.log(logger::info, "old compose file found, moving to new location {}", newDockerComposeFile)
oldDockerComposeFile.copyTo(newDockerComposeFile, overwrite = true)
//do not delete the old file, it may be used by other IDEs. worst case it will stay as zombie file in the user's temp directory
////oldDockerComposeFile.delete()
Log.log(logger::info, "old compose file moved to new location {}", newDockerComposeFile)
} else {
Log.log(logger::info, "old compose file not found")
}

findActiveProject()?.let {
ActivityMonitor.getInstance(it).registerCustomEvent(
"migrated docker compose file", mapOf(
"oldDockerComposeFileExists" to oldDockerComposeFile.exists()
)
)
}

}
} catch (e: Throwable) {
Log.warnWithException(logger, e, "error migrating docker compose file")
ErrorReporter.getInstance().reportError("DockerComposeFileMigration.migrateDockerComposeFile", e)
}
}


This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,13 @@ class DockerService {
}


init {
migrateDockerComposeFile(composeFileProvider.getComposeFilePath(), logger)
}


fun getComposeFilePath(): String {
return composeFileProvider.getComposeFile().absolutePath
return composeFileProvider.getComposeFilePath()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class DockerServiceStarter : DigmaProjectActivity() {

override fun executeProjectStartup(project: Project) {
//initialize the docker service as early as possible
//todo: probably not necessary because it does nothing in its init block
DockerService.getInstance()

service<DockerComposePersistenceFeatureService>().migrateToNewComposeFileLocation(project)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ class LocalInstallationFacade {

fun installEngine(project: Project, resultTask: Consumer<String>) {

if (service<DockerComposePersistenceFeatureService>().updateInProgress.get()) {
Log.log(logger::trace, "installEngine rejected because DockerComposePersistenceFeature update in progress")
resultTask.accept("install engine rejected because DockerComposePersistenceFeature update in progress")
return
}

Log.log(logger::trace, "installEngine requested")
if (isLocalEngineInstalled()) {
Log.log(logger::trace, "installEngine rejected because already installed")
Expand All @@ -77,12 +71,6 @@ class LocalInstallationFacade {

fun stopEngine(project: Project, resultTask: Consumer<String>) {

if (service<DockerComposePersistenceFeatureService>().updateInProgress.get()) {
Log.log(logger::trace, "stopEngine rejected because DockerComposePersistenceFeature update in progress")
resultTask.accept("stop engine rejected because DockerComposePersistenceFeature update in progress")
return
}

Log.log(logger::trace, "stopEngine requested")
doOperation(OP.STOP, resultTask) {
DockerService.getInstance().stopEngine(project, myResultTask)
Expand All @@ -91,12 +79,6 @@ class LocalInstallationFacade {

fun startEngine(project: Project, resultTask: Consumer<String>) {

if (service<DockerComposePersistenceFeatureService>().updateInProgress.get()) {
Log.log(logger::trace, "startEngine rejected because DockerComposePersistenceFeature update in progress")
resultTask.accept("start engine rejected because DockerComposePersistenceFeature update in progress")
return
}

Log.log(logger::trace, "startEngine requested")
if (isLocalEngineRunning(project)) {
Log.log(logger::trace, "startEngine rejected because already running")
Expand All @@ -111,12 +93,6 @@ class LocalInstallationFacade {

fun removeEngine(project: Project, resultTask: Consumer<String>) {

if (service<DockerComposePersistenceFeatureService>().updateInProgress.get()) {
Log.log(logger::trace, "removeEngine rejected because DockerComposePersistenceFeature update in progress")
resultTask.accept("remove engine rejected because DockerComposePersistenceFeature update in progress")
return
}

Log.log(logger::trace, "removeEngine requested")
doOperation(OP.REMOVE, resultTask) {
DockerService.getInstance().removeEngine(project, myResultTask)
Expand Down
Loading

0 comments on commit 7f6c2ed

Please sign in to comment.