forked from vieter-v/vieter
feat(docker): fully migrate build commands to new code
This commit is contained in:
parent
79fd9c1f87
commit
e041682fea
5 changed files with 70 additions and 16 deletions
|
|
@ -22,14 +22,13 @@ pub fn (mut d DockerDaemon) pull_image(image string, tag string) ? {
|
|||
return error(data.message)
|
||||
}
|
||||
|
||||
// Keep reading the body until the pull has completed
|
||||
mut body := d.get_chunked_response_reader()
|
||||
|
||||
mut buf := []u8{len: 1024}
|
||||
|
||||
for {
|
||||
c := body.read(mut buf) or { break }
|
||||
|
||||
print(buf[..c].bytestr())
|
||||
body.read(mut buf) or { break }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -38,6 +37,22 @@ pub fn pull_image(image string, tag string) ?http.Response {
|
|||
return request('POST', urllib.parse('/v1.41/images/create?fromImage=$image&tag=$tag')?)
|
||||
}
|
||||
|
||||
// create_image_from_container creates a new image from a container.
|
||||
pub fn (mut d DockerDaemon) create_image_from_container(id string, repo string, tag string) ?Image {
|
||||
d.send_request('POST', urllib.parse('/v1.41/commit?container=$id&repo=$repo&tag=$tag')?)?
|
||||
head, body := d.read_response()?
|
||||
|
||||
if head.status_code != 201 {
|
||||
data := json.decode(DockerError, body)?
|
||||
|
||||
return error(data.message)
|
||||
}
|
||||
|
||||
data := json.decode(Image, body)?
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
// create_image_from_container creates a new image from a container with the
|
||||
// given repo & tag, given the container's ID.
|
||||
pub fn create_image_from_container(id string, repo string, tag string) ?Image {
|
||||
|
|
@ -56,3 +71,15 @@ pub fn remove_image(id string) ?bool {
|
|||
|
||||
return res.status_code == 200
|
||||
}
|
||||
|
||||
// remove_image removes the image with the given id.
|
||||
pub fn (mut d DockerDaemon) remove_image(id string) ? {
|
||||
d.send_request('DELETE', urllib.parse('/v1.41/images/$id')?)?
|
||||
head, body := d.read_response()?
|
||||
|
||||
if head.status_code != 200 {
|
||||
data := json.decode(DockerError, body)?
|
||||
|
||||
return error(data.message)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ pub fn new_conn() ?&DockerDaemon {
|
|||
return d
|
||||
}
|
||||
|
||||
// close closes the underlying socket connection.
|
||||
pub fn (mut d DockerDaemon) close() ? {
|
||||
d.socket.close()?
|
||||
}
|
||||
|
||||
// send_request sends an HTTP request without body.
|
||||
pub fn (mut d DockerDaemon) send_request(method string, url urllib.URL) ? {
|
||||
req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\n\n'
|
||||
|
|
@ -124,7 +129,7 @@ pub fn (mut d DockerDaemon) read_response() ?(http.Response, string) {
|
|||
mut builder := strings.new_builder(1024)
|
||||
mut body := d.get_chunked_response_reader()
|
||||
|
||||
util.reader_to_writer(mut body, mut builder) ?
|
||||
util.reader_to_writer(mut body, mut builder)?
|
||||
|
||||
return head, builder.str()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue