feat(containers): add Archive get/put
+ 52
- 4
src/docker/api/containers.cr
@@ -117,8 +117,33 @@ module Docker::Api::Containers
   end
 
   # Get logs from a container
-  def logs(id : String)
-    response = post "/containers/#{id}/logs"
+  def logs(
+    id : String,
+    stdout : Bool? = true,
+    stderr : Bool? = true,
+    follow : Bool? = true,
+  )
+    response = get "/containers/#{id}/logs?stdout=#{stdout ? 1 : 0}&stderr=#{stderr ? 1 : 0}&follow=#{follow ? 1 : 0}"
+    response.body
+  end
+
+  # Retrieve an archive from a container
+  def get_archive(id : String, path : String) : Bytes
+    params = HTTP::Params.build do |param|
+      param.add "path", path
+    end
+    response = get "/containers/#{id}/archive?#{params}"
+    Bytes.new(response.body)
+  end
+
+  # Send an archive to a container
+  def put_archive(id : String, path : String, archive : Bytes)
+    headers = HTTP::Headers.new
+    headers["Content-Type"] = "application/x-tar"
+    params = HTTP::Params.build do |param|
+      param.add "path", path
+    end
+    response = put "/containers/#{id}/archive?#{params}", headers, archive
     response.body
   end
 

new file
src/docker/archive.cr
@@ -0,0 +1,20 @@
+require "./api_client_wrapper"
+require "./api/models/container"
+
+# Interact with a single container that exists on a docker client.
+class Docker::Container
+  include Docker::ApiClientWrapper
+
+  def initialize(@client : Docker::Client, id : String)
+  end
+
+  # Method to get an archive from container
+  def get(path : String)
+    @client.get_archive @id, path
+  end
+
+  # Method to send an archive to container
+  def put(path : String, archive : Bytes)
+    @client.put_archive @id, path, archive
+  end
+end

src/docker/container.cr
@@ -49,6 +49,10 @@ class Docker::Container
     attrs.state.status
   end
 
+  def archive
+    Docker::Archive.new(client, id)
+  end
+
   # Start this container.
   def start
     client.start id

...
@@ -116,8 +120,7 @@ class Docker::Container
 
   # Get logs from the container.
   def logs
-    response = client.logs id
-    response.body
+    client.logs id
   end
 
   # Block until the container stops, then return its exit code.