-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
CHE-398: Add ability to create local machine snapshots without registry #1351
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
import org.eclipse.che.plugin.docker.client.ProgressMonitor; | ||
import org.eclipse.che.plugin.docker.client.json.ContainerConfig; | ||
import org.eclipse.che.plugin.docker.client.json.HostConfig; | ||
import org.eclipse.che.plugin.docker.client.params.RemoveImageParams; | ||
import org.eclipse.che.plugin.docker.machine.node.DockerNode; | ||
import org.eclipse.che.plugin.docker.machine.node.WorkspaceFolderPathProvider; | ||
import org.slf4j.Logger; | ||
|
@@ -93,6 +94,7 @@ public class DockerInstanceProvider implements InstanceProvider { | |
private final Set<String> commonMachineEnvVariables; | ||
private final String[] allMachinesExtraHosts; | ||
private final String projectFolderPath; | ||
private final boolean snapshotUseRegistry; | ||
|
||
@Inject | ||
public DockerInstanceProvider(DockerConnector docker, | ||
|
@@ -110,9 +112,8 @@ public DockerInstanceProvider(DockerConnector docker, | |
@Named("machine.docker.pull_image") boolean doForcePullOnBuild, | ||
@Named("machine.docker.privilege_mode") boolean privilegeMode, | ||
@Named("machine.docker.dev_machine.machine_env") Set<String> devMachineEnvVariables, | ||
@Named("machine.docker.machine_env") Set<String> allMachinesEnvVariables) | ||
throws IOException { | ||
|
||
@Named("machine.docker.machine_env") Set<String> allMachinesEnvVariables, | ||
@Named("machine.docker.snapshot_use_registry") boolean snapshotUseRegistry) throws IOException { | ||
this.docker = docker; | ||
this.dockerMachineFactory = dockerMachineFactory; | ||
this.dockerInstanceStopDetector = dockerInstanceStopDetector; | ||
|
@@ -122,6 +123,7 @@ public DockerInstanceProvider(DockerConnector docker, | |
this.privilegeMode = privilegeMode; | ||
this.supportedRecipeTypes = Collections.singleton("dockerfile"); | ||
this.projectFolderPath = projectFolderPath; | ||
this.snapshotUseRegistry = snapshotUseRegistry; | ||
|
||
allMachinesSystemVolumes = removeEmptyAndNullValues(allMachinesSystemVolumes); | ||
devMachineSystemVolumes = removeEmptyAndNullValues(devMachineSystemVolumes); | ||
|
@@ -239,9 +241,9 @@ public Instance createInstance(InstanceKey instanceKey, | |
Machine machine, | ||
LineConsumer creationLogsOutput) throws NotFoundException, MachineException { | ||
final DockerInstanceKey dockerInstanceKey = new DockerInstanceKey(instanceKey); | ||
|
||
pullImage(dockerInstanceKey, creationLogsOutput); | ||
|
||
if (snapshotUseRegistry) { | ||
pullImage(dockerInstanceKey, creationLogsOutput); | ||
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. This code is not covered with tests |
||
} | ||
final String userName = EnvironmentContext.getCurrent().getSubject().getUserName(); | ||
final String machineContainerName = containerNameGenerator.generateContainerName(machine.getWorkspaceId(), | ||
machine.getId(), | ||
|
@@ -361,8 +363,16 @@ public void removeInstanceSnapshot(InstanceKey instanceKey) throws SnapshotExcep | |
// use registry API directly because docker doesn't have such API yet | ||
// https://github.com/docker/docker-registry/issues/45 | ||
final DockerInstanceKey dockerInstanceKey = new DockerInstanceKey(instanceKey); | ||
String registry = dockerInstanceKey.getRegistry(); | ||
String repository = dockerInstanceKey.getRepository(); | ||
if (!snapshotUseRegistry) { | ||
try { | ||
docker.removeImage(RemoveImageParams.create(dockerInstanceKey.getFullName())); | ||
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. This code is not covered with tests |
||
} catch (IOException ignore) { | ||
} | ||
return; | ||
} | ||
|
||
final String registry = dockerInstanceKey.getRegistry(); | ||
final String repository = dockerInstanceKey.getRepository(); | ||
if (registry == null || repository == null) { | ||
LOG.error("Failed to remove instance snapshot: invalid instance key: {}", instanceKey); | ||
throw new SnapshotException("Snapshot removing failed. Snapshot attributes are not valid"); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why VisibleForTesting and not only protected access instead of package access ?
also there is no test calling this method so I don't see why it should be "VisibleForTesting"