Commit Graph

439 Commits

Author SHA1 Message Date
1fb74bb17c Separate API router from server.
Implement basic interfaces to write custom routers that can be plugged
to the server. Remove server coupling with the daemon.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: da982cf5511814b6897244ecaa9c016f8800340a
Component: engine
2015-09-29 19:43:03 -04:00
a6a6684e96 Use golang.org/x/net/context in api/server/
This patch removes the internal context package and uses golang's
package instead.

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: 94e3b0f4288cdff767817b751e9a318e665ea7ac
Component: engine
2015-09-29 17:40:55 -04:00
69db6279aa Revert "Merge pull request #16228 from duglin/ContextualizeEvents"
Although having a request ID available throughout the codebase is very
valuable, the impact of requiring a Context as an argument to every
function in the codepath of an API request, is too significant and was
not properly understood at the time of the review.

Furthermore, mixing API-layer code with non-API-layer code makes the
latter usable only by API-layer code (one that has a notion of Context).

This reverts commit de4164043546d2b9ee3bf323dbc41f4979c84480, reversing
changes made to 7daeecd42d7bb112bfe01532c8c9a962bb0c7967.

Signed-off-by: Tibor Vass <tibor@docker.com>

Conflicts:
	api/server/container.go
	builder/internals.go
	daemon/container_unix.go
	daemon/create.go
Upstream-commit: b08f071e18043abe8ce15f56826d38dd26bedb78
Component: engine
2015-09-29 14:26:51 -04:00
fef14476a9 Revert "Merge pull request #16567 from calavera/context_per_request"
This reverts commit ff92f45be49146cd7ac7716c36d89de989cb262e, reversing
changes made to 80e31df3b6fdf6c1fbd6a5d0aceb0a148066508c.

Reverting to make the next revert easier.

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: 79c31f4b13d331d4011b2975a96dcdeab2036865
Component: engine
2015-09-29 13:40:46 -04:00
b31922f0fe Merge pull request #16567 from calavera/context_per_request
Define a context per request.
Upstream-commit: ff92f45be49146cd7ac7716c36d89de989cb262e
Component: engine
2015-09-25 13:01:51 -07:00
556d0a0826 refactor create to not expose internal data structures
- use existing exposed type

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
Upstream-commit: 93bd57b0b21e1a802b80388c8fc034780e3200fc
Component: engine
2015-09-25 09:35:18 -07:00
8cec2a263a Define a context per request.
Avoid creating a global context object that will be used while the daemon is running.

Not only this object won't ever be garbage collected, but it won't ever be used for anything else than creating other contexts in each request. I think it's a bad practive to have something like this sprawling aroud the code.

This change removes that global object and initializes a context in the cases we don't have already one, like shutting down the server.
This also removes a bunch of context arguments from functions that did nothing with it.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 27c76522dea91ec585f0b5f0ae1fec8c255b7b22
Component: engine
2015-09-24 18:44:53 -04:00
bf44c732da Add context.RequestID to event stream
This PR adds a "request ID" to each event generated, the 'docker events'
stream now looks like this:

```
2015-09-10T15:02:50.000000000-07:00 [reqid: c01e3534ddca] de7c5d4ca927253cf4e978ee9c4545161e406e9b5a14617efb52c658b249174a: (from ubuntu) create
```
Note the `[reqID: c01e3534ddca]` part, that's new.

Each HTTP request will generate its own unique ID. So, if you do a
`docker build` you'll see a series of events all with the same reqID.
This allow for log processing tools to determine which events are all related
to the same http request.

I didn't propigate the context to all possible funcs in the daemon,
I decided to just do the ones that needed it in order to get the reqID
into the events. I'd like to have people review this direction first, and
if we're ok with it then I'll make sure we're consistent about when
we pass around the context - IOW, make sure that all funcs at the same level
have a context passed in even if they don't call the log funcs - this will
ensure we're consistent w/o passing it around for all calls unnecessarily.

