UNPKG

4.27 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright © 2018 Atomist, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18const automation_client_1 = require("@atomist/automation-client");
19const sdm_pack_node_1 = require("@atomist/sdm-pack-node");
20const sdm_pack_spring_1 = require("@atomist/sdm-pack-spring");
21const CloudFoundryTarget_1 = require("../api/CloudFoundryTarget");
22exports.AddCloudFoundryManifestMarker = "[atomist:add-pcf-manifest]";
23// Using this marker removes some buttons on the Pull Request
24exports.AtomistGeneratedMarker = "[atomist:generated]";
25exports.AtomistConfigTsPath = "src/atomist.config.ts";
26// This should not have been invoked unless it's a Spring or Node project
27exports.addCloudFoundryManifestTransform = async (p, ctx) => {
28 const javaId = await sdm_pack_spring_1.MavenProjectIdentifier(p);
29 if (javaId && await sdm_pack_spring_1.HasSpringBootPom.predicate(p)) {
30 return p.addFile(CloudFoundryTarget_1.CloudFoundryManifestPath, javaManifestFor(javaId.artifact, ctx.context.workspaceId));
31 }
32 const nodeId = await sdm_pack_node_1.NodeProjectIdentifier(p);
33 if (nodeId) {
34 const isAutomationClient = !!await p.getFile(exports.AtomistConfigTsPath);
35 automation_client_1.logger.info(`addCloudFoundryManifestEditor: Node project %j: automation client=${isAutomationClient}`, p.id);
36 return p.addFile(CloudFoundryTarget_1.CloudFoundryManifestPath, isAutomationClient ?
37 automationClientManifestFor(nodeId.name, ctx.context.workspaceId) :
38 nodeManifestFor(nodeId.name, ctx.context.workspaceId))
39 .then(() => p.addFile(".cfignore", "node_modules/"));
40 }
41 return ctx.context.messageClient.respond(`Unable to add Cloud Foundry manifest to project \`${p.id.owner}:${p.id.repo}\`: Neither Maven nor Node`);
42};
43/**
44 * Command handler wrapping AddCloudFoundryManifest editor
45 * @type {HandleCommand<EditOneOrAllParameters>}
46 */
47exports.AddCloudFoundryManifest = {
48 transform: exports.addCloudFoundryManifestTransform,
49 name: "AddCloudFoundryManifest",
50 intent: "Add Cloud Foundry manifest",
51 transformPresentation: () => new automation_client_1.editModes.PullRequest(`add-pcf-manifest-${Date.now()}`, "Add Cloud Foundry manifest", `This will trigger the Software Development Machine to deploy to your Cloud Foundry space.
52
53${exports.AtomistGeneratedMarker}`, `Add Cloud Foundry manifest
54
55${exports.AddCloudFoundryManifestMarker}`),
56};
57// Simple template for Cloud Foundry manifest
58const javaManifestFor = (name, teamId) => `---
59applications:
60- name: "${name}"
61 memory: 1024M
62 instances: 1
63 buildpack: https://github.com/cloudfoundry/java-buildpack.git
64 env:
65 ATOMIST_TEAM: ${teamId}`;
66const nodeManifestFor = (name, teamId) => `---
67applications:
68- name: "${name}"
69 memory: 512M
70 instances: 1
71 buildpack: https://github.com/cloudfoundry/nodejs-buildpack
72 env:
73 ATOMIST_TEAMS: ${teamId}`;
74// tslint:disable-next-line:max-line-length
75exports.StartAutomationClientCommand = "node --trace-warnings --expose_gc --optimize_for_size --always_compact --max_old_space_size=384 node_modules/@atomist/automation-client/start.client.js";
76/* tslint:disable:max-line-length */
77// dd: The poorly names "max_old_space_size" seems to map roughly to heap,
78// so you want your container limit to be 15-25% higher than whatever you set the max_old_space_size to.
79const automationClientManifestFor = (name, teamId) => `---
80applications:
81- name: ${name}
82 command: "${exports.StartAutomationClientCommand}"
83 memory: 512M
84 buildpack: https://github.com/cloudfoundry/nodejs-buildpack
85 env:
86 SUPPRESS_NO_CONFIG_WARNING: true
87 ATOMIST_TEAMS: ${teamId}`;
88//# sourceMappingURL=addCloudFoundryManifest.js.map
\No newline at end of file