-
Notifications
You must be signed in to change notification settings - Fork 95
[JCLOUDS-500] Initial commit for docker #57
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Docker as a local cloud provider | ||
jclouds-docker is a local cloud provider modelled on [docker](http://www.docker.io). Similar to other jclouds supported | ||
providers, it supports the same portable abstractions offered by jclouds. | ||
|
||
##Setup | ||
|
||
Please follow these steps to configure your workstation for jclouds-docker: | ||
|
||
- install the latest Docker release (please visit https://docs.docker.com/installation/) | ||
|
||
#How it works | ||
|
||
|
||
--------------- ------------- | ||
| Image(s) | | Node(s) | | ||
--------------- ------------- | ||
--------- docker remote api ---------------------------------------- | ||
| jclouds | ---------------------------> | DOCKER_HOST | | ||
--------- ---------------------------------------- | ||
|
||
##Components | ||
|
||
- jclouds \- acts as a java client to access to docker features | ||
- DOCKER_HOST \- hosts Docker API, NB: jclouds-docker assumes that the latest Docker is installed | ||
- Image \- it is a docker image that can be started. | ||
- Node \- is a docker container | ||
|
||
## Assumptions | ||
|
||
- jclouds-docker assumes that the images specified using the template are ssh'able. | ||
|
||
-------------- | ||
|
||
#Notes: | ||
- jclouds-docker is still at alpha stage please report any issues you find at [jclouds issues](https://issues.apache.org/jira/browse/JCLOUDS) | ||
- jclouds-docker has been tested on Mac OSX, it might work on Linux iff vbox is running and set up correctly. However, it has never been tried on Windows. | ||
|
||
-------------- | ||
|
||
#Troubleshooting | ||
As jclouds docker support is quite new, issues may occasionally arise. Please follow these steps to get things going again: | ||
|
||
1. Remove all containers | ||
|
||
`$ docker ps -a -q | xargs docker stop | xargs docker rm` | ||
2. remove all the images | ||
|
||
`$ docker images -q | xargs docker rmi` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
|
||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.jclouds.labs</groupId> | ||
<artifactId>jclouds-labs</artifactId> | ||
<version>1.8.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<!-- TODO: when out of labs, switch to org.jclouds.provider --> | ||
<groupId>org.apache.jclouds.labs</groupId> | ||
<artifactId>docker</artifactId> | ||
<name>jclouds docker API</name> | ||
<description>ComputeService binding to the Docker API</description> | ||
<packaging>bundle</packaging> | ||
|
||
<properties> | ||
<test.docker.endpoint>https://localhost:4243</test.docker.endpoint> | ||
<test.docker.api-version>1.10</test.docker.api-version> | ||
<test.docker.identity>FIXME</test.docker.identity> | ||
<test.docker.credential>FIXME</test.docker.credential> | ||
<jclouds.osgi.export>org.jclouds.docker*;version="${project.version}"</jclouds.osgi.export> | ||
<jclouds.osgi.import> | ||
org.jclouds.compute.internal;version="${project.version}", | ||
org.jclouds.rest.internal;version="${project.version}", | ||
org.jclouds*;version="${project.version}", | ||
* | ||
</jclouds.osgi.import> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.jclouds</groupId> | ||
<artifactId>jclouds-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.jclouds</groupId> | ||
<artifactId>jclouds-compute</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-compress</artifactId> | ||
<version>1.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.jclouds.driver</groupId> | ||
<artifactId>jclouds-sshj</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.jclouds</groupId> | ||
<artifactId>jclouds-core</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.jclouds</groupId> | ||
<artifactId>jclouds-compute</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.jclouds.driver</groupId> | ||
<artifactId>jclouds-slf4j</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.squareup.okhttp</groupId> | ||
<artifactId>mockwebserver</artifactId> | ||
<scope>test</scope> | ||
<exclusions> | ||
<!-- Already provided by jclouds-sshj --> | ||
<exclusion> | ||
<groupId>org.bouncycastle</groupId> | ||
<artifactId>bcprov-jdk15on</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>live</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>integration</id> | ||
<phase>integration-test</phase> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<configuration> | ||
<systemPropertyVariables> | ||
<test.docker.endpoint>${test.docker.endpoint}</test.docker.endpoint> | ||
<test.docker.api-version>${test.docker.api-version}</test.docker.api-version> | ||
<test.docker.credential>${test.docker.identity}</test.docker.credential> | ||
<test.docker.credential>${test.docker.credential}</test.docker.credential> | ||
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. Add |
||
</systemPropertyVariables> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> | ||
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. Use a 2 space indent in XML files |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jclouds.docker; | ||
|
||
import org.jclouds.docker.features.RemoteApi; | ||
import org.jclouds.rest.annotations.Delegate; | ||
|
||
import java.io.Closeable; | ||
|
||
/** | ||
* Provides synchronous access to Docker Remote API. | ||
* | ||
* @see <a href="https://docs.docker.com/reference/api/docker_remote_api/"></a> | ||
*/ | ||
public interface DockerApi extends Closeable { | ||
|
||
/** | ||
* Provides synchronous access to Docker Remote API features. | ||
*/ | ||
@Delegate | ||
RemoteApi getRemoteApi(); | ||
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. Is there a plan to add more apis to this class? If not, you could consider moving all methods from the 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. Potentially as they supports many APIs http://docs.docker.io/en/latest/reference/api/ 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. Fine by me then! |
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jclouds.docker; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.google.inject.Module; | ||
import org.jclouds.Constants; | ||
import org.jclouds.apis.ApiMetadata; | ||
import org.jclouds.compute.ComputeServiceContext; | ||
import org.jclouds.compute.config.ComputeServiceProperties; | ||
import org.jclouds.docker.compute.config.DockerComputeServiceContextModule; | ||
import org.jclouds.docker.config.DockerHttpApiModule; | ||
import org.jclouds.docker.config.DockerParserModule; | ||
import org.jclouds.rest.internal.BaseHttpApiMetadata; | ||
|
||
import java.net.URI; | ||
import java.util.Properties; | ||
|
||
import static org.jclouds.compute.config.ComputeServiceProperties.TEMPLATE; | ||
import static org.jclouds.reflect.Reflection2.typeToken; | ||
|
||
/** | ||
* Implementation of {@link BaseHttpApiMetadata} for the Docker API | ||
*/ | ||
public class DockerApiMetadata extends BaseHttpApiMetadata<DockerApi> { | ||
|
||
@Override | ||
public Builder toBuilder() { | ||
return new Builder().fromApiMetadata(this); | ||
} | ||
|
||
public DockerApiMetadata() { | ||
this(new Builder()); | ||
} | ||
|
||
protected DockerApiMetadata(Builder builder) { | ||
super(builder); | ||
} | ||
|
||
public static Properties defaultProperties() { | ||
Properties properties = BaseHttpApiMetadata.defaultProperties(); | ||
properties.setProperty(Constants.PROPERTY_MAX_RETRIES, "15"); | ||
properties.setProperty("jclouds.ssh.retry-auth", "true"); | ||
properties.setProperty(Constants.PROPERTY_CONNECTION_TIMEOUT, "1200000"); // 15 minutes | ||
properties.setProperty(ComputeServiceProperties.IMAGE_LOGIN_USER, "root:password"); | ||
properties.setProperty(TEMPLATE, "osFamily=UBUNTU,os64Bit=true,osVersionMatches=1[012].[01][04]"); | ||
return properties; | ||
} | ||
|
||
public static class Builder extends BaseHttpApiMetadata.Builder<DockerApi, Builder> { | ||
|
||
protected Builder() { | ||
super(DockerApi.class); | ||
id("docker") | ||
.name("Docker API") | ||
.identityName("user") | ||
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. capitalize and change by a text describing what the identity is? |
||
.credentialName("password") | ||
.documentation(URI.create("https://docs.docker.com/reference/api/docker_remote_api/")) | ||
.version("1.12") | ||
.defaultEndpoint("http://127.0.0.1:2375") | ||
.defaultProperties(DockerApiMetadata.defaultProperties()) | ||
.view(typeToken(ComputeServiceContext.class)) | ||
.defaultModules(ImmutableSet.<Class<? extends Module>>of( | ||
DockerHttpApiModule.class, | ||
DockerParserModule.class, | ||
DockerComputeServiceContextModule.class)); | ||
} | ||
|
||
@Override | ||
public DockerApiMetadata build() { | ||
return new DockerApiMetadata(this); | ||
} | ||
|
||
@Override | ||
protected Builder self() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public Builder fromApiMetadata(ApiMetadata in) { | ||
return this; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jclouds.docker.binders; | ||
|
||
import com.google.common.base.Throwables; | ||
import com.google.common.io.Files; | ||
import org.jclouds.compute.reference.ComputeServiceConstants; | ||
import org.jclouds.docker.features.internal.Archives; | ||
import org.jclouds.http.HttpRequest; | ||
import org.jclouds.io.Payload; | ||
import org.jclouds.io.Payloads; | ||
import org.jclouds.logging.Logger; | ||
import org.jclouds.rest.Binder; | ||
|
||
import javax.annotation.Resource; | ||
import javax.inject.Named; | ||
import javax.inject.Singleton; | ||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
@Singleton | ||
public class BindInputStreamToRequest implements Binder { | ||
|
||
@Resource | ||
@Named(ComputeServiceConstants.COMPUTE_LOGGER) | ||
protected Logger logger = Logger.NULL; | ||
|
||
@Override | ||
public <R extends HttpRequest> R bindToRequest(R request, Object input) { | ||
checkArgument(checkNotNull(input, "input") instanceof File, "this binder is only valid for File!"); | ||
checkNotNull(request, "request"); | ||
|
||
File dockerFile = (File) input; | ||
File tmpDir = Files.createTempDir(); | ||
final File targetFile = new File(tmpDir + File.separator + "Dockerfile"); | ||
try { | ||
Files.copy(dockerFile, targetFile); | ||
File archive = Archives.tar(tmpDir, File.createTempFile("archive", ".tar")); | ||
FileInputStream data = new FileInputStream(archive); | ||
Payload payload = Payloads.newInputStreamPayload(data); | ||
payload.getContentMetadata().setContentLength(data.getChannel().size()); | ||
payload.getContentMetadata().setContentType("application/tar"); | ||
request.setPayload(payload); | ||
} catch (IOException e) { | ||
logger.error(e, "Couldn't create a tarball for %s", targetFile); | ||
throw Throwables.propagate(e); | ||
} | ||
return request; | ||
} | ||
} |
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.
Don't think we need this since we're inheriting from the labs parent POM?