Skip to content

Commit

Permalink
CODENVY-560 : Introduce new type for providing docker recipes and rem…
Browse files Browse the repository at this point in the history
…ove InstanceKey

#1 new docker recipe type

currently we have type:"dockerfile", location: "http://path-to-recipe"

now we could provide
type:"dockerfile", content: "FROM codenvy/foo\nENV FLORENT=TRUE\"

and
type:"image", location or content: "codenvy/foo"

#2 InstanceKey
Up to now, InstanceKey was used to perform snapshot recovery.
But machine source is a way to provide this information.
So remove InstanceKey and replace it by MachineSource (and DockerMachineSource instead of DockerInstanceKey)

InstanceProvider:
void removeInstanceSnapshot(InstanceKey instanceKey)
--> void removeInstanceSnapshot(MachineSource machineSource)

Instance:
InstanceKey saveToSnapshot(String owner)
--> MachineSource saveToSnapshot(String owner)

#3 InstanceProvider model
To avoid also that MachineManager "knows" the inner type, the recipe handling is moved to the instance provider implementation
And as the snapshot handling is with MachineSource (included in MachineConfig included in Machine), no need to give extra InstanceKey parameter

Replace two previous methods

Instance createInstance(Recipe recipe,
                            Machine machine,
                            LineConsumer creationLogsOutput)

 Instance createInstance(InstanceKey instanceKey,
                            Machine machine,
                            LineConsumer creationLogsOutput) throws NotFoundException, InvalidInstanceSnapshotException, MachineException;

by only one:
   createInstance(Machine machine,
                            LineConsumer creationLogsOutput)

Change-Id: Ia7ea97bc1a44059b4892f5db387f54f2e1709fa3
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf committed May 30, 2016
1 parent d4cbdfe commit a2b5698
Show file tree
Hide file tree
Showing 45 changed files with 1,311 additions and 508 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,10 @@ public interface MachineSource {
* Returns URL or ID
*/
String getLocation();

/**
* @return content of the machine source. No need to use an external link.
*/
String getContent();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
import org.eclipse.che.api.core.NotFoundException;
import org.eclipse.che.api.core.model.machine.Command;
import org.eclipse.che.api.core.model.machine.Machine;
import org.eclipse.che.api.core.model.machine.MachineSource;
import org.eclipse.che.api.core.util.LineConsumer;
import org.eclipse.che.api.core.util.ListLineConsumer;
import org.eclipse.che.api.machine.server.exception.MachineException;
import org.eclipse.che.api.machine.server.model.impl.MachineRuntimeInfoImpl;
import org.eclipse.che.api.machine.server.spi.Instance;
import org.eclipse.che.api.machine.server.spi.InstanceKey;
import org.eclipse.che.api.machine.server.spi.InstanceProcess;
import org.eclipse.che.api.machine.server.spi.impl.AbstractInstance;
import org.eclipse.che.commons.lang.NameGenerator;
Expand Down Expand Up @@ -60,6 +60,11 @@
public class DockerInstance extends AbstractInstance {
private static final Logger LOG = LoggerFactory.getLogger(DockerInstance.class);

/**
* Name of the latest tag used in Docker image.
*/
public static final String LATEST_TAG = "latest";

private static final AtomicInteger pidSequence = new AtomicInteger(1);
private static final String PID_FILE_TEMPLATE = "/tmp/docker-exec-%s.pid";
private static final Pattern PID_FILE_PATH_PATTERN = Pattern.compile(String.format(PID_FILE_TEMPLATE, "([0-9]+)"));
Expand Down Expand Up @@ -191,21 +196,20 @@ public InstanceProcess createProcess(Command command, String outputChannel) thro
}

@Override
public InstanceKey saveToSnapshot(String owner) throws MachineException {
public MachineSource saveToSnapshot(String owner) throws MachineException {
try {
final String repository = generateRepository();
final String tag = "latest";
if(!snapshotUseRegistry) {
commitContainer(owner, repository, tag);
return new DockerInstanceKey(repository, tag);
commitContainer(owner, repository, LATEST_TAG);
return new DockerMachineSource(repository).withTag(LATEST_TAG);
}
final String repositoryName = registry + '/' + repository;
commitContainer(owner, repositoryName, tag);
commitContainer(owner, repositoryName, LATEST_TAG);
//TODO fix this workaround. Docker image is not visible after commit when using swarm
Thread.sleep(2000);
final ProgressLineFormatterImpl lineFormatter = new ProgressLineFormatterImpl();
final String digest = docker.push(PushParams.create(repository)
.withTag(tag)
.withTag(LATEST_TAG)
.withRegistry(registry),
progressMonitor -> {
try {
Expand All @@ -214,7 +218,7 @@ public InstanceKey saveToSnapshot(String owner) throws MachineException {
}
});
docker.removeImage(RemoveImageParams.create(repositoryName).withForce(false));
return new DockerInstanceKey(repository, tag, registry, digest);
return new DockerMachineSource(repository).withRegistry(registry).withDigest(digest).withTag(LATEST_TAG);
} catch (IOException ioEx) {
throw new MachineException(ioEx);
} catch (InterruptedException e) {
Expand Down

This file was deleted.

Loading

0 comments on commit a2b5698

Please sign in to comment.