From 51334c297d1e92683a368270d33521dc88528e94 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Sun, 5 Jun 2016 04:45:46 +0200 Subject: [PATCH] even more docker --- ts/npmci.build.docker.ts | 28 ++++++++++++++++++++++------ ts/npmci.get.ts | 0 ts/npmci.prepare.ts | 5 +++-- 3 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 ts/npmci.get.ts diff --git a/ts/npmci.build.docker.ts b/ts/npmci.build.docker.ts index de32a1f..5a0ee58 100644 --- a/ts/npmci.build.docker.ts +++ b/ts/npmci.build.docker.ts @@ -26,11 +26,14 @@ let makeDockerfiles = function(){ } export class Dockerfile { + filePath:string; + buildTag:string; repo:string; version:string; content:string; baseImage:string; constructor(options:{filePath?:string,fileContents?:string|Buffer,read?:boolean}){ + this.filePath = options.filePath; this.repo = NpmciEnv.repo.user + "/" + NpmciEnv.repo.repo; this.version = dockerFileVersion(plugins.path.parse(options.filePath).base); if(options.filePath && options.read){ @@ -39,10 +42,16 @@ export class Dockerfile { this.baseImage = dockerBaseImage(this.content); }; build(){ - + let tag = dockerTag(this.repo,this.version); + plugins.shelljs.exec("docker build -t " + tag + " -f " + this.filePath + " ."); + this.buildTag = tag; }; push(){ - + if(this.buildTag){ + plugins.shelljs.exec("docker push " + this.buildTag); + } else { + plugins.beautylog.error("Dockerfile hasn't been built yet!"); + } } } @@ -64,10 +73,17 @@ let dockerBaseImage = function(dockerfileContentArg:string){ return regexResultArray[1]; } -export let dockerTagVersion = function(){ +export let dockerTag = function(repoArg:string,versionArg:string):string{ + let tagString:string; + let registry = NpmciEnv.dockerRegistry; if(process.env.CI_BUILD_STAGE == "test"){ - return "test"; - } else { - return "latest" + registry = "registry.gitlab.com"; + } + let repo = repoArg; + let version = versionArg; + if(process.env.CI_BUILD_STAGE == "test" || process.env.CI_BUILD_STAGE == "build"){ + version = version + "_test"; } + tagString = registry + "/" + repo + ":" + version; + return tagString; }; diff --git a/ts/npmci.get.ts b/ts/npmci.get.ts new file mode 100644 index 0000000..e69de29 diff --git a/ts/npmci.prepare.ts b/ts/npmci.prepare.ts index f516b6f..06f9766 100644 --- a/ts/npmci.prepare.ts +++ b/ts/npmci.prepare.ts @@ -51,9 +51,10 @@ export let prepare = function(serviceArg:string){ case "npm": return npm(); case "docker": - return docker(); + return docker() + .then(dockerGitlab); // always also login to gitlab registry for tests case "docker-gitlab": - return dockerGitlab(); + return dockerGitlab() default: break; }