Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (options.push) {
if (!options.user || !options.password) {
const message = "Required configuration missing for pushing docker image. Please make sure to set " +
"'registry', 'user' and 'password' in your configuration.";
progressLog.write(message);
return { code: 1, message };
}
const loginArgs: string[] = ["login", "--username", options.user, "--password", options.password];
if (/[^A-Za-z0-9]/.test(options.registry)) {
loginArgs.push(options.registry);
}
// 2. run docker login
let result = await spawnAndWatch(
{
command: "docker",
args: loginArgs,
},
{},
progressLog,
{
...spOpts,
logCommand: false,
});
if (result.code !== 0) {
return result;
}
// 3. run docker push
command: "docker",
args: loginArgs,
},
{},
progressLog,
{
...spOpts,
logCommand: false,
});
if (result.code !== 0) {
return result;
}
// 3. run docker push
result = await spawnAndWatch(
{
command: "docker",
args: ["push", image],
},
{},
progressLog,
spOpts);
if (result.code !== 0) {
return result;
}
}
}
}
const opts = {
cwd: p.baseDir,
};
const spOpts = {
errorFinder: code => code !== 0,
};
const imageName = await imageNameCreator(p, sdmGoal, options, context);
const image = `${imageName.registry}/${imageName.name}:${imageName.version}`;
const dockerfilePath = await (options.dockerfileFinder ? options.dockerfileFinder(p) : "Dockerfile");
// 1. run docker build
let result: ExecuteGoalResult = await spawnAndWatch(
{
command: "docker",
args: ["build", ".", "-f", dockerfilePath, "-t", image],
},
opts,
progressLog,
spOpts);
if (result.code !== 0) {
return result;
}
result = await dockerPush(image, options, progressLog);
// 4. create image link
if (await postLinkImageWebhook(
export const NodeProjectVersioner: ProjectVersioner = async (sdmGoal, p, log) => {
const pjFile = await p.getFile("package.json");
const pj = JSON.parse(await pjFile.getContent());
const branch = sdmGoal.branch.split("/").join(".");
const branchSuffix = branch !== sdmGoal.push.repo.defaultBranch ? `${branch}.` : "";
const version = `${pj.version}-${branchSuffix}${df(new Date(), "yyyymmddHHMMss")}`;
await spawnAndWatch({
command: "npm",
args: ["--no-git-tag-version", "version", version],
},
{
cwd: p.baseDir,
},
log,
{
errorFinder: code => code !== 0,
});
return version;
};
export async function npmCompilePreparation(p: GitProject, goalInvocation: GoalInvocation): Promise {
return spawnAndWatch({
command: "npm",
args: ["run", "compile"],
}, {
cwd: p.baseDir,
...DevelopmentEnvOptions,
}, goalInvocation.progressLog,
{
errorFinder: code => code != null,
});
}
public async undeploy(cfi: CloudFoundryInfo, deployment: CloudFoundryDeployment, log: ProgressLog): Promise {
await spawnAndWatch(asSpawnCommand(
`cf login -a ${cfi.api} -o ${cfi.org} -u ${cfi.username} -p '${cfi.password}' -s ${cfi.space}`),
{}, log);
return spawnAndWatch(asSpawnCommand(`cf delete ${deployment.appName}`), {}, log);
}
p.join(__dirname, "..", "..", "..", "..", "..", "scripts", "npm-publish.bash"),
];
if (options.registry) {
args.push("--registry", options.registry);
}
const access = await projectConfigurationValue("npm.publish.access", project, options.access);
if (access) {
args.push("--access", access);
}
if (options.tag) {
args.push("--tag", options.tag);
} else {
args.push("--tag", gitBranchToNpmTag(id.branch));
}
const result: ExecuteGoalResult = await spawnAndWatch(
{ command: "bash", args },
{ cwd: project.baseDir },
goalInvocation.progressLog,
);
if (result.code === 0) {
const pi = await projectIdentifier(project);
const url = `${options.registry}/${pi.name}/-/${pi.name}-${pi.version}.tgz`;
result.targetUrl = url;
if (options.status) {
await createStatus(
credentials,
id as GitHubRepoRef,
{
context: "npm/atomist/package",
export async function npmInstallPreparation(p: GitProject, goalInvocation: GoalInvocation): Promise {
const hasPackageLock = p.fileExistsSync("package-lock.json");
return spawnAndWatch({
command: "npm",
args: [hasPackageLock ? "ci" : "install"],
}, {
cwd: p.baseDir,
...DevelopmentEnvOptions,
}, goalInvocation.progressLog,
{
errorFinder: code => code != null,
});
}
export async function deleteBranchTag(branch: string, p: GitProject, options: NpmOptions): Promise {
const pj = await p.getFile("package.json");
if (pj) {
const tag = gitBranchToNpmTag(branch);
const name = JSON.parse(await pj.getContent()).name;
await configure(options, p);
const result = await spawnAndWatch({
command: "npm",
args: ["dist-tags", "rm", name, tag],
},
{
cwd: p.baseDir,
},
new LoggingProgressLog("npm dist-tag rm"),
{
errorFinder: SuccessIsReturn0ErrorFinder,
});
return result;
}
return Success;
}