Skip to content

Commit f1e67fa

Browse files
committed
chore: add ContainerIDFile options
Signed-off-by: Arjun Raja Yogidas <[email protected]>
1 parent 12fa203 commit f1e67fa

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

api/handlers/container/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ func (h *handler) create(w http.ResponseWriter, r *http.Request) {
155155
StopSignal: stopSignal,
156156
StopTimeout: stopTimeout,
157157
OomKillDisable: req.HostConfig.OomKillDisable,
158+
CidFile: req.HostConfig.ContainerIDFile, // CidFile write the container ID to the file
158159
// #endregion
159160

160161
// #region for platform flags

api/handlers/container/create_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,27 @@ var _ = Describe("Container Create API ", func() {
541541
Expect(rr.Body).Should(MatchJSON(jsonResponse))
542542
})
543543

544+
It("should set ContainerIdFile option", func() {
545+
body := []byte(`{
546+
"Image": "test-image",
547+
"HostConfig": {
548+
"ContainerIDFile": "/lib/example.txt"
549+
}
550+
}`)
551+
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))
552+
553+
// expected create options
554+
createOpt.CidFile = "/lib/example.txt"
555+
556+
service.EXPECT().Create(gomock.Any(), "test-image", nil, equalTo(createOpt), equalTo(netOpt)).Return(
557+
cid, nil)
558+
559+
// handler should return success message with 201 status code.
560+
h.create(rr, req)
561+
Expect(rr).Should(HaveHTTPStatus(http.StatusCreated))
562+
Expect(rr.Body).Should(MatchJSON(jsonResponse))
563+
})
564+
544565
It("should return 404 if the image was not found", func() {
545566
body := []byte(`{"Image": "test-image"}`)
546567
req, _ := http.NewRequest(http.MethodPost, "/containers/create", bytes.NewReader(body))

api/types/container_types.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ type ContainerConfig struct {
5757
// HostConfig is from https://github.com/moby/moby/blob/v24.0.2/api/types/container/hostconfig.go#L376-L436
5858
type ContainerHostConfig struct {
5959
// Applicable to all platforms
60-
Binds []string // List of volume bindings for this container
61-
// TODO: ContainerIDFile string // File (path) where the containerId is written
62-
LogConfig LogConfig // Configuration of the logs for this container
63-
NetworkMode string // Network mode to use for the container
64-
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
65-
RestartPolicy RestartPolicy // Restart policy to be used for the container
66-
AutoRemove bool // Automatically remove container when it exits
60+
Binds []string // List of volume bindings for this container
61+
ContainerIDFile string // File (path) where the containerId is written
62+
LogConfig LogConfig // Configuration of the logs for this container
63+
NetworkMode string // Network mode to use for the container
64+
PortBindings nat.PortMap // Port mapping between the exposed port (container) and the host
65+
RestartPolicy RestartPolicy // Restart policy to be used for the container
66+
AutoRemove bool // Automatically remove container when it exits
6767
// TODO: VolumeDriver string // Name of the volume driver used to mount volumes
6868
// TODO: VolumesFrom []string // List of volumes to take from other container
6969
// TODO: ConsoleSize [2]uint // Initial console size (height,width)

0 commit comments

Comments
 (0)