2022-06-22 09:15:00 +02:00
|
|
|
module docker
|
2022-06-18 18:27:26 +02:00
|
|
|
|
2022-12-15 11:55:04 +01:00
|
|
|
import types { Image }
|
2022-06-18 17:59:22 +02:00
|
|
|
|
2022-12-15 11:55:04 +01:00
|
|
|
pub fn (mut d DockerConn) image_inspect(image string) !Image {
|
2023-01-05 12:53:30 +01:00
|
|
|
d.request(.get, '/images/$image/json', {})
|
|
|
|
d.send()!
|
2022-12-15 11:55:04 +01:00
|
|
|
|
2023-01-05 11:52:07 +01:00
|
|
|
data := d.read_json_response<Image>()!
|
2022-12-15 11:55:04 +01:00
|
|
|
|
|
|
|
return data
|
2022-06-18 17:59:22 +02:00
|
|
|
}
|
|
|
|
|
2023-01-05 13:00:18 +01:00
|
|
|
// image_pull pulls the given image:tag.
|
|
|
|
pub fn (mut d DockerConn) image_pull(image string, tag string) ! {
|
2023-01-05 12:53:30 +01:00
|
|
|
d.request(.post, '/images/create', {
|
|
|
|
'fromImage': image
|
|
|
|
'tag': tag
|
|
|
|
})
|
|
|
|
d.send()!
|
2023-01-05 11:52:07 +01:00
|
|
|
d.read_response_head()!
|
|
|
|
d.check_error()!
|
2022-06-18 17:59:22 +02:00
|
|
|
|
|
|
|
// Keep reading the body until the pull has completed
|
|
|
|
mut body := d.get_chunked_response_reader()
|
|
|
|
|
|
|
|
mut buf := []u8{len: 1024}
|
|
|
|
|
|
|
|
for {
|
|
|
|
body.read(mut buf) or { break }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// create_image_from_container creates a new image from a container.
|
2023-01-05 13:00:18 +01:00
|
|
|
pub fn (mut d DockerConn) image_from_container(id string, repo string, tag string) !Image {
|
2023-01-05 12:53:30 +01:00
|
|
|
d.request(.post, '/commit', {
|
|
|
|
'container': id
|
|
|
|
'repo': repo
|
|
|
|
'tag': tag
|
|
|
|
})
|
|
|
|
d.send()!
|
|
|
|
|
|
|
|
return d.read_json_response<Image>()!
|
2022-06-18 17:59:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// remove_image removes the image with the given id.
|
2023-01-05 13:00:18 +01:00
|
|
|
pub fn (mut d DockerConn) image_remove(id string) ! {
|
2023-01-05 12:53:30 +01:00
|
|
|
d.request(.delete, '/images/$id', {})
|
|
|
|
d.send()!
|
2022-12-15 11:17:51 +01:00
|
|
|
d.read_response()!
|
2022-06-18 17:59:22 +02:00
|
|
|
}
|