From e1245f24ce786098f94adfc340be80d82980fcd5 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Fri, 3 Jun 2016 03:44:24 +0200 Subject: [PATCH] add some functions --- dist/npmci.build.js | 16 +++++++++++++--- ts/npmci.build.ts | 15 ++------------- ts/npmci.env.ts | 22 ++++++++++++++++++++++ ts/npmci.prepare.ts | 3 +++ ts/npmci.publish.ts | 16 ++++------------ 5 files changed, 44 insertions(+), 28 deletions(-) diff --git a/dist/npmci.build.js b/dist/npmci.build.js index 87b2943..19e5b08 100644 --- a/dist/npmci.build.js +++ b/dist/npmci.build.js @@ -14,16 +14,26 @@ exports.build = function (commandArg) { }; var docker = function () { var done = plugins.q.defer(); - plugins.shelljs.exec("docker build -t " + "registry.gitlab.com/" + env.repo.user + "/" + env.repo.repo + ":latest ."); + plugins.shelljs.exec("docker build -t " + env.repo.user + "/" + env.repo.repo + ":latest ."); done.resolve(); return done.promise; }; var dockerGitlab = function () { var done = plugins.q.defer(); var repo = new plugins.smartstring.GitRepo(process.env.CI_BUILD_REPO); - plugins.shelljs.exec("docker build -t " + "registry.gitlab.com/" + env.repo.user + "/" + env.repo.repo + ":latest ."); + var dockerTag = "registry.gitlab.com/" + env.repo.user + "/" + env.repo.repo + ":" + dockerTagVersion() + " ."; + plugins.beautylog.info("now building docker image with tag " + dockerTag); + plugins.shelljs.exec("docker build -t " + dockerTag); done.resolve(); return done.promise; }; +var dockerTagVersion = function () { + if (process.env.CI_BUILD_STAGE == "test") { + return "test"; + } + else { + return "latest"; + } +}; -//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5wbWNpLmJ1aWxkLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxRQUFPLGdCQUFnQixDQUFDLENBQUE7QUFDeEIsSUFBWSxPQUFPLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUUzQyxJQUFZLEdBQUcsV0FBTSxhQUFhLENBQ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byArIFwiOmxhdGVzdCAuXCIpO1xyXG4gICAgZG9uZS5yZXNvbHZlKCk7XHJcbiAgICByZXR1cm4gZG9uZS5wcm9taXNlO1xyXG59XHJcblxyXG5sZXQgZG9ja2VyR2l0bGFiID0gZnVuY3Rpb24oKXtcclxuICAgIGxldCBkb25lID0gcGx1Z2lucy5xLmRlZmVyKCk7XHJcbiAgICBsZXQgcmVwbyA9IG5ldyBwbHVnaW5zLnNtYXJ0c3RyaW5nLkdpdFJlcG8ocHJvY2Vzcy5lbnYuQ0lfQlVJTERfUkVQTyk7XHJcbiAgICBsZXQgZG9ja2VyVGFnID0gXCJyZWdpc3RyeS5naXRsYWIuY29tL1wiICsgZW52LnJlcG8udXNlciArIFwiL1wiICsgZW52LnJlcG8ucmVwbyArIFwiOlwiICsgZG9ja2VyVGFnVmVyc2lvbigpICtcIiAuXCI7XHJcbiAgICBwbHVnaW5zLmJlYXV0eWxvZy5pbmZvKFwibm93IGJ1aWxkaW5nIGRvY2tlciBpbWFnZSB3aXRoIHRhZyBcIiArIGRvY2tlclRhZyk7XHJcbiAgICBwbHVnaW5zLnNoZWxsanMuZXhlYyhcImRvY2tlciBidWlsZCAtdCBcIiArIGRvY2tlclRhZyk7XHJcbiAgICBkb25lLnJlc29sdmUoKTtcclxuICAgIHJldHVybiBkb25lLnByb21pc2U7XHJcbn1cclxuXHJcbmxldCBkb2NrZXJUYWdWZXJzaW9uID0gZnVuY3Rpb24oKXtcclxuICAgIGlmKHByb2Nlc3MuZW52LkNJX0JVSUxEX1NUQUdFID09IFwidGVzdFwiKXtcclxuICAgICAgICByZXR1cm4gXCJ0ZXN0XCI7XHJcbiAgICB9IGVsc2Uge1xyXG4gICAgICAgIHJldHVybiBcImxhdGVzdFwiXHJcbiAgICB9XHJcbn0iXX0= diff --git a/ts/npmci.build.ts b/ts/npmci.build.ts index 771b00b..feab24b 100644 --- a/ts/npmci.build.ts +++ b/ts/npmci.build.ts @@ -6,25 +6,14 @@ import * as env from "./npmci.env"; export let build = function(commandArg){ switch(commandArg){ case "docker": - return docker(); - case "docker-gitlab": - return dockerGitlab(); - default: - break; + return docker(); } } let docker = function(){ let done = plugins.q.defer(); - plugins.shelljs.exec("docker build -t " + "registry.gitlab.com/" + env.repo.user + "/" + env.repo.repo + ":latest ."); + plugins.shelljs.exec("docker build -t " + env.dockerTag()); done.resolve(); return done.promise; } -let dockerGitlab = function(){ - let done = plugins.q.defer(); - let repo = new plugins.smartstring.GitRepo(process.env.CI_BUILD_REPO); - plugins.shelljs.exec("docker build -t " + "registry.gitlab.com/" + env.repo.user + "/" + env.repo.repo + ":latest ."); - done.resolve(); - return done.promise; -} \ No newline at end of file diff --git a/ts/npmci.env.ts b/ts/npmci.env.ts index dda8024..b975a6a 100644 --- a/ts/npmci.env.ts +++ b/ts/npmci.env.ts @@ -6,3 +6,25 @@ import {GitRepo} from "smartstring"; export let repo = new GitRepo(process.env.CI_BUILD_REPO); export let dockerTestTag:string; export let dockerReleaseTag:string; + +export let dockerRegistry = "docker.io"; // will be set by npmci.prepare + +export let dockerTagVersion = function(){ + if(process.env.CI_BUILD_STAGE == "test"){ + return "test"; + } else { + return "latest" + } +} + +export let dockerTag = function(){ + return dockerRegistry + "/" + repo.user + "/" + repo.repo + ":" + dockerTagVersion() +" ."; +} + +export let dockerTagTest = function(){ + return dockerRegistry + "/" + repo.user + "/" + repo.repo + ":test ."; +} + +export let dockerTagRelease = function(){ + return dockerRegistry + "/" + repo.user + "/" + repo.repo + ":latest ."; +} diff --git a/ts/npmci.prepare.ts b/ts/npmci.prepare.ts index a01f3db..9797de8 100644 --- a/ts/npmci.prepare.ts +++ b/ts/npmci.prepare.ts @@ -1,6 +1,7 @@ import "typings-global"; import * as plugins from "./npmci.plugins"; import {bash} from "./npmci.bash"; +import * as env from "./npmci.env" let npm = function(){ let done = plugins.q.defer(); @@ -22,6 +23,7 @@ let npm = function(){ let docker = function(){ let done = plugins.q.defer(); + env.dockerRegistry = "docker.io" let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/ if(!process.env.NPMCI_LOGIN_DOCKER){ plugins.beautylog.error("You have to specify Login Data to the Docker Registry"); @@ -37,6 +39,7 @@ let docker = function(){ let dockerGitlab = function(){ let done = plugins.q.defer(); + env.dockerRegistry = "registry.gitlab.io" let ciBuildToken = process.env.CI_BUILD_TOKEN plugins.shelljs.exec("docker login -u gitlab-ci-token -p " + ciBuildToken + " registry.gitlab.com"); done.resolve(); diff --git a/ts/npmci.publish.ts b/ts/npmci.publish.ts index 886399e..6596d5b 100644 --- a/ts/npmci.publish.ts +++ b/ts/npmci.publish.ts @@ -4,21 +4,12 @@ import {prepare} from "./npmci.prepare"; import {bash} from "./npmci.bash"; export let publish = (serviceArg:string = "npm") => { - let done = plugins.q.defer(); switch (serviceArg){ case "npm": - publishNpm() - .then(function(){ - done.resolve(); - }); - break; + return publishNpm(); case "docker": - publishDocker() - .then(function(){ - done.resolve(); - }); + return publishDocker(); } - return done.promise; }; let publishNpm = function(){ @@ -36,7 +27,8 @@ let publishDocker = function(){ let done = plugins.q.defer(); prepare("docker") .then(function(){ - bash("docker push"); + bash + bash("docker push "); done.resolve(); }); return done.promise;