Skip to content

Commit fb8e0cc

Browse files
committed
fix(images): keep image configurations if build fails (closes #316)
1 parent e8b7d51 commit fb8e0cc

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/api/image-builder.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ export function buildDockerImage(data: ImageData): void {
4343
docker.buildImage({ context: folderPath, src: src }, { t: data.name })
4444
.then(output => {
4545
output.on('data', d => {
46-
imageBuilder.next({ name: data.name, output: d.toString() });
46+
const output = d.toString();
47+
const parsed = JSON.parse(output);
48+
49+
if (parsed && parsed.errorDetail) {
50+
const error = parsed.errorDetail.error ? `(${parsed.errorDetail.error})` : '';
51+
imageBuilder.next({
52+
name: data.name,
53+
output: `error while building image ${data.name} ${error}`
54+
});
55+
} else {
56+
imageBuilder.next({ name: data.name, output: output });
57+
}
4758
});
4859
output.on('finish', () => {
4960
msg = {
@@ -59,6 +70,7 @@ export function buildDockerImage(data: ImageData): void {
5970
type: 'error',
6071
notify: true
6172
};
73+
imageBuilder.next({ name: data.name, output: msg.message });
6274
logger.next(msg);
6375
});
6476
output.on('end', () => {
@@ -77,6 +89,7 @@ export function buildDockerImage(data: ImageData): void {
7789
notify: true
7890
};
7991
logger.next(msg);
92+
imageBuilder.next({ name: data.name, output: msg.message });
8093
});
8194
});
8295
}

src/app/components/app-images/app-images.component.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@ <h1>Warning:</h1>
159159
</div>
160160
</div>
161161
</div>
162+
<div class="columns is-multiline error-item" *ngIf="buildingError">
163+
<div class="column is-12">
164+
Error (check your build configurations):
165+
</div>
166+
<div class="column is-12">
167+
{{buildingError}}
168+
</div>
169+
</div>
162170
<h2>Image name</h2>
163171
<input type="text" class="image-name-input" [(ngModel)]="form.name" placeholder="Image Name">
164172
<div class="columns is-multiline" *ngIf="baseImages?.length && !editingImage">

src/app/components/app-images/app-images.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
3939
tab: string;
4040
sub: Subscription;
4141
approve: boolean;
42+
buildingError: string;
4243
terminalOptions: { size: 'small' | 'large', newline: boolean };
4344
terminalInput: any;
4445
baseImageOptions: { key: any, value: string }[];
@@ -53,6 +54,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
5354
) {
5455
this.baseImages = [];
5556
this.baseImage = '';
57+
this.buildingError = '';
5658
this.customImages = [];
5759
this.baseImageOptions = [];
5860
this.dangerousCommands = [];
@@ -135,7 +137,10 @@ export class AppImagesComponent implements OnInit, OnDestroy {
135137
this.zone.run(() => this.terminalInput = output.stream);
136138
}
137139
} else if (output && output.errorDetail) {
138-
this.zone.run(() => this.terminalInput = `<span style="color:rgb(255,85,85);">${output.errorDetail.message}</span>`);
140+
this.zone.run(() => this.terminalInput = output.errorDetail.message);
141+
} else if (event.data.output && event.data.output.startsWith('error while building image')) {
142+
this.building = false;
143+
this.buildingError = event.data.output;
139144
}
140145
});
141146

@@ -144,6 +149,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
144149
}
145150

146151
resetForm(imageType: boolean): void {
152+
this.buildingError = '';
147153
this.editingImage = false;
148154

149155
if (imageType) {
@@ -257,6 +263,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
257263
this.form.initsh = this.customImages[index].initsh;
258264
}
259265
this.form.base = base;
266+
this.buildingError = '';
260267
}
261268

262269
fetchImages(): void {
@@ -325,6 +332,7 @@ export class AppImagesComponent implements OnInit, OnDestroy {
325332
}
326333

327334
buildImage(): void {
335+
this.buildingError = '';
328336
if (this.checkImage()) {
329337
this.approve = true;
330338
window.scrollTo(0, 0);

src/app/styles/images.sass

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,14 @@
162162
align-items: center
163163
justify-content: center
164164
text-align: center
165+
166+
.error-item
167+
margin: 10px 0px
168+
font-size: 14px
169+
border: 1px solid $red
170+
background: rgba($red-secondary, 0.4)
171+
font-weight: $weight-semibold
172+
color: darken($red, 10)
173+
align-items: center
174+
justify-content: center
175+
text-align: center

0 commit comments

Comments
 (0)