ping @icecrime @calavera @crosbymichael

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 26b1064967d9fcefd4c35f60e96bf6d7c9a3b5f8
Component: engine
2015-09-24 11:56:37 -07:00
8316b128fe Merge pull request #16411 from duglin/DaemonErrors
Move more 'daemon' errors to the new error package
Upstream-commit: ebe7ef9fc2238f008101f31c0c405cbc460ab757
Component: engine
2015-09-23 21:20:56 -04:00
1547f964d2 Merge pull request #16497 from MHBauer/attach-refactor-new
refactor attach to not use internal data structures
Upstream-commit: ddd0c47412dd30f1d333b5bd53e22c9949d1e86f
Component: engine
2015-09-23 16:52:39 -07:00
5ee0f81315 Move more 'daemon' errors to the new error package
Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 0a734182eb09497806a9ff3e1c8031ab1ab39f13
Component: engine
2015-09-23 09:51:45 -07:00
65ae094a39 refactor attach to not use internal data structures
- refactor to make it easier to split the api in the future

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
Upstream-commit: 8aef1a33eb730a7c9b7e92b688bc63e6a3c69f62
Component: engine
2015-09-23 08:55:21 -07:00
6f56efa779 Merge pull request #16331 from calavera/server_middlewares
Organize server pre-func logic in middlewares.
Upstream-commit: 9dc0973655bba2250b906bc8b316d87af809a15e
Component: engine
2015-09-22 16:10:42 -05:00
a91e1506bf Merge pull request #16419 from HuKeping/comments
Comment: add description for some code which hard to understand
Upstream-commit: f97e6f2a374b85c5ef14b19b805991d98a7f3d27
Component: engine
2015-09-21 20:44:54 -07:00
fc5d97018d Comment: add description for some code which hard to understand
Signed-off-by: Hu Keping <hukeping@huawei.com>
Upstream-commit: 3b443abec254cb8214881e11af4c09e923cd2dd1
Component: engine
2015-09-22 09:34:49 +08:00
651f1e747f Organize server pre-func logic in middlewares.
It defines global middlewares for every request.
This makes the server slightly more composable.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 0fea04d27ee91d7b57e0a77b110db1c861768c74
Component: engine
2015-09-21 14:27:06 -04:00
7020653250 api: server: container: fix wrong comment
This comment was wrongly referring to the old job mechanism and it
wasn't clear what it was trying to document.

Signed-off-by: Antonio Murdaca <runcom@linux.com>
Upstream-commit: 76b3b5431475709b27f0c113f9319321388a49d1
Component: engine
2015-09-21 00:46:16 +02:00
3904dd3167 Move api/errors/ to errors/
Per @calavera's suggestion: https://github.com/docker/docker/pull/16355#issuecomment-141139220

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: a283a30fb026aad4434a9f2e34f7ce955d27a957
Component: engine
2015-09-17 11:54:14 -07:00
2d5e18cda2 Merge pull request #16355 from duglin/DaemonErrors
Convert some "daemon" static error strings to the new errocode package format
Upstream-commit: 828e4ac45a5b4954997949570b9b032c57137849
Component: engine
2015-09-17 11:48:37 -07:00
d13159ba93 Merge pull request #16361 from MHBauer/stats-refactor
refactor stats to not use internal data structures
Upstream-commit: cafee2eb4544442cd1307c1484235261b5b2752a
Component: engine
2015-09-17 08:28:07 -07:00
b23ea59e6d refactor stats to not use internal data structures
- refactor to make it easier to split the api in the future
 - addition to check the existing test case and make sure it contains
   some expected output

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
Upstream-commit: 2d5d606fd368814ead4ff189eeae264f2af8691b
Component: engine
2015-09-16 17:28:52 -07:00
6295202aba Convert some "daemon" static error strings to the new errocode package format
Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: f7d4b4fe2b130a522dee847a657218806180fa52
Component: engine
2015-09-16 16:16:42 -07:00
5e58ae50d3 Merge pull request #15786 from HuKeping/stats-network
Refactor the statistics of network in docker stats
Upstream-commit: 259a0fb16ceac921763172127183059dea7e3c46
Component: engine
2015-09-16 20:29:16 +02:00
ded3de600a Support for passing build-time variables in build context
- The build-time variables are passed as environment-context for command(s)
run as part of the RUN primitve. These variables are not persisted in environment of
intermediate and final images when passed as context for RUN. The build environment
is prepended to the intermediate continer's command string for aiding cache lookups.
It also helps with build traceability. But this also makes the feature less secure from
point of view of passing build time secrets.

