chore: added roadmap; started volume_list
ci/woodpecker/push/lint Pipeline failed Details

jef
Jef Roosens 2022-06-18 22:17:52 +02:00
parent f92f73b0ff
commit 843db9e3ec
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 184 additions and 8 deletions

143
ROADMAP.md 100644
View File

@ -0,0 +1,143 @@
# Roadmap
This file keeps track of which parts of the Docker Engine API v1.41 are
currently supported. Note that in-development support is not listed here, so as
long as the full functionality isn't supported, it won't be noted.
This list was taking from the [API
reference](https://docs.docker.com/engine/api/v1.41/).
* Containers
- [ ] List containers
- [ ] Create a container
- [ ] Inspect a container
- [ ] List processes running inside a container
- [ ] Get container logs
- [ ] Get changes on a containers filesystem
- [ ] Export a container
- [ ] Get container stats based on resource usage
- [ ] Resize a container TTY
- [ ] Start a container
- [ ] Stop a container
- [ ] Restart a container
- [ ] Kill a container
- [ ] Update a container
- [ ] Rename a container
- [ ] Pause a container
- [ ] Unpause a container
- [ ] Attach to a container
- [ ] Attach to a container via a websocket
- [ ] Wait for a container
- [ ] Remove a container
- [ ] Get information about files in a container
- [ ] Get an archive of a filesystem resource in a container
- [ ] Extract an archive of files or folders to a directory in a container
- [ ] Delete stopped containers
* Images
- [ ] List images
- [ ] Build an image
- [ ] Delete builder cache
- [ ] Create an image
- [ ] Inspect an image
- [ ] Get the history of an image
- [ ] Push an image
- [ ] Tag an image
- [ ] Remove an image
- [ ] Search images
- [ ] Delete unused images
- [ ] Create a new image from a container
- [ ] Export an image
- [ ] Export several images
- [ ] Import images
* Networks
- [ ] List networks
- [ ] Inspect a network
- [ ] Remove a network
- [ ] Create a network
- [ ] Connect a container to a network
- [ ] Disconnect a container from a network
- [ ] Delete unused networks
* Volumes
- [ ] List volumes
- [ ] Create a volume
- [ ] Inspect a volume
- [ ] Remove a volume
- [ ] Delete unused volumes
* Exec
- [ ] Create an exec instance
- [ ] Start an exec instance
- [ ] Resize an exec instance
- [ ] Inspect an exec instance
* Swarm
- [ ] Inspect swarm
- [ ] Initialize a new swarm
- [ ] Join an existing swarm
- [ ] Leave a swarm
- [ ] Update a swarm
- [ ] Get the unlock key
- [ ] Unlock a locked manager
* Nodes
- [ ] List nodes
- [ ] Inspect a node
- [ ] Delete a node
- [ ] Update a node
* Services
- [ ] List services
- [ ] Create a service
- [ ] Inspect a service
- [ ] Delete a service
- [ ] Update a service
- [ ] Get service logs
* Tasks
- [ ] List tasks
- [ ] Inspect a task
- [ ] Get task logs
* Secrets
- [ ] List secrets
- [ ] Create a secret
- [ ] Inspect a secret
- [ ] Delete a secret
- [ ] Update a secret
* Configs
- [ ] List configs
- [ ] Create a config
- [ ] Inspect a config
- [ ] Delete a config
- [ ] Update a config
* Plugins
- [ ] List plugins
- [ ] Get plugin privileges
- [ ] Install a plugin
- [ ] Inspect a plugin
- [ ] Remove a plugin
- [ ] Enable a plugin
- [ ] Disable a plugin
- [ ] Upgrade a plugin
- [ ] Create a plugin
- [ ] Push a plugin
- [ ] Configure a plugin
* System
- [ ] Check auth configuration
- [ ] Get system information
- [ ] Get version
- [ ] Ping
- [ ] Monitor events
- [ ] Get data usage information
* Distribution
- [ ] Get image information from the registry
* Session
- [ ] Initialize interactive session

View File

@ -39,7 +39,7 @@ pub fn (mut d DockerConn) close() ? {
} }
// send_request sends an HTTP request without body. // send_request sends an HTTP request without body.
pub fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? { fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? {
req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\n\n' req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\n\n'
d.socket.write_string(req)? d.socket.write_string(req)?
@ -49,7 +49,7 @@ pub fn (mut d DockerConn) send_request(method http.Method, url urllib.URL) ? {
} }
// send_request_with_body sends an HTTP request with the given body. // send_request_with_body sends an HTTP request with the given body.
pub fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib.URL, content_type string, body string) ? { fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib.URL, content_type string, body string) ? {
req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\nContent-Type: $content_type\nContent-Length: $body.len\n\n$body\n\n' req := '$method $url.request_uri() HTTP/1.1\nHost: localhost\nContent-Type: $content_type\nContent-Length: $body.len\n\n$body\n\n'
d.socket.write_string(req)? d.socket.write_string(req)?
@ -60,7 +60,7 @@ pub fn (mut d DockerConn) send_request_with_body(method http.Method, url urllib.
// send_request_with_json<T> is a convenience wrapper around // send_request_with_json<T> is a convenience wrapper around
// send_request_with_body that encodes the input as JSON. // send_request_with_body that encodes the input as JSON.
pub fn (mut d DockerConn) send_request_with_json<T>(method http.Method, url urllib.URL, data &T) ? { fn (mut d DockerConn) send_request_with_json<T>(method http.Method, url urllib.URL, data &T) ? {
body := json.encode(data) body := json.encode(data)
return d.send_request_with_body(method, url, 'application/json', body) return d.send_request_with_body(method, url, 'application/json', body)
@ -70,7 +70,7 @@ pub fn (mut d DockerConn) send_request_with_json<T>(method http.Method, url urll
// '\r\n\r\n', after which it parses the response as an HTTP response. // '\r\n\r\n', after which it parses the response as an HTTP response.
// Importantly, this function never consumes the reader past the HTTP // Importantly, this function never consumes the reader past the HTTP
// separator, so the body can be read fully later on. // separator, so the body can be read fully later on.
pub fn (mut d DockerConn) read_response_head() ?http.Response { fn (mut d DockerConn) read_response_head() ?http.Response {
mut res := []u8{} mut res := []u8{}
util.read_until_separator(mut d.reader, mut res, vdocker.http_separator)? util.read_until_separator(mut d.reader, mut res, vdocker.http_separator)?
@ -80,7 +80,7 @@ pub fn (mut d DockerConn) read_response_head() ?http.Response {
// read_response_body reads `length` bytes from the stream. It can be used when // read_response_body reads `length` bytes from the stream. It can be used when
// the response encoding isn't chunked to fully read it. // the response encoding isn't chunked to fully read it.
pub fn (mut d DockerConn) read_response_body(length int) ?string { fn (mut d DockerConn) read_response_body(length int) ?string {
if length == 0 { if length == 0 {
return '' return ''
} }
@ -101,7 +101,7 @@ pub fn (mut d DockerConn) read_response_body(length int) ?string {
// read_response is a convenience function which always consumes the entire // read_response is a convenience function which always consumes the entire
// response & returns it. It should only be used when we're certain that the // response & returns it. It should only be used when we're certain that the
// result isn't too large. // result isn't too large.
pub fn (mut d DockerConn) read_response() ?(http.Response, string) { fn (mut d DockerConn) read_response() ?(http.Response, string) {
head := d.read_response_head()? head := d.read_response_head()?
if head.header.get(http.CommonHeader.transfer_encoding) or { '' } == 'chunked' { if head.header.get(http.CommonHeader.transfer_encoding) or { '' } == 'chunked' {
@ -121,7 +121,7 @@ pub fn (mut d DockerConn) read_response() ?(http.Response, string) {
// get_chunked_response_reader returns a ChunkedResponseReader using the socket // get_chunked_response_reader returns a ChunkedResponseReader using the socket
// as reader. // as reader.
pub fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader { fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader {
r := new_chunked_response_reader(d.reader) r := new_chunked_response_reader(d.reader)
return r return r
@ -129,7 +129,7 @@ pub fn (mut d DockerConn) get_chunked_response_reader() &ChunkedResponseReader {
// get_stream_format_reader returns a StreamFormatReader using the socket as // get_stream_format_reader returns a StreamFormatReader using the socket as
// reader. // reader.
pub fn (mut d DockerConn) get_stream_format_reader() &StreamFormatReader { fn (mut d DockerConn) get_stream_format_reader() &StreamFormatReader {
r := new_chunked_response_reader(d.reader) r := new_chunked_response_reader(d.reader)
r2 := new_stream_format_reader(r) r2 := new_stream_format_reader(r)

33
volumes.v 100644
View File

@ -0,0 +1,33 @@
module vdocker
import net.http { Method }
import net.urllib
import json
import time
struct Volume {
name string [json: Name]
driver string [json: Driver]
mountpoint string [json: Mountpoint]
created_at time.Time [json: CreatedAt]
}
struct VolumeListResponse {
volumes []Volume [json: Volumes]
warnings []string [json: Warnings]
}
pub fn (mut d DockerConn) volume_list() ?VolumeListResponse {
d.send_request(Method.get, urllib.parse('/v1.41/volumes')?)?
head, body := d.read_response()?
if head.status_code != 200 {
data := json.decode(DockerError, body)?
return error(data.message)
}
data := json.decode(VolumeListResponse, body)?
return data
}