Skip to content

Commit

Permalink
chore(wip): work in progress towards new features
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielHabenicht committed Apr 10, 2019
1 parent a633299 commit b081ec8
Show file tree
Hide file tree
Showing 19 changed files with 399 additions and 178 deletions.
2 changes: 1 addition & 1 deletion develop.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SemanticReleaseConfig, SemanticReleaseContext } from 'semantic-release';
import { prepare, publish, verifyConditions } from './src';
import { DockerPluginConfig } from './src/dockerPluginConfig';
import { DockerPluginConfig } from './src/models';

const config: SemanticReleaseConfig = {
branch: '',
Expand Down
27 changes: 10 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@commitlint/config-conventional": "^7.1.2",
"@types/chai": "^4.1.3",
"@types/chai-as-promised": "^7.1.0",
"@types/dockerode": "^2.5.4",
"@types/dockerode": "^2.5.13",
"@types/mocha": "^5.2.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
Expand Down
7 changes: 0 additions & 7 deletions src/dockerPluginConfig.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/model/auth.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/model/registry.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/models/PluginSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { DockerPluginConfig } from './dockerPluginConfig';

export interface PluginSettings {
path: '@iteratec/semantic-release-docker';
defaultValues: DockerPluginConfig;
}
9 changes: 9 additions & 0 deletions src/models/authentication.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Credentials } from './credentials';

/**
* Authentication
* From: https://docs.docker.com/engine/api/v1.37/#section/Authentication
*/
export interface Authentication extends Credentials {
serveraddress: string;
}
4 changes: 4 additions & 0 deletions src/models/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface Credentials {
username: string;
password: string;
}
8 changes: 8 additions & 0 deletions src/models/dockerPluginConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { SemanticReleasePlugin } from "semantic-release";
export interface DockerPluginConfig extends SemanticReleasePlugin {
additionalTags?: string[];
imageName: string;
registryUrl?: string;
repositoryName?: string;
pushVersionTag?: boolean;
}
3 changes: 3 additions & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { Authentication } from './authentication';
export { DockerPluginConfig } from './dockerPluginConfig';
export { Credentials } from './credentials';
13 changes: 13 additions & 0 deletions src/plugin-settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { PluginSettings } from "./models/PluginSettings";

export const pluginSettings: PluginSettings = {
path: "@iteratec/semantic-release-docker",
defaultValues: {
additionalTags: [],
imageName: "",
path: "@iteratec/semantic-release-docker",
pushVersionTag: true,
registryUrl: "",
repositoryName: ""
}
};
161 changes: 129 additions & 32 deletions src/prepare/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import chaiAsPromised from 'chai-as-promised';
import Dockerode from 'dockerode';

import { SemanticReleaseConfig, SemanticReleaseContext } from 'semantic-release';
import { DockerPluginConfig } from '../dockerPluginConfig';
import { DockerPluginConfig } from '../models';
import { prepare } from './index';

describe('@iteratec/semantic-release-docker', function() {
Expand All @@ -14,27 +14,6 @@ describe('@iteratec/semantic-release-docker', function() {
repositoryUrl: '',
tagFormat: '',
};
const context: SemanticReleaseContext = {
// tslint:disable-next-line:no-empty
logger: { log: (message: string) => {} },
nextRelease: {
gitTag: '',
notes: '',
version: 'next',
},
options: {
branch: '',
noCi: true,
prepare: [
{
imageName: '',
path: '@iteratec/semantic-release-docker',
} as DockerPluginConfig,
],
repositoryUrl: '',
tagFormat: '',
},
};

before(function() {
use(chaiAsPromised);
Expand All @@ -43,22 +22,140 @@ describe('@iteratec/semantic-release-docker', function() {
before(async function() {
this.timeout(10000);
const docker = new Dockerode();
return await docker.pull('hello-world', {});
docker.buildImage(
{
context: './',
src: ['Dockerfile'],
},
{
t: 'test1:latest',
},
function(error, output) {
if (error) {
return console.error(error);
}
},
);
docker.buildImage(
{
context: './',
src: ['Dockerfile'],
},
{
t: 'test2:latest',
},
function(error, output) {
if (error) {
return console.error(error);
}
},
);
process.env.DOCKER_REGISTRY_USER = 'username';
process.env.DOCKER_REGISTRY_PASSWORD = 'password';
});

it('should throw if no imagename is provided', function() {
const context = {
// tslint:disable-next-line:no-empty
logger: { log: (message: string) => {} },
nextRelease: {
gitTag: '',
notes: '',
version: 'next',
},
options: {
branch: '',
noCi: true,
prepare: [
{
path: '@iteratec/semantic-release-docker',
} as DockerPluginConfig,
],
repositoryUrl: '',
tagFormat: '',
},
} as SemanticReleaseContext;
return expect(prepare(config, context)).to.be.rejectedWith('\'imageName\' is not set in plugin configuration');
});

it('should tag an image', function() {
(context.options.prepare![0] as DockerPluginConfig).imageName = 'hello-world';
return expect(prepare(config, context)).to.eventually.deep.equal([['hello-world']]);
});
// it('should tag an image', function() {
// const context = {
// // tslint:disable-next-line:no-empty
// logger: { log: (message: string) => {} },
// nextRelease: {
// gitTag: '',
// notes: '',
// version: 'next',
// },
// options: {
// branch: '',
// noCi: true,
// prepare: [
// {
// imageName: 'test1',
// path: '@iteratec/semantic-release-docker',
// } as DockerPluginConfig,
// ],
// repositoryUrl: '',
// tagFormat: '',
// },
// } as SemanticReleaseContext;
// return expect(prepare(config, context)).to.eventually.deep.equal([['test1']]);
// });

it('should add multiple tags to an image', function() {
(context.options.prepare![0] as DockerPluginConfig).imageName = 'hello-world';
(context.options.prepare![0] as DockerPluginConfig).additionalTags = ['tag1', 'tag2'];
return expect(prepare(config, context).then((data) => data[0])).to.eventually.have.length(3);
});
// it('should add multiple tags to an image', function() {
// const context = {
// // tslint:disable-next-line:no-empty
// logger: { log: (message: string) => {} },
// nextRelease: {
// gitTag: '',
// notes: '',
// version: 'next',
// },
// options: {
// branch: '',
// noCi: true,
// prepare: [
// {
// imageName: 'test1',
// path: '@iteratec/semantic-release-docker',
// additionalTags: ['tag1', 'tag2'],
// } as DockerPluginConfig,
// ],
// repositoryUrl: '',
// tagFormat: '',
// },
// } as SemanticReleaseContext;
// return expect(prepare(config, context).then((data) => data[0])).to.eventually.have.length(3);
// });

// it('should add multiple images', function() {
// const context = {
// // tslint:disable-next-line:no-empty
// logger: { log: (message: string) => {} },
// nextRelease: {
// gitTag: '',
// notes: '',
// version: 'next',
// },
// options: {
// branch: '',
// noCi: true,
// prepare: [
// {
// imageName: 'test1',
// path: '@iteratec/semantic-release-docker',
// } as DockerPluginConfig,
// {
// imageName: 'test2',
// path: '@iteratec/semantic-release-docker',
// } as DockerPluginConfig,
// ],
// repositoryUrl: '',
// tagFormat: '',
// },
// } as SemanticReleaseContext;
// return expect(prepare(config, context)).to.eventually.have.length(2);
// });
});
});
Loading

0 comments on commit b081ec8

Please sign in to comment.