- The build-time variables also get used to expand the symbols used in certain
Dockerfile primitves like ADD, COPY, USER etc, without an explicit prior definiton using a
ENV primitive. These variables get persisted in the intermediate and final images
whenever they are expanded.

- The build-time variables are only expanded or passed to the RUN primtive if they
are defined in Dockerfile using the ARG primitive or belong to list of built-in variables.
HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy, FTP_PROXY and NO_PROXY are built-in
variables that needn't be explicitly defined in Dockerfile to use this feature.

Signed-off-by: Madhav Puri <madhav.puri@gmail.com>
Upstream-commit: 54240f8da9992880e20a1508e9a6f0e59f2adef1
Component: engine
2015-09-16 03:31:15 -07:00
700bfcfe4a Merge pull request #15069 from duglin/UseErrorPackage
Use the new error package
Upstream-commit: e91f2c26ce38787e159162d2c4a43744396e3308
Component: engine
2015-09-15 09:28:53 -04:00
c71aa53e3d Refactor the statistics of network in docker stats
For now docker stats will sum the rxbytes, txbytes, etc. of all
the interfaces.

It is OK for the output of CLI `docker stats` but not good for
the API response, especially when the container is in sereval
subnets.

It's better to leave these origianl data to user.

Signed-off-by: Hu Keping <hukeping@huawei.com>
Upstream-commit: d3379946ec96fb6163cb8c4517d7d5a067045801
Component: engine
2015-09-15 15:40:34 +08:00
bb8ff26c08 Use the new error package
This is the first step in converting out static strings into well-defined
error types.  This shows just a few examples of it to get a feel for how things
will look. Once we agree on the basic outline we can then work on converting
the rest of the code over.

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 628b9a41b09fde3ce1493f7d4f1495b9afaa506c
Component: engine
2015-09-14 13:11:01 -07:00
862065b3b2 Add log reading to the journald log driver
If a logdriver doesn't register a callback function to validate log
options, it won't be usable.  Fix the journald driver by adding a dummy
validator.

Teach the client and the daemon's "logs" logic that the server can also
supply "logs" data via the "journald" driver.  Update documentation and
tests that depend on error messages.

Add support for reading log data from the systemd journal to the
journald log driver.  The internal logic uses a goroutine to scan the
journal for matching entries after any specified cutoff time, formats
the messages from those entries as JSONLog messages, and stuffs the
results down a pipe whose reading end we hand back to the caller.

If we are missing any of the 'linux', 'cgo', or 'journald' build tags,
however, we don't implement a reader, so the 'logs' endpoint will still
return an error.

Make the necessary changes to the build setup to ensure that support for
reading container logs from the systemd journal is built.

Rename the Jmap member of the journald logdriver's struct to "vars" to
make it non-public, and to make it easier to tell that it's just there
to hold additional variable values that we want journald to record along
with log data that we're sending to it.

In the client, don't assume that we know which logdrivers the server
implements, and remove the check that looks at the server.  It's
redundant because the server already knows, and the check also makes
using older clients with newer servers (which may have new logdrivers in
them) unnecessarily hard.

