Browse Source

added search

Victor Vieux 12 years ago
parent
commit
59a6316f5e

+ 22 - 0
api.go

@@ -365,6 +365,28 @@ func ListenAndServe(addr string, srv *Server) error {
 		}
 	})
 
+	r.Path("/images/search").Methods("GET").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+		log.Println(r.Method, r.RequestURI)
+		if err := r.ParseForm(); err != nil {
+                        http.Error(w, err.Error(), http.StatusInternalServerError)
+                        return
+                }
+
+		term := r.Form.Get("term")
+		outs, err := srv.ImagesSearch(term)
+		if err != nil {
+			httpError(w, err)
+			return
+		}
+		b, err := json.Marshal(outs)
+                if err != nil {
+                        http.Error(w, err.Error(), http.StatusInternalServerError)
+                } else {
+                        w.Header().Set("Content-Type", "application/json")
+                        w.Write(b)
+                }
+	})
+
 	r.Path("/images/{name:*.}/insert").Methods("POST").HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
 		log.Println(r.Method, r.RequestURI)
 		if err := r.ParseForm(); err != nil {

+ 5 - 0
api_params.go

@@ -31,6 +31,11 @@ type ApiContainers struct {
 	Ports   string `json:",omitempty"`
 }
 
+type ApiSearch struct {
+	Name string
+	Description string
+}
+
 type ApiId struct {
 	Id string
 }

+ 38 - 0
commands.go

@@ -53,6 +53,7 @@ func ParseCommands(args ...string) error {
 
 	cmds := map[string]func(args ...string) error{
 		"attach":  CmdAttach,
+		"build": CmdBuild,
 		"commit":  CmdCommit,
 		"diff":    CmdDiff,
 		"export":  CmdExport,
@@ -74,6 +75,7 @@ func ParseCommands(args ...string) error {
 		"rmi":     CmdRmi,
 		"run":     CmdRun,
 		"tag":     CmdTag,
+		"search":	CmdSearch,
 		"start":   CmdStart,
 		"stop":    CmdStop,
 		"version": CmdVersion,
@@ -116,6 +118,7 @@ func cmdHelp(args ...string) error {
 		{"rm", "Remove a container"},
 		{"rmi", "Remove an image"},
 		{"run", "Run a command in a new container"},
+		{"search", "Search for an image in the docker index"},
 		{"start", "Start a stopped container"},
 		{"stop", "Stop a running container"},
 		{"tag", "Tag an image into a repository"},
@@ -948,6 +951,41 @@ func CmdAttach(args ...string) error {
 	return nil
 }
 
+func CmdSearch(args ...string) error {
+	cmd := Subcmd("search", "NAME", "Search the docker index for images")
+	if err := cmd.Parse(args); err != nil {
+		return nil
+	}
+	if cmd.NArg() != 1 {
+		cmd.Usage()
+		return nil
+	}
+	
+	v := url.Values{}
+        v.Set("term", cmd.Arg(0))
+	body, _, err := call("GET", "/images/search?"+v.Encode(), nil)
+        if err != nil {
+                return err
+        }
+
+        var outs []ApiSearch
+        err = json.Unmarshal(body, &outs)
+        if err != nil {
+                return err
+        }
+	fmt.Printf("Found %d results matching your query (\"%s\")\n", len(outs), cmd.Arg(0))
+	w := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
+	fmt.Fprintf(w, "NAME\tDESCRIPTION\n")
+	for _, out := range outs {
+		fmt.Fprintf(w, "%s\t%s\n", out.Name, out.Description)
+	}
+	w.Flush()
+	return nil
+}
+
+// Ports type - Used to parse multiple -p flags
+type ports []int
+
 // ListOpts type
 type ListOpts []string
 

+ 1 - 0
docs/README.md

@@ -15,6 +15,7 @@ Installation
 
 * Work in your own fork of the code, we accept pull requests.
 * Install sphinx: ``pip install sphinx``
+* Install sphinx httpdomain contrib package ``sphinxcontrib-httpdomain``
 * If pip is not available you can probably install it using your favorite package manager as **python-pip**
 
 Usage

+ 1 - 0
docs/sources/commandline/cli.rst

@@ -47,6 +47,7 @@ Available Commands
    command/rm
    command/rmi
    command/run
+   command/search
    command/start
    command/stop
    command/tag

+ 10 - 0
docs/sources/commandline/command/search.rst

@@ -0,0 +1,10 @@
+===================================================================
+``search`` -- Search for an image in the docker index
+===================================================================
+
+::
+
+    Usage: docker search TERM
+
+    Searches for the TERM parameter on the Docker index and prints out a list of repositories
+    that match.

+ 2 - 2
docs/sources/examples/couchdb_data_volumes.rst

@@ -2,9 +2,9 @@
 :description: Sharing data between 2 couchdb databases
 :keywords: docker, example, package installation, networking, couchdb, data volumes
 
-.. _running_redis_service:
+.. _running_couchdb_service:
 
-Create a redis service
+Create a CouchDB service
 ======================
 
 .. include:: example_header.inc

+ 89 - 74
docs/sources/index.html

@@ -7,6 +7,7 @@
 <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="google-site-verification" content="UxV66EKuPe87dgnH1sbrldrx6VsoWMrx5NjwkgUFxXI" />
     <title>Docker - the Linux container engine</title>
 
     <meta name="description" content="Docker encapsulates heterogeneous payloads in standard containers">
@@ -23,6 +24,29 @@
     <script src="_static/js/vendor/jquery-1.9.1.min.js" type="text/javascript" ></script>
     <script src="_static/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js" type="text/javascript" ></script>
 
+    <style>
+        .indexlabel {
+            float: left;
+            width: 150px;
+            display: block;
+            padding: 10px 20px 10px;
+            font-size: 20px;
+            font-weight: 200;
+            background-color: #a30000;
+            color: white;
+            height: 22px;
+        }
+        .searchbutton {
+            font-size: 20px;
+            height: 40px;
+        }
+
+        .debug {
+            border: 1px red dotted;
+        }
+
+    </style>
+
 </head>
 
 
@@ -49,59 +73,40 @@
 </div>
 
 
-<div class="container">
-    <div class="row">
-        <div class="text-center">
-            <img src="_static/img/docker-letters-logo.gif">
-        </div>
-    </div>
-</div>
-
-<div class="container">
+<div class="container" style="margin-top: 30px;">
     <div class="row">
 
         <div class="span12">
             <section class="contentblock header">
 
-                <div class="span6" style="margin:10px 0px 0px 30px; float: right; ">
-                    <div class="js-video" >
-                        <iframe width="640" height="360" src="http://www.youtube.com/embed/wW9CAH9nSLs?feature=player_detailpage&rel=0&modestbranding=1&start=11" frameborder="0" allowfullscreen></iframe>
+                <div class="span5" style="margin-bottom: 15px;">
+                    <div style="text-align: center;" >
+                        <img src="_static/img/docker_letters_500px.png">
+
+                        <h2>The Linux container engine</h2>
                     </div>
-                </div>
 
-                <div style="text-align: center; padding: 50px 30px 50px 30px;">
-		    <h1>Docker</h1>
-		    <h2>The Linux container engine</h2>
-                </div>
+                    <div style="display: block; text-align: center; margin-top: 20px;">
 
-                <div style="display: block; text-align: center; padding: 10px 30px 50px 30px;">
+                        <h5>
+                            Docker is an open-source engine which automates the deployment of applications as highly portable, self-sufficient containers which are independent of hardware, language, framework, packaging system and hosting provider.
+                        </h5>
 
-		<p>
-		Docker is an open-source engine which automates the deployment of applications as highly portable, self-sufficient containers.
-		</p>
+                    </div>
 
-		<p>
-		Docker containers are both <string>hardware-agnostic</strong> and <strong>platform-agnostic</strong>. This means that they can run anywhere, from your
-		laptop to the largest EC2 compute instance and everything in between - and they don't require that you use a particular
-		language, framework or packaging system. That makes them great building blocks for deploying and scaling web apps, databases
-		and backend services without depending on a particular stack or provider.
-		</p>
 
-		<p>
-		Docker is an open-source implementation of the deployment engine which powers <a href="http://dotcloud.com">dotCloud</a>, a popular Platform-as-a-Service.
-		It benefits directly from the experience accumulated over several years of large-scale operation and support of hundreds of thousands
-		of applications and databases.
-		</p>
+                    <div style="display: block; text-align: center; margin-top: 30px;">
+                        <a class="btn btn-custom btn-large" href="gettingstarted/">Let's get started</a>
+                    </div>
 
                 </div>
 
-
-                <div style="display: block; text-align: center;">
-                    <a class="btn btn-custom btn-large" href="gettingstarted/">Let's get started</a>
+                <div class="span6" >
+                    <div class="js-video" >
+                        <iframe width="600" height="360" src="http://www.youtube.com/embed/wW9CAH9nSLs?feature=player_detailpage&rel=0&modestbranding=1&start=11" frameborder="0" allowfullscreen></iframe>
+                    </div>
                 </div>
 
-
-
                 <br style="clear: both"/>
             </section>
         </div>
@@ -111,31 +116,56 @@
 <div class="container">
     <div class="row">
 
-        <div class="span3">
+        <div class="span6">
             <section class="contentblock">
                 <h4>Heterogeneous payloads</h4>
                 <p>Any combination of binaries, libraries, configuration files, scripts, virtualenvs, jars, gems, tarballs, you name it. No more juggling between domain-specific tools. Docker can deploy and run them all.</p>
-            </section>
-        </div>
-        <div class="span3">
-            <section class="contentblock">
                 <h4>Any server</h4>
                 <p>Docker can run on any x64 machine with a modern linux kernel - whether it's a laptop, a bare metal server or a VM. This makes it perfect for multi-cloud deployments.</p>
+                <h4>Isolation</h4>
+                <p>Docker isolates processes from each other and from the underlying host, using lightweight containers.</p>
+                <h4>Repeatability</h4>
+                <p>Because each container is isolated in its own filesystem, they behave the same regardless of where, when, and alongside what they run.</p>
             </section>
         </div>
-        <div class="span3">
+        <div class="span6">
             <section class="contentblock">
-                <h4>Isolation</h4>
-                <p>docker isolates processes from each other and from the underlying host, using lightweight containers.</p>
+                <h1>New! Docker Index</h1>
+                On the Docker Index you can find and explore pre-made container images. It allows you to share your images and download them.
+
+                <br><br>
+                <a href="https://index.docker.io" target="_blank">
+                    <div class="indexlabel">
+                        DOCKER index
+                    </div>
+                </a>
+                &nbsp;
+                <input type="button" class="searchbutton" type="submit" value="Search images"
+                       onClick="window.open('https://index.docker.io')" />
+
             </section>
-        </div>
-        <div class="span3">
             <section class="contentblock">
-                <h4>Repeatability</h4>
-                <p>Because containers are isolated in their own filesystem, they behave the same regardless of where, when, and alongside what they run.</p>
+                <div id="wufoo-z7x3p3">
+                    Fill out my <a href="http://dotclouddocker.wufoo.com/forms/z7x3p3">online form</a>.
+                </div>
+                <script type="text/javascript">var z7x3p3;(function(d, t) {
+                    var s = d.createElement(t), options = {
+                        'userName':'dotclouddocker',
+                        'formHash':'z7x3p3',
+                        'autoResize':true,
+                        'height':'577',
+                        'async':true,
+                        'header':'show'};
+                    s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'wufoo.com/scripts/embed/form.js';
+                    s.onload = s.onreadystatechange = function() {
+                        var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;
+                        try { z7x3p3 = new WufooForm();z7x3p3.initialize(options);z7x3p3.display(); } catch (e) {}};
+                    var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);
+                })(document, 'script');</script>
             </section>
         </div>
     </div>
+
 </div>
 
 <style>
@@ -183,18 +213,12 @@
     </div>
 </div>
 
-<!--         <p>Docker encapsulates heterogeneous payloads in <a href="#container">Standard Containers</a>, and runs them on any server with strong guarantees of isolation and repeatability.</p>
-
-        <p>It is a great building block for automating distributed systems: large-scale web deployments, database clusters, continuous deployment systems, private PaaS, service-oriented architectures, etc.</p>
-
- -->
 <div class="container">
     <div class="row">
         <div class="span6">
 
             <section class="contentblock">
 
-                <!-- <img src="_static/lego_docker.jpg" width="600px" style="float:right; margin-left: 10px"> -->
                 <h2>Notable features</h2>
 
                 <ul>
@@ -218,35 +242,26 @@
                     <li><a href="http://lxc.sourceforge.net/">lxc</a>, a set of convenience scripts to simplify the creation of linux containers.</li>
                 </ul>
 
+                <h2>Who started it</h2>
+                <p>
+                    Docker is an open-source implementation of the deployment engine which powers <a href="http://dotcloud.com">dotCloud</a>, a popular Platform-as-a-Service.</p>
+
+                <p>It benefits directly from the experience accumulated over several years of large-scale operation and support of hundreds of thousands
+                    of applications and databases.
+                </p>
+
             </section>
         </div>
 
         <div class="span6">
-            <section class="contentblock">
-                <div id="wufoo-z7x3p3">
-                    Fill out my <a href="http://dotclouddocker.wufoo.com/forms/z7x3p3">online form</a>.
-                </div>
-                <script type="text/javascript">var z7x3p3;(function(d, t) {
-                    var s = d.createElement(t), options = {
-                        'userName':'dotclouddocker',
-                        'formHash':'z7x3p3',
-                        'autoResize':true,
-                        'height':'577',
-                        'async':true,
-                        'header':'show'};
-                    s.src = ('https:' == d.location.protocol ? 'https://' : 'http://') + 'wufoo.com/scripts/embed/form.js';
-                    s.onload = s.onreadystatechange = function() {
-                        var rs = this.readyState; if (rs) if (rs != 'complete') if (rs != 'loaded') return;
-                        try { z7x3p3 = new WufooForm();z7x3p3.initialize(options);z7x3p3.display(); } catch (e) {}};
-                    var scr = d.getElementsByTagName(t)[0], par = scr.parentNode; par.insertBefore(s, scr);
-                })(document, 'script');</script>
-            </section>
+
 
             <section class="contentblock">
                 <h3 id="twitter">Twitter</h3>
                 <a class="twitter-timeline" href="https://twitter.com/getdocker" data-widget-id="312730839718957056">Tweets by @getdocker</a>
                 <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
             </section>
+
         </div>
     </div>
 

+ 2 - 1
docs/theme/docker/layout.html

@@ -6,6 +6,7 @@
 <head>
     <meta charset="utf-8">
     <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta name="google-site-verification" content="UxV66EKuPe87dgnH1sbrldrx6VsoWMrx5NjwkgUFxXI" />
 
     <title>Docker - {{ meta['title'] if meta and meta['title'] else title }}</title>
 
@@ -74,7 +75,7 @@
             </div>
 
             <div style="margin-left: -12px; float: left;">
-                <a href="{{ pathto('./', 1) }}"><img style="margin-top: 12px; height: 38px" src="{{ pathto('_static/img/docker-letters-logo.gif', 1) }}"></a>
+                <a href="http://www.docker.io"><img style="margin-top: 12px; height: 38px" src="{{ pathto('_static/img/docker-letters-logo.gif', 1) }}"></a>
             </div>
         </div>
 

+ 1 - 1
docs/theme/docker/static/css/main.css

@@ -82,7 +82,7 @@ h4 {
 .btn-custom {
   background-color: #292929 !important;
   background-repeat: repeat-x;
-  filter: progid:DXImageTransform.Microsoft.gradient(startColorstr="#515151", endColorstr="#282828");
+  filter: progid:dximagetransform.microsoft.gradient(startColorstr="#515151", endColorstr="#282828");
   background-image: -khtml-gradient(linear, left top, left bottom, from(#515151), to(#282828));
   background-image: -moz-linear-gradient(top, #515151, #282828);
   background-image: -ms-linear-gradient(top, #515151, #282828);

BIN
docs/theme/docker/static/img/docker_letters_500px.png


+ 36 - 0
registry.go

@@ -9,6 +9,7 @@ import (
 	"io"
 	"io/ioutil"
 	"net/http"
+	"net/url"
 	"path"
 	"strings"
 )
@@ -211,6 +212,11 @@ func (graph *Graph) getRemoteTags(stdout io.Writer, registries []string, reposit
 
 func (graph *Graph) getImageForTag(stdout io.Writer, tag, remote, registry string, token []string) (string, error) {
 	client := graph.getHttpClient()
+
+	if !strings.Contains(remote, "/") {
+		remote = "library/" + remote
+	}
+
 	registryEndpoint := "https://" + registry + "/v1"
 	repositoryTarget := registryEndpoint + "/repositories/" + remote + "/tags/" + tag
 
@@ -638,3 +644,33 @@ func (graph *Graph) Checksums(output io.Writer, repo Repository) ([]map[string]s
 	}
 	return result, nil
 }
+
+type SearchResults struct {
+	Query      string              `json:"query"`
+	NumResults int                 `json:"num_results"`
+	Results    []map[string]string `json:"results"`
+}
+
+func (graph *Graph) SearchRepositories(stdout io.Writer, term string) (*SearchResults, error) {
+	client := graph.getHttpClient()
+	u := INDEX_ENDPOINT + "/search?q=" + url.QueryEscape(term)
+	req, err := http.NewRequest("GET", u, nil)
+	if err != nil {
+		return nil, err
+	}
+	res, err := client.Do(req)
+	if err != nil {
+		return nil, err
+	}
+	defer res.Body.Close()
+	if res.StatusCode != 200 {
+		return nil, fmt.Errorf("Unexepected status code %d", res.StatusCode)
+	}
+	rawData, err := ioutil.ReadAll(res.Body)
+	if err != nil {
+		return nil, err
+	}
+	result := new(SearchResults)
+	err = json.Unmarshal(rawData, result)
+	return result, err
+}

+ 1 - 1
runtime_test.go

@@ -72,7 +72,7 @@ func init() {
 		runtime: runtime,
 	}
 	// Retrieve the Image
-	if err := srv.ImagePull(unitTestImageName, os.Stdout); err != nil {
+	if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout); err != nil {
 		panic(err)
 	}
 }

+ 19 - 0
server.go

@@ -43,6 +43,25 @@ func (srv *Server) ContainerExport(name string, file *os.File) error {
 	return fmt.Errorf("No such container: %s", name)
 }
 
+func (srv *Server) ImagesSearch(term string) ([]ApiSearch, error) {
+	results, err := srv.runtime.graph.SearchRepositories(nil, term)
+	if err != nil {
+                return nil, err
+        }
+	
+	var outs []ApiSearch
+	for _, repo := range results.Results {
+		var out ApiSearch
+		out.Description = repo["description"]
+                if len(out.Description) > 45 {
+                        out.Description = Trunc(out.Description, 42) + "..."
+                }
+		out.Name = repo["name"]
+		outs = append(outs, out)
+	}
+	return outs, nil
+}
+
 func (srv *Server) ImageInsert(name, url, path string, stdout *os.File) error {
 	img, err := srv.runtime.repositories.LookupImage(name)
 	if err != nil {

+ 2 - 2
server_test.go

@@ -13,7 +13,7 @@ func TestCreateRm(t *testing.T) {
 
 	srv := &Server{runtime: runtime}
 
-	config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "echo test"})
+	config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "echo test"}, nil)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -46,7 +46,7 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
 
 	srv := &Server{runtime: runtime}
 
-	config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "/bin/cat"})
+	config, _, err := ParseRun([]string{GetTestImage(runtime).Id, "/bin/cat"}, nil)
 	if err != nil {
 		t.Fatal(err)
 	}