Skip to content

Commit 61c1a37

Browse files
Upload dockerd configuration over HTTP
1 parent d87ffbd commit 61c1a37

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,21 @@ has a significantly higher inference time when using a small and slow SD card.
209209
To get more informed about specifications, check the
210210
[SD Card Standards](https://www.sdcard.org/developers/sd-standard-overview/).
211211

212+
## Additional configuration
213+
214+
For even more control over the dockerd daemon,
215+
a configuration file can be uploaded to the device using HTTP.
216+
217+
```sh
218+
curl --anyauth -u "root:$DEVICE_PASSWORD" -F [email protected] -X POST \
219+
http://$DEVICE_IP/local/dockerdwrapper/daemon.json
220+
```
221+
222+
The complete specification of this file can be found in the Docker reference, in section
223+
[Daemon configuration file](https://docs.docker.com/reference/cli/dockerd/#daemon-configuration-file).
224+
225+
The dockerd service will automatically restart after a new configuration file has been uploaded.
226+
212227
## Using the Docker ACAP
213228

214229
The Docker ACAP does not contain the docker client binary. This means that all

app/app_paths.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22

33
#define APP_DIRECTORY "/usr/local/packages/" APP_NAME
44
#define APP_LOCALDATA APP_DIRECTORY "/localdata"
5+
6+
#define DAEMON_JSON "daemon.json"

app/dockerdwrapper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ static bool start_dockerd(const struct settings* settings, struct app_state* app
487487
args_len - args_offset,
488488
"%s %s",
489489
"dockerd",
490-
"--config-file " APP_LOCALDATA "/daemon.json");
490+
"--config-file " APP_LOCALDATA "/" DAEMON_JSON);
491491

492492
g_strlcpy(msg, "Starting dockerd", msg_len);
493493

app/html/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ <h2>Remove TLS certificates and keys</h2>
1515
curl --anyauth -u $DEVICE_USER:$DEVICE_PASSWORD -X DELETE http://$DEVICE_IP/local/dockerdwrapper/server-cert.pem<br>
1616
curl --anyauth -u $DEVICE_USER:$DEVICE_PASSWORD -X DELETE http://$DEVICE_IP/local/dockerdwrapper/server-key.pem<br>
1717
</code>
18+
<h2>Check and upload dockerd configuration</h2>
19+
<code>
20+
curl --anyauth -u $DEVICE_USER:$DEVICE_PASSWORD http://$DEVICE_IP/local/dockerdwrapper/daemon.json<br>
21+
curl --anyauth -u $DEVICE_USER:$DEVICE_PASSWORD -F [email protected] -X POST http://$DEVICE_IP/local/dockerdwrapper/daemon.json.pem<br>
22+
</code>
1823
</body>
1924
</html>

app/http_request.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define HTTP_200_OK "200 OK"
99
#define HTTP_204_NO_CONTENT "204 No Content"
1010
#define HTTP_400_BAD_REQUEST "400 Bad Request"
11+
#define HTTP_403_FORBIDDEN "403 Forbidden"
1112
#define HTTP_404_NOT_FOUND "404 Not Found"
1213
#define HTTP_405_METHOD_NOT_ALLOWED "405 Method Not Allowed"
1314
#define HTTP_422_UNPROCESSABLE_CONTENT "422 Unprocessable Content"
@@ -93,6 +94,25 @@ static void post_request(FCGX_Request* request,
9394
log_error("Failed to remove %s: %s", temp_file, strerror(errno));
9495
}
9596

97+
static void get_request(FCGX_Request* request, const char* filename) {
98+
if (strcmp(filename, DAEMON_JSON) != 0) {
99+
response_msg(request, HTTP_403_FORBIDDEN, "Resource is write-only");
100+
return;
101+
}
102+
103+
g_autofree char* contents = NULL;
104+
gsize length;
105+
GError* error = NULL;
106+
const char* full_path = APP_LOCALDATA "/" DAEMON_JSON;
107+
if (!g_file_get_contents(full_path, &contents, &length, &error)) {
108+
log_error("Failed to read %s: %s.", full_path, error->message);
109+
response_msg(request, HTTP_404_NOT_FOUND, "Could not read file");
110+
return;
111+
}
112+
113+
response(request, HTTP_200_OK, "application/json", contents);
114+
}
115+
96116
static void delete_request(FCGX_Request* request, const char* filename) {
97117
if (!exists_in_localdata(filename))
98118
response_msg(request, HTTP_404_NOT_FOUND, "File not found in localdata");
@@ -130,6 +150,8 @@ void http_request_callback(void* request_void_ptr, void* restart_dockerd_context
130150

131151
if (strcmp(method, "POST") == 0)
132152
post_request(request, filename, restart_dockerd_context_void_ptr);
153+
else if (strcmp(method, "GET") == 0)
154+
get_request(request, filename);
133155
else if (strcmp(method, "DELETE") == 0)
134156
delete_request(request, filename);
135157
else

app/manifest.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
],
5959
"settingPage": "index.html",
6060
"httpConfig": [
61+
{
62+
"access": "admin",
63+
"name": "daemon.json",
64+
"type": "fastCgi"
65+
},
6166
{
6267
"access": "admin",
6368
"name": "ca.pem",

0 commit comments

Comments
 (0)