fix(core): update
This commit is contained in:
parent
546e139b46
commit
9767b8767a
@ -61,6 +61,7 @@ tap.test('should return a change Observable', async tools => {
|
|||||||
tap.test('should create a secret', async () => {
|
tap.test('should create a secret', async () => {
|
||||||
const mySecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
const mySecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||||
name: 'testSecret',
|
name: 'testSecret',
|
||||||
|
version: '1.0.3',
|
||||||
contentArg: `{ "hi": "wow"}`,
|
contentArg: `{ "hi": "wow"}`,
|
||||||
labels: {}
|
labels: {}
|
||||||
});
|
});
|
||||||
@ -89,15 +90,16 @@ tap.test('should create a service', async () => {
|
|||||||
});
|
});
|
||||||
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
const testSecret = await docker.DockerSecret.createSecret(testDockerHost, {
|
||||||
name: 'serviceSecret',
|
name: 'serviceSecret',
|
||||||
|
version: '0.0.1',
|
||||||
labels: {},
|
labels: {},
|
||||||
contentArg: '{"hi": "wow"}'
|
contentArg: '{"hi": "wow"}'
|
||||||
});
|
});
|
||||||
const testService = await DockerService.createService(testDockerHost, {
|
const testService = await DockerService.createService(testDockerHost, {
|
||||||
Image: 'nginx:latest',
|
image: 'nginx:latest',
|
||||||
Labels: {
|
labels: {
|
||||||
'testlabel': 'hi'
|
'testlabel': 'hi'
|
||||||
},
|
},
|
||||||
Name: 'testService',
|
name: 'testService',
|
||||||
networks: [testNetwork],
|
networks: [testNetwork],
|
||||||
networkAlias: 'testService',
|
networkAlias: 'testService',
|
||||||
secrets: [testSecret]
|
secrets: [testSecret]
|
||||||
|
@ -15,9 +15,15 @@ export class DockerImage {
|
|||||||
|
|
||||||
public static async findImageByName(dockerHost: DockerHost, imageNameArg: string) {
|
public static async findImageByName(dockerHost: DockerHost, imageNameArg: string) {
|
||||||
const images = await this.getImages(dockerHost);
|
const images = await this.getImages(dockerHost);
|
||||||
return images.find(image => {
|
const result = images.find(image => {
|
||||||
|
if (image.RepoTags) {
|
||||||
return image.RepoTags.includes(imageNameArg);
|
return image.RepoTags.includes(imageNameArg);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async createFromRegistry(
|
public static async createFromRegistry(
|
||||||
|
@ -28,9 +28,13 @@ export class DockerSecret {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async createSecret(dockerHostArg: DockerHost, secretDescriptor: interfaces.ISecretCreationDescriptor) {
|
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', {
|
const response = await dockerHostArg.request('POST', '/secrets/create', {
|
||||||
Name: secretDescriptor.name,
|
Name: secretDescriptor.name,
|
||||||
Labels: secretDescriptor.labels,
|
Labels: labels,
|
||||||
Data: plugins.smartstring.base64.encode(secretDescriptor.contentArg)
|
Data: plugins.smartstring.base64.encode(secretDescriptor.contentArg)
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -46,9 +50,9 @@ export class DockerSecret {
|
|||||||
Name: string;
|
Name: string;
|
||||||
Labels: interfaces.TLabels;
|
Labels: interfaces.TLabels;
|
||||||
};
|
};
|
||||||
Version: {
|
public Version: {
|
||||||
Index:string;
|
Index:string;
|
||||||
}
|
};
|
||||||
|
|
||||||
public dockerHost: DockerHost;
|
public dockerHost: DockerHost;
|
||||||
constructor(dockerHostArg: DockerHost) {
|
constructor(dockerHostArg: DockerHost) {
|
||||||
@ -70,4 +74,10 @@ export class DockerSecret {
|
|||||||
public async remove () {
|
public async remove () {
|
||||||
await this.dockerHost.request('DELETE', `/secrets/${this.ID}`);
|
await this.dockerHost.request('DELETE', `/secrets/${this.ID}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// get things
|
||||||
|
public getVersion() {
|
||||||
|
return this.Spec.Labels.version;
|
||||||
|
}
|
||||||
}
|
}
|
@ -39,14 +39,18 @@ export class DockerService {
|
|||||||
// lets get the image
|
// lets get the image
|
||||||
plugins.smartlog.defaultLogger.log(
|
plugins.smartlog.defaultLogger.log(
|
||||||
'info',
|
'info',
|
||||||
`downloading image for service ${serviceCreationDescriptor.Name}`
|
`downloading image for service ${serviceCreationDescriptor.name}`
|
||||||
);
|
);
|
||||||
const serviceImage = await DockerImage.createFromRegistry(dockerHost, {
|
const serviceImage = await DockerImage.createFromRegistry(dockerHost, {
|
||||||
imageUrl: serviceCreationDescriptor.Image
|
imageUrl: serviceCreationDescriptor.image
|
||||||
});
|
});
|
||||||
|
|
||||||
const serviceVersion = serviceImage.Labels.version;
|
const serviceVersion = serviceImage.Labels.version;
|
||||||
serviceCreationDescriptor.Labels.version = serviceVersion;
|
|
||||||
|
const labels: interfaces.TLabels = {
|
||||||
|
...serviceCreationDescriptor.labels,
|
||||||
|
version: serviceVersion
|
||||||
|
};
|
||||||
|
|
||||||
const networkArray: any[] = [];
|
const networkArray: any[] = [];
|
||||||
for (const network of serviceCreationDescriptor.networks) {
|
for (const network of serviceCreationDescriptor.networks) {
|
||||||
@ -71,11 +75,11 @@ export class DockerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const response = await dockerHost.request('POST', '/services/create', {
|
const response = await dockerHost.request('POST', '/services/create', {
|
||||||
Name: serviceCreationDescriptor.Name,
|
Name: serviceCreationDescriptor.name,
|
||||||
TaskTemplate: {
|
TaskTemplate: {
|
||||||
ContainerSpec: {
|
ContainerSpec: {
|
||||||
Image: serviceCreationDescriptor.Image,
|
Image: serviceCreationDescriptor.image,
|
||||||
Labels: serviceCreationDescriptor.Labels,
|
Labels: labels,
|
||||||
Secrets: secretArray
|
Secrets: secretArray
|
||||||
},
|
},
|
||||||
UpdateConfig: {
|
UpdateConfig: {
|
||||||
@ -87,13 +91,13 @@ export class DockerService {
|
|||||||
},
|
},
|
||||||
ForceUpdate: 1
|
ForceUpdate: 1
|
||||||
},
|
},
|
||||||
Labels: serviceCreationDescriptor.Labels,
|
Labels: serviceCreationDescriptor.labels,
|
||||||
Networks: networkArray
|
Networks: networkArray
|
||||||
});
|
});
|
||||||
|
|
||||||
const createdService = await DockerService.getServiceByName(
|
const createdService = await DockerService.getServiceByName(
|
||||||
dockerHost,
|
dockerHost,
|
||||||
serviceCreationDescriptor.Name
|
serviceCreationDescriptor.name
|
||||||
);
|
);
|
||||||
return createdService;
|
return createdService;
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import * as interfaces from './';
|
|||||||
|
|
||||||
export interface ISecretCreationDescriptor {
|
export interface ISecretCreationDescriptor {
|
||||||
name: string;
|
name: string;
|
||||||
|
version: string;
|
||||||
contentArg: any;
|
contentArg: any;
|
||||||
labels: interfaces.TLabels;
|
labels: interfaces.TLabels;
|
||||||
}
|
}
|
@ -3,9 +3,9 @@ import { DockerNetwork } from '../docker.classes.network';
|
|||||||
import { DockerSecret } from '../docker.classes.secret';
|
import { DockerSecret } from '../docker.classes.secret';
|
||||||
|
|
||||||
export interface IServiceCreationDescriptor {
|
export interface IServiceCreationDescriptor {
|
||||||
Name: string;
|
name: string;
|
||||||
Image: string;
|
image: string;
|
||||||
Labels: interfaces.TLabels;
|
labels: interfaces.TLabels;
|
||||||
networks: DockerNetwork[];
|
networks: DockerNetwork[];
|
||||||
networkAlias: string;
|
networkAlias: string;
|
||||||
secrets: DockerSecret[];
|
secrets: DockerSecret[];
|
||||||
|
Loading…
Reference in New Issue
Block a user