Skip to content
This repository has been archived by the owner on Jun 22, 2018. It is now read-only.

Commit

Permalink
Private registry using volumes as backend storage
Browse files Browse the repository at this point in the history
  • Loading branch information
floriangrundig committed Jul 29, 2015
1 parent 0e84d0d commit 481d280
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ private boolean successfulPull(String fullLog) {
}

private boolean successfulPush(String fullLog) {
return fullLog.contains("successfully pushed") || fullLog.contains("already pushed");
return fullLog.contains("successfully pushed") || fullLog.contains("already pushed") || fullLog.contains("already exists");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.command.CreateContainerCmd;
import com.github.dockerjava.api.model.Bind;
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.PortBinding;
import com.github.dockerjava.api.model.Volume;
import org.apache.log4j.Logger;
import org.apache.mesos.mini.container.AbstractContainer;
import org.apache.mesos.mini.mesos.MesosClusterConfig;

import java.io.File;
import java.security.SecureRandom;

public class PrivateDockerRegistry extends AbstractContainer {

private final Logger LOGGER = Logger.getLogger(PrivateDockerRegistry.class);
private final MesosClusterConfig config;
private final String REGISTRY_IMAGE_NAME = "registry";
private final String REGISTRY_TAG = "2.0.1";
Expand All @@ -25,6 +28,17 @@ String generateRegistryContainerName() {
return "registry_" + new SecureRandom().nextInt();
}


private File createRegistryStorageDirectory() {
File registryStorageRootDir = new File(".registry");

if (!registryStorageRootDir.exists()) {
LOGGER.info("The private registry storage root directory doesn't exist, creating one...");
registryStorageRootDir.mkdir();
}
return registryStorageRootDir;
}

@Override
protected void pullImage() {
pullImage(REGISTRY_IMAGE_NAME, REGISTRY_TAG);
Expand All @@ -33,9 +47,12 @@ protected void pullImage() {
@Override
protected CreateContainerCmd dockerCommand() {
return dockerClient.createContainerCmd(REGISTRY_IMAGE_NAME + ":" + REGISTRY_TAG)
.withName(generateRegistryContainerName())
.withExposedPorts(ExposedPort.parse("5000"))
.withEnv("REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry")
.withName(generateRegistryContainerName())
.withExposedPorts(ExposedPort.parse("5000"))
.withVolumes(new Volume("/var/lib/registry"))
.withBinds(Bind.parse(
createRegistryStorageDirectory().getAbsolutePath() + ":/var/lib/registry:rw"))
.withEnv("REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry")
.withPortBindings(PortBinding.parse("0.0.0.0:" + config.privateRegistryPort + ":5000"));
}
}

0 comments on commit 481d280

Please sign in to comment.