When we try to "logs" and have to report that the container's logdriver
doesn't support reading, send the error message through the
might-be-a-multiplexer so that clients which are expecting multiplexed
data will be able to properly display the error, instead of tripping
over the data and printing a less helpful "Unrecognized input header"
error.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> (github: nalind)
Upstream-commit: e611a189cb3147cd79ccabfe8ba61ae3e3e28459
Component: engine
2015-09-11 16:50:03 -04:00
d563cc164c Signal to stop a container.
Allow to set the signal to stop a container in `docker run`:
- Use `--stop-signal` with docker-run to set the default signal the container will use to exit.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 0e50d946a25beb134bce2aaf4a209b5cfcbacf8f
Component: engine
2015-09-10 19:56:05 -04:00
9ec0a0380f Move context stuff to its own package
Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: f790496d8bd0930d7b1bc4adf120ae5ef169a958
Component: engine
2015-09-09 14:23:25 -07:00
8f5d65caff Add a "context" to the api/server/* code
This defines a 'context' object that is passed to each API handler.
Right now the context just has a unique 'requestID' for each API call.
The next steps would be:
- use this 'requestID' in our logging.
- determine the best way to format the logging to include this info.

In particular for log events that generate multiple entries in the log
we can use the requestID to help correlate the log entries.

Adding the requestID to the logging will be a challenge since it could mean
changing every single logrus.XXX() call to pass in the 'context' object.

But first step is to agree on a format, which we can discus in a subsequent
PR, but my initial thoughts are to add it right after the timestamp:

current format:
INFO[0039] POST /v1.21/build?buildargs=%7B%22foo%22%3A%22xxx%22%7D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=&ulimits=null

proposed format:
INFO[0039-83dea1222191] POST /v1.21/build?buildargs=%7B%22foo%22%3A%22xxx%22%7D&cgroupparent=&cpuperiod=0&cpuquota=0&cpusetcpus=&cpusetmems=&cpushares=0&dockerfile=Dockerfile&memory=0&memswap=0&rm=1&t=&ulimits=null

Signed-off-by: Doug Davis <dug@us.ibm.com>
Upstream-commit: 8b454dd79e6a11c3c881f8a755423713c0491287
Component: engine
2015-09-09 12:51:20 -07:00
154c412ece Merge pull request #15798 from calavera/volume_driver_host_config
Move VolumeDriver to HostConfig to make containers portable.
Upstream-commit: 9ca4aa479788867cd2dce161efa1e43ea5dfc14f
Component: engine
2015-09-08 22:05:40 -04:00
6d655f6a79 Merge pull request #16130 from aboch/vnd
Vendoring libnetwork 3e31cead05cba8ec20241630d051e6d73765b3a2
Upstream-commit: eb5c81e79980dd7fad211724adb27e42a3295a6c
Component: engine
2015-09-08 11:29:34 -07:00
51f6d2a64b Vendoring libnetwork 3e31cead05cba8ec20241630d051e6d73765b3a2
+ Fix a couple of bugs introduced by previous vendoring:
  - in bitseq which prevents to use experimental overlay networking
  - in docker service ls cli o/p
+ Add missing http subrouter for newly introduced sandboxes
+ Fix fragmentation issue on vxlan header addition for overlay network driver
+ Remove libnetwork test code utilities from vendoring

Signed-off-by: Alessandro Boch <aboch@docker.com>
Upstream-commit: 4d648f924af93b6429d566120a65cb441fee692a
Component: engine
2015-09-08 07:36:35 -07:00
4a380ba714 Don't lookup container 4 times for stats
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: dc8a39036b8c9da4c21c48f492cdbb795170bb21
Component: engine
2015-09-08 10:12:46 -04:00
d4738db561 Fix connection block when using docker stats API
For now CLI `docker stats` will not block even if the container was
not running is because there is a 2s timeout setting when waiting for
the response.

I think why we hang there waiting for the container to run is because we
want to get the stats of container immediately when it starts running.
But it will block when use the API directly, for example
- curl
- Google Chrome plugin, Postman
- Firefox plugin, RESTClient

This patch keeps the feature that getting info immediately when container
starts running and in the meantime, it will not block when using the API
directrly.

Signed-off-by: Hu Keping <hukeping@huawei.com>
Upstream-commit: d9bf8163ad8579cf2ab9f55925f9ea5037e5b525
Component: engine
2015-09-06 17:21:41 +08:00
350911ed1c Move VolumeDriver to HostConfig to make containers portable.
Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 6549d6517bf9a7c79d21a86cbf36af10fcdbfbe0
Component: engine
2015-09-04 12:42:44 -04:00
d8058c38dd Remove /containers/ps from the api router.
This route was deprecated more than two years ago in the linked
commit[1]. It's not referenced anywhere in the documentation and it's
time to stop maintaning it.

[1]: 4f9443927e

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: b5cc077864665290456c5ec724427c1f0d7bc96b
Component: engine
2015-09-01 05:17:35 -04:00
f6d5f51a76 [daemon] Refactor image_delete.go
This file was not well documented and had very high cyclomatic complexity.
This patch completely rearranges this file and the ImageDelete method to
be easier to follow and more maintainable in the future.

Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
Upstream-commit: 111d2f348767692a34366ff5cd01f607cf54ad57
Component: engine
2015-08-28 11:01:24 -07:00
1870e3919c golint fixes for daemon/ package
- some method names were changed to have a 'Locking' suffix, as the
 downcased versions already existed, and the existing functions simply
 had locks around the already downcased version.
 - deleting unused functions
 - package comment
 - magic numbers replaced by golang constants
 - comments all over

Signed-off-by: Morgan Bauer <mbauer@us.ibm.com>
Upstream-commit: abd72d4008dde7ee8249170d49eb4bc963c51e24
Component: engine
2015-08-27 22:07:42 -07:00
bfe1bbc7d2 Add volume API/CLI
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: b3b7eb2723461b1eb4be692f4bced0ae8ea9cb58
Component: engine
2015-08-26 13:37:52 -04:00
6dd2b74345 Merge pull request #15711 from monitorjbl/import-commit-message
adding message option to the import subcommand
Upstream-commit: b857dadb334fe0660abce4ae73a8b5b5c7f92c33
Component: engine
2015-08-26 11:42:10 +02:00
434547ed08 Merge pull request #14978 from gesellix/websocket-disable-check-origin
skip checkOrigin during websocket handshake
Upstream-commit: e134ccada7fae12271c4169e592b8bf09aff923d
Component: engine
2015-08-25 12:56:30 -04:00
b498641d47 Merge pull request #14665 from coolljt0725/fix_build_with_resource_limit
Fix build with resource limit which system not support.
Upstream-commit: 6f8c4480e4f99b08c84d25f1611d6b12ee646066
Component: engine
2015-08-25 16:42:13 +02:00
15378abfc2 adding message option to the import subcommand
Signed-off-by: Taylor Jones <monitorjbl@gmail.com>
Upstream-commit: 936b2c6afe490b562df4ebea854b116c3b40a9f5
Component: engine
2015-08-25 02:55:04 +00:00
e7fb39d7af Allow HEAD requests to container archives via CORS.
Add HEAD to Access-Control-Allow-Methods.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 354a2e105d26a310501891e6c097eacfd037d8c6
Component: engine
2015-08-24 05:57:22 -04:00
589fca3f48 fix a panic when the exec fails to start
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
Upstream-commit: fcf9daad91d9be24ceddbc4add4d3a8179c9b32c
Component: engine
2015-08-22 00:01:44 +08:00
6442b64e6e Fix build with resource limit which system is not support.
Signed-off-by: Lei Jitang <leijitang@huawei.com>
Upstream-commit: 770daa15f359ddc7329a2a031332c251e5a53a29
Component: engine
2015-08-18 11:54:00 +08:00
57a36297f7 Fix issue with exec TTY caused by 15446
The bool logic around setting up the TTY ended up getting flipped
accidentally.
Also added a test for exec with TTY.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Upstream-commit: 5ffcecf130aea8c0b92d1be728e2c302cf2c6c70
Component: engine
2015-08-14 14:55:26 -07:00
60f12fa9b0 Merge pull request #15446 from cpuguy83/better_err_on_exec_err
Return better errors from exec
Upstream-commit: d3198fa8c4f704a2ddd4d876003757b30a61c00c
Component: engine
2015-08-12 11:13:29 -07:00