Skip to content
This repository was archived by the owner on Jul 15, 2022. It is now read-only.

Commit f04901f

Browse files
author
Leonardo Chaia
committed
feat: clone containers
1 parent eebc027 commit f04901f

File tree

3 files changed

+50
-32
lines changed

3 files changed

+50
-32
lines changed

src/app/daemon-tools/container-action-buttons/container-action-buttons.component.html

+34-22
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
<tim-loading></tim-loading>
33
</ng-template>
44
<div *ngIf="!loading; else loadingTemplate"
5-
fxLayout="row">
5+
fxLayout="row"
6+
fxLayoutAlign="start center"
7+
fxLayoutGap="8px">
68

7-
<div fxFlex="grow"
8-
fxLayout="row"
9-
fxLayoutAlign="start center"
10-
fxLayoutGap="4px">
11-
12-
<ng-container *ngIf="containerState === 'running'; else notRunningTemplate">
9+
<ng-container *ngIf="containerState === 'running'; else notRunningTemplate">
10+
<div>
1311
<button type="button"
1412
*ngIf="isButtonVisible('attach')"
1513
(click)="attach()"
@@ -18,18 +16,20 @@
1816
<mat-icon>code</mat-icon>
1917
Attach
2018
</button>
21-
19+
</div>
20+
<div>
2221
<button type="button"
2322
*ngIf="isButtonVisible('exec')"
2423
(click)="exec()"
2524
mat-raised-button>
2625
<mat-icon>settings_ethernet</mat-icon>
2726
Exec
2827
</button>
28+
</div>
29+
</ng-container>
2930

30-
</ng-container>
31-
32-
<ng-template #notRunningTemplate>
31+
<ng-template #notRunningTemplate>
32+
<div>
3333
<button type="button"
3434
*ngIf="isButtonVisible('start')"
3535
(click)="start()"
@@ -38,26 +38,38 @@
3838
<mat-icon>play_arrow</mat-icon>
3939
Start
4040
</button>
41-
</ng-template>
42-
41+
</div>
42+
</ng-template>
43+
<div>
4344
<button type="button"
4445
*ngIf="isButtonVisible('logs')"
4546
(click)="logs()"
4647
mat-raised-button>
4748
<mat-icon>subject</mat-icon>
4849
Logs
4950
</button>
51+
</div>
5052

51-
<ng-container *ngIf="containerState === 'running'">
52-
<button type="button"
53-
*ngIf="isButtonVisible('stop')"
54-
(click)="stop()"
55-
mat-raised-button>
56-
<mat-icon>stop</mat-icon>
57-
Stop
58-
</button>
59-
</ng-container>
53+
<div *ngIf="containerState === 'running'">
54+
<button type="button"
55+
*ngIf="isButtonVisible('stop')"
56+
(click)="stop()"
57+
mat-raised-button>
58+
<mat-icon>stop</mat-icon>
59+
Stop
60+
</button>
61+
</div>
62+
63+
<div fxFlex="grow"></div>
6064

65+
<div>
66+
<button type="button"
67+
*ngIf="isButtonVisible('clone')"
68+
(click)="clone()"
69+
mat-raised-button>
70+
<mat-icon>add_to_photos</mat-icon>
71+
Clone
72+
</button>
6173
</div>
6274

6375
<div>

src/app/daemon-tools/container-action-buttons/container-action-buttons.component.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { Component, Input } from '@angular/core';
22
import { TabService } from '../../tabs/tab.service';
33
import { TimoneerTabs } from '../../timoneer-tabs';
44
import { Observable, throwError } from 'rxjs';
5-
import { catchError, map } from 'rxjs/operators';
5+
import { catchError, map, take } from 'rxjs/operators';
66
import { DockerContainerService } from '../docker-container.service';
77
import { NotificationService } from '../../shared/notification.service';
8+
import { ContainerCreateBody } from 'dockerode';
89

910
@Component({
1011
selector: 'tim-container-action-buttons',
@@ -75,11 +76,24 @@ export class ContainerActionButtonsComponent {
7576
});
7677
}
7778

79+
public clone() {
80+
this.bindLoading(this.containerService.inspect(this.containerId))
81+
.pipe(take(1))
82+
.subscribe((containerInfo) => {
83+
this.tabService.add(TimoneerTabs.DOCKER_CONTAINER_NEW, {
84+
params: {
85+
...containerInfo.Config,
86+
HostConfig: containerInfo.HostConfig
87+
} as ContainerCreateBody
88+
});
89+
});
90+
}
91+
7892
public isButtonVisible(key: string) {
7993
return !this.hiddenButtons || !this.hiddenButtons.includes(key);
8094
}
8195

82-
private bindLoading(obs: Observable<any>) {
96+
private bindLoading<T>(obs: Observable<T>) {
8397
this.loading = true;
8498
return obs.pipe(
8599
catchError((e) => {

src/app/daemon-tools/container-create-port-mapping/container-create-port-mapping.component.ts

-8
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,6 @@ export class ContainerCreatePortMappingComponent implements OnInit, OnChanges {
5656
const exposedPorts = Object.keys(this.image.Config.ExposedPorts || {})
5757
.map(k => parseInt(k.split('/')[0], 10));
5858

59-
// Remove bindings that are not in the new image
60-
for (const control of this.portBindingsArray.controls) {
61-
const value = control.value as PortBinding;
62-
if (!exposedPorts.includes(value.containerPort)) {
63-
this.containerForm.removePortBinding(this.portBindingsArray, control);
64-
}
65-
}
66-
6759
const out = this.suggestedPorts || [];
6860
this.availablePorts = out.concat(exposedPorts.filter(p => !out.some(o => o.containerPort === p))
6961
.map(p => ({ containerPort: p })));

0 commit comments

Comments
 (0)