-
Notifications
You must be signed in to change notification settings - Fork 522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new Docker SDK-based client #2134
Merged
Merged
Changes from 22 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
5e279f0
Implement client for Docker SDK
bwateratmsft 1ebbce1
Fix compile error
bwateratmsft e6dd34f
Add another stopped container state
bwateratmsft b7c40e5
Return to using official repo
bwateratmsft 5d72bc4
Assume linux if we can't tell what OS
bwateratmsft 485671f
Merge branch 'master' into bmw/dockerserve
bwateratmsft c56580f
Output lots of relevant task information
bwateratmsft be9f887
Single quotes
bwateratmsft b35dd79
Merge branch 'master' into bmw/dockerserve
bwateratmsft 7de3556
Single quotes
bwateratmsft 18d618c
Comment changes
bwateratmsft 4c40815
Refactoring
bwateratmsft 6d0f0f7
Install docker SDK from public source
bwateratmsft 48c3226
Fix build break
bwateratmsft 7a06217
Disable stop
bwateratmsft f740140
Merge branch 'master' into bmw/dockerserve
bwateratmsft 33bd90f
Karol's feedback
bwateratmsft 2c5569d
Merge branch 'master' into bmw/dockerserve
bwateratmsft 84b79df
List all containers
bwateratmsft e726d86
Monkey patch in a label for compose proj
bwateratmsft 13e0525
Merge commit 'c56580faaf' into bmw/dockerserve
bwateratmsft a4021ec
Remove mistaken change
bwateratmsft 69a49a1
Remove another mistaken change
bwateratmsft 14dd3b6
Use the prettier syntax
bwateratmsft 0b8e74c
Add getCurrentContext method
bwateratmsft 083c324
Merge branch 'master' into bmw/dockerserve
bwateratmsft f983398
Merge branch 'master' into bmw/dockerserve
bwateratmsft 277031c
Note a todo item so that we can submit
bwateratmsft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { Container } from '@docker/sdk/containers'; | ||
import { DockerContainer, InspectionPort } from '../Containers'; | ||
|
||
// Group 1 is container group name; group 2 is container name | ||
const containerGroupAndName = /(?:([a-z0-9\-]+)_)?([a-z0-9\-]+)/i; | ||
|
||
export function containerToDockerContainer(container: Container.AsObject): DockerContainer | undefined { | ||
if (!container) { | ||
return undefined; | ||
} | ||
|
||
const ports = container.portsList.map(p => { | ||
return { | ||
IP: p.hostIp, | ||
PublicPort: p.hostPort, | ||
PrivatePort: p.containerPort, | ||
Type: p.protocol, | ||
}; | ||
}); | ||
|
||
const labels: { [key: string]: string } = {}; | ||
container.labelsList.forEach(l => { | ||
const [label, value] = l.split(/=|:/i); | ||
labels[label] = value; | ||
}); | ||
|
||
// If the containers are in a group and there's no com.docker.compose.project label, | ||
// use the group name as that label so that grouping in the UI works | ||
let match: string; | ||
if (labels['com.docker.compose.project'] === undefined && | ||
(match = containerGroupAndName.exec(container.id)?.[1])) { // Assignment and check is intentional | ||
labels['com.docker.compose.project'] = match; | ||
} | ||
|
||
return { | ||
Id: container.id, | ||
Image: container.image, | ||
Name: container.id, // TODO ? | ||
State: container.status, | ||
Status: container.status, | ||
ImageID: undefined, // TODO ? | ||
CreatedTime: undefined, // TODO ? | ||
Labels: labels, // TODO--not yet supported on ACI | ||
Ports: ports, | ||
}; | ||
} | ||
|
||
export function containerPortsToInspectionPorts(container: DockerContainer): { [portAndProtocol: string]: InspectionPort[] } | undefined { | ||
if (container?.Ports === undefined) { | ||
return undefined; | ||
} | ||
|
||
const result: { [portAndProtocol: string]: InspectionPort[] } = {}; | ||
|
||
for (const port of container.Ports) { | ||
// Get the key | ||
const key = `${port.PrivatePort}/${port.Type}`; | ||
|
||
// If there's no entries for this key yet, create an empty list | ||
if (result[key] === undefined) { | ||
result[key] = []; | ||
} | ||
|
||
// Add the value to the list | ||
result[key].push({ | ||
HostIp: port.IP, | ||
HostPort: port.PublicPort.toString(), | ||
}); | ||
} | ||
|
||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get OS type from container instead of system? That would allow for Windows containers in ACI to work.
*Need the SDK to provide platform