Reuse docker compose file version.
Ensures that the version of the input docker-compose file is used when producing generated ones (those with qualified image names as well those with the image digests).
This commit is contained in:
Родитель
496f32b8b9
Коммит
6c2043d76b
|
@ -11,6 +11,7 @@ import DockerConnection from "./dockerConnection";
|
|||
export default class DockerComposeConnection extends DockerConnection {
|
||||
private dockerComposePath: string;
|
||||
private dockerComposeFile: string;
|
||||
private dockerComposeVersion: string;
|
||||
private additionalDockerComposeFiles: string[];
|
||||
private requireAdditionalDockerComposeFiles: boolean;
|
||||
private projectName: string;
|
||||
|
@ -23,6 +24,7 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
if (!this.dockerComposeFile) {
|
||||
throw new Error("No Docker Compose file matching " + tl.getInput("dockerComposeFile") + " was found.");
|
||||
}
|
||||
this.dockerComposeVersion = "2";
|
||||
this.additionalDockerComposeFiles = tl.getDelimitedInput("additionalDockerComposeFiles", "\n");
|
||||
this.requireAdditionalDockerComposeFiles = tl.getBoolInput("requireAdditionalDockerComposeFiles");
|
||||
this.projectName = tl.getInput("projectName");
|
||||
|
@ -64,7 +66,7 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
};
|
||||
}
|
||||
fs.writeFileSync(this.finalComposeFile, yaml.safeDump({
|
||||
version: "2",
|
||||
version: this.dockerComposeVersion,
|
||||
services: services
|
||||
}, { lineWidth: -1 } as any));
|
||||
});
|
||||
|
@ -115,6 +117,9 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
public getImages(builtOnly?: boolean): any {
|
||||
return this.getCombinedConfig().then(input => {
|
||||
var doc = yaml.safeLoad(input);
|
||||
if (doc.version) {
|
||||
this.dockerComposeVersion = doc.version;
|
||||
}
|
||||
var projectName = this.projectName;
|
||||
if (!projectName) {
|
||||
projectName = path.basename(path.dirname(this.dockerComposeFile));
|
||||
|
@ -134,6 +139,10 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
});
|
||||
}
|
||||
|
||||
public getVersion(): string {
|
||||
return this.dockerComposeVersion;
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
if (this.finalComposeFile && tl.exist(this.finalComposeFile)) {
|
||||
del.sync(this.finalComposeFile, { force: true });
|
||||
|
|
|
@ -26,7 +26,7 @@ function dockerPull(connection: DockerComposeConnection, imageName: string, imag
|
|||
});
|
||||
}
|
||||
|
||||
function writeImageDigestComposeFile(imageDigests: any, imageDigestComposeFile: string): void {
|
||||
function writeImageDigestComposeFile(version: string, imageDigests: any, imageDigestComposeFile: string): void {
|
||||
var services = {};
|
||||
Object.keys(imageDigests).forEach(serviceName => {
|
||||
services[serviceName] = {
|
||||
|
@ -34,7 +34,7 @@ function writeImageDigestComposeFile(imageDigests: any, imageDigestComposeFile:
|
|||
};
|
||||
});
|
||||
fs.writeFileSync(imageDigestComposeFile, yaml.safeDump({
|
||||
version: "2",
|
||||
version: version,
|
||||
services: services
|
||||
}, { lineWidth: -1 } as any));
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ function writeImageDigestComposeFile(imageDigests: any, imageDigestComposeFile:
|
|||
export function createImageDigestComposeFile(connection: DockerComposeConnection, imageDigestComposeFile: string) {
|
||||
return connection.getImages().then(images => {
|
||||
var promise: any;
|
||||
var version = connection.getVersion();
|
||||
var imageDigests = {};
|
||||
Object.keys(images).forEach(serviceName => {
|
||||
(imageName => {
|
||||
|
@ -53,9 +54,9 @@ export function createImageDigestComposeFile(connection: DockerComposeConnection
|
|||
})(images[serviceName]);
|
||||
});
|
||||
if (!promise) {
|
||||
writeImageDigestComposeFile(imageDigests, imageDigestComposeFile);
|
||||
writeImageDigestComposeFile(version, imageDigests, imageDigestComposeFile);
|
||||
} else {
|
||||
return promise.then(() => writeImageDigestComposeFile(imageDigests, imageDigestComposeFile));
|
||||
return promise.then(() => writeImageDigestComposeFile(version, imageDigests, imageDigestComposeFile));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"version": {
|
||||
"Major": 0,
|
||||
"Minor": 3,
|
||||
"Patch": 3
|
||||
"Patch": 4
|
||||
},
|
||||
"demands": [],
|
||||
"groups": [
|
||||
|
|
|
@ -11,6 +11,7 @@ import DockerConnection from "./dockerConnection";
|
|||
export default class DockerComposeConnection extends DockerConnection {
|
||||
private dockerComposePath: string;
|
||||
private dockerComposeFile: string;
|
||||
private dockerComposeVersion: string;
|
||||
private additionalDockerComposeFiles: string[];
|
||||
private requireAdditionalDockerComposeFiles: boolean;
|
||||
private projectName: string;
|
||||
|
@ -23,6 +24,7 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
if (!this.dockerComposeFile) {
|
||||
throw new Error("No Docker Compose file matching " + tl.getInput("dockerComposeFile") + " was found.");
|
||||
}
|
||||
this.dockerComposeVersion = "2";
|
||||
this.additionalDockerComposeFiles = tl.getDelimitedInput("additionalDockerComposeFiles", "\n");
|
||||
this.requireAdditionalDockerComposeFiles = tl.getBoolInput("requireAdditionalDockerComposeFiles");
|
||||
this.projectName = tl.getInput("projectName");
|
||||
|
@ -64,7 +66,7 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
};
|
||||
}
|
||||
fs.writeFileSync(this.finalComposeFile, yaml.safeDump({
|
||||
version: "2",
|
||||
version: this.dockerComposeVersion,
|
||||
services: services
|
||||
}, { lineWidth: -1 } as any));
|
||||
});
|
||||
|
@ -115,6 +117,9 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
public getImages(builtOnly?: boolean): any {
|
||||
return this.getCombinedConfig().then(input => {
|
||||
var doc = yaml.safeLoad(input);
|
||||
if (doc.version) {
|
||||
this.dockerComposeVersion = doc.version;
|
||||
}
|
||||
var projectName = this.projectName;
|
||||
if (!projectName) {
|
||||
projectName = path.basename(path.dirname(this.dockerComposeFile));
|
||||
|
@ -134,6 +139,10 @@ export default class DockerComposeConnection extends DockerConnection {
|
|||
});
|
||||
}
|
||||
|
||||
public getVersion(): string {
|
||||
return this.dockerComposeVersion;
|
||||
}
|
||||
|
||||
public close(): void {
|
||||
if (this.finalComposeFile && tl.exist(this.finalComposeFile)) {
|
||||
del.sync(this.finalComposeFile, { force: true });
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"version": {
|
||||
"Major": 0,
|
||||
"Minor": 1,
|
||||
"Patch": 5
|
||||
"Patch": 6
|
||||
},
|
||||
"demands": [],
|
||||
"groups": [
|
||||
|
|
Загрузка…
Ссылка в новой задаче