diff --git a/test/test.ts b/test/test.ts index 933b9b5..6f48ef2 100644 --- a/test/test.ts +++ b/test/test.ts @@ -61,6 +61,7 @@ tap.test('should return a change Observable', async tools => { tap.test('should create a secret', async () => { const mySecret = await docker.DockerSecret.createSecret(testDockerHost, { name: 'testSecret', + version: '1.0.3', contentArg: `{ "hi": "wow"}`, labels: {} }); @@ -89,15 +90,16 @@ tap.test('should create a service', async () => { }); const testSecret = await docker.DockerSecret.createSecret(testDockerHost, { name: 'serviceSecret', + version: '0.0.1', labels: {}, contentArg: '{"hi": "wow"}' }); const testService = await DockerService.createService(testDockerHost, { - Image: 'nginx:latest', - Labels: { + image: 'nginx:latest', + labels: { 'testlabel': 'hi' }, - Name: 'testService', + name: 'testService', networks: [testNetwork], networkAlias: 'testService', secrets: [testSecret] diff --git a/ts/docker.classes.image.ts b/ts/docker.classes.image.ts index 88fbbf5..55b3570 100644 --- a/ts/docker.classes.image.ts +++ b/ts/docker.classes.image.ts @@ -15,9 +15,15 @@ export class DockerImage { public static async findImageByName(dockerHost: DockerHost, imageNameArg: string) { const images = await this.getImages(dockerHost); - return images.find(image => { - return image.RepoTags.includes(imageNameArg); + const result = images.find(image => { + if (image.RepoTags) { + return image.RepoTags.includes(imageNameArg); + } else { + return false; + } + }); + return result; } public static async createFromRegistry( diff --git a/ts/docker.classes.secret.ts b/ts/docker.classes.secret.ts index 7bb3e90..8f553d5 100644 --- a/ts/docker.classes.secret.ts +++ b/ts/docker.classes.secret.ts @@ -28,9 +28,13 @@ export class DockerSecret { } public static async createSecret(dockerHostArg: DockerHost, secretDescriptor: interfaces.ISecretCreationDescriptor) { + const labels: interfaces.TLabels = { + ...secretDescriptor.labels, + version: secretDescriptor.version + }; const response = await dockerHostArg.request('POST', '/secrets/create', { Name: secretDescriptor.name, - Labels: secretDescriptor.labels, + Labels: labels, Data: plugins.smartstring.base64.encode(secretDescriptor.contentArg) }); @@ -46,9 +50,9 @@ export class DockerSecret { Name: string; Labels: interfaces.TLabels; }; - Version: { + public Version: { Index:string; - } + }; public dockerHost: DockerHost; constructor(dockerHostArg: DockerHost) { @@ -70,4 +74,10 @@ export class DockerSecret { public async remove () { await this.dockerHost.request('DELETE', `/secrets/${this.ID}`); } + + + // get things + public getVersion() { + return this.Spec.Labels.version; + } } \ No newline at end of file diff --git a/ts/docker.classes.service.ts b/ts/docker.classes.service.ts index 07787c7..cb91778 100644 --- a/ts/docker.classes.service.ts +++ b/ts/docker.classes.service.ts @@ -39,14 +39,18 @@ export class DockerService { // lets get the image plugins.smartlog.defaultLogger.log( 'info', - `downloading image for service ${serviceCreationDescriptor.Name}` + `downloading image for service ${serviceCreationDescriptor.name}` ); const serviceImage = await DockerImage.createFromRegistry(dockerHost, { - imageUrl: serviceCreationDescriptor.Image + imageUrl: serviceCreationDescriptor.image }); const serviceVersion = serviceImage.Labels.version; - serviceCreationDescriptor.Labels.version = serviceVersion; + + const labels: interfaces.TLabels = { + ...serviceCreationDescriptor.labels, + version: serviceVersion + }; const networkArray: any[] = []; for (const network of serviceCreationDescriptor.networks) { @@ -71,11 +75,11 @@ export class DockerService { } const response = await dockerHost.request('POST', '/services/create', { - Name: serviceCreationDescriptor.Name, + Name: serviceCreationDescriptor.name, TaskTemplate: { ContainerSpec: { - Image: serviceCreationDescriptor.Image, - Labels: serviceCreationDescriptor.Labels, + Image: serviceCreationDescriptor.image, + Labels: labels, Secrets: secretArray }, UpdateConfig: { @@ -87,13 +91,13 @@ export class DockerService { }, ForceUpdate: 1 }, - Labels: serviceCreationDescriptor.Labels, + Labels: serviceCreationDescriptor.labels, Networks: networkArray }); const createdService = await DockerService.getServiceByName( dockerHost, - serviceCreationDescriptor.Name + serviceCreationDescriptor.name ); return createdService; } diff --git a/ts/interfaces/secret.ts b/ts/interfaces/secret.ts index d191f53..246b967 100644 --- a/ts/interfaces/secret.ts +++ b/ts/interfaces/secret.ts @@ -2,6 +2,7 @@ import * as interfaces from './'; export interface ISecretCreationDescriptor { name: string; + version: string; contentArg: any; labels: interfaces.TLabels; } \ No newline at end of file diff --git a/ts/interfaces/service.ts b/ts/interfaces/service.ts index 779fcdc..66d488d 100644 --- a/ts/interfaces/service.ts +++ b/ts/interfaces/service.ts @@ -3,9 +3,9 @@ import { DockerNetwork } from '../docker.classes.network'; import { DockerSecret } from '../docker.classes.secret'; export interface IServiceCreationDescriptor { - Name: string; - Image: string; - Labels: interfaces.TLabels; + name: string; + image: string; + labels: interfaces.TLabels; networks: DockerNetwork[]; networkAlias: string; secrets: DockerSecret[];