mirror of https://github.com/docker/compose.git
Send the `tail` parameter to ACI if present
This commit is contained in:
parent
169e3a9b1f
commit
6a5973597d
|
@ -221,13 +221,13 @@ func exec(ctx context.Context, address string, password string, reader io.Reader
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getACIContainerLogs(ctx context.Context, aciContext store.AciContext, containerGroupName, containerName string) (string, error) {
|
func getACIContainerLogs(ctx context.Context, aciContext store.AciContext, containerGroupName, containerName string, tail *int32) (string, error) {
|
||||||
containerClient, err := getContainerClient(aciContext.SubscriptionID)
|
containerClient, err := getContainerClient(aciContext.SubscriptionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", errors.Wrapf(err, "cannot get container client")
|
return "", errors.Wrapf(err, "cannot get container client")
|
||||||
}
|
}
|
||||||
|
|
||||||
logs, err := containerClient.ListLogs(ctx, aciContext.ResourceGroup, containerGroupName, containerName, nil)
|
logs, err := containerClient.ListLogs(ctx, aciContext.ResourceGroup, containerGroupName, containerName, tail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("cannot get container logs: %v", err)
|
return "", fmt.Errorf("cannot get container logs: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,21 +236,20 @@ func (cs *aciContainerService) Exec(ctx context.Context, name string, command st
|
||||||
|
|
||||||
func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
|
func (cs *aciContainerService) Logs(ctx context.Context, containerName string, req containers.LogsRequest) error {
|
||||||
groupName, containerAciName := getGroupAndContainerName(containerName)
|
groupName, containerAciName := getGroupAndContainerName(containerName)
|
||||||
logs, err := getACIContainerLogs(ctx, cs.ctx, groupName, containerAciName)
|
var tail *int32
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if req.Tail != "all" {
|
if req.Tail != "all" {
|
||||||
tail, err := strconv.Atoi(req.Tail)
|
reqTail, err := strconv.Atoi(req.Tail)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lines := strings.Split(logs, "\n")
|
i32 := int32(reqTail)
|
||||||
|
tail = &i32
|
||||||
|
}
|
||||||
|
|
||||||
// If asked for less lines than exist, take only those lines
|
logs, err := getACIContainerLogs(ctx, cs.ctx, groupName, containerAciName, tail)
|
||||||
if tail <= len(lines) {
|
if err != nil {
|
||||||
logs = strings.Join(lines[len(lines)-tail:], "\n")
|
return err
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = fmt.Fprint(req.Writer, logs)
|
_, err = fmt.Fprint(req.Writer, logs)
|
||||||
|
|
Loading…
Reference in New Issue