@atomist/sample-sdm
Version:
Sample Atomist automation for software delivery
122 lines • 9.55 kB
JavaScript
"use strict";
/*
* Copyright © 2018 Atomist, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
const sdm_1 = require("@atomist/sdm");
const build = require("@atomist/sdm/dsl/buildDsl");
const DisplayDeployEnablement_1 = require("@atomist/sdm/handlers/commands/DisplayDeployEnablement");
const SetDeployEnablement_1 = require("@atomist/sdm/handlers/commands/SetDeployEnablement");
const machineFactory_1 = require("@atomist/sdm/machine/machineFactory");
const jvmPushTests_1 = require("@atomist/sdm/mapping/pushtest/jvm/jvmPushTests");
const nodePushTests_1 = require("@atomist/sdm/mapping/pushtest/node/nodePushTests");
const cloudFoundryManifestPushTest_1 = require("@atomist/sdm/mapping/pushtest/pcf/cloudFoundryManifestPushTest");
const toPublicRepo_1 = require("@atomist/sdm/mapping/pushtest/toPublicRepo");
const localDeploymentGoals_1 = require("../deploy/localDeploymentGoals");
const localSpringBootDeployers_1 = require("../deploy/localSpringBootDeployers");
const cloudReadiness_1 = require("../pack/cloud-readiness/cloudReadiness");
const demoEditors_1 = require("../pack/demo-editors/demoEditors");
const javaSupport_1 = require("../pack/java/javaSupport");
const nodeSupport_1 = require("../pack/node/nodeSupport");
const materialChangeToNodeRepo_1 = require("../pack/node/pushtest/materialChangeToNodeRepo");
const cloudFoundryDeploy_1 = require("../pack/pcf/cloudFoundryDeploy");
const suggestAddingCloudFoundryManifest_1 = require("../pack/pcf/suggestAddingCloudFoundryManifest");
const sentrySupport_1 = require("../pack/sentry/sentrySupport");
const materialChangeToJavaRepo_1 = require("../pack/spring/pushtest/materialChangeToJavaRepo");
const springPushTests_1 = require("../pack/spring/pushtest/springPushTests");
const springSupport_1 = require("../pack/spring/springSupport");
const teamPolicies_1 = require("./teamPolicies");
const deploy = require("@atomist/sdm/dsl/deployDsl");
const MavenBuilder_1 = require("@atomist/sdm/internal/delivery/build/local/maven/MavenBuilder");
const npmBuilder_1 = require("@atomist/sdm/internal/delivery/build/local/npm/npmBuilder");
const NpmDetectBuildMapping_1 = require("@atomist/sdm/internal/delivery/build/local/npm/NpmDetectBuildMapping");
const ManagedDeployments_1 = require("@atomist/sdm/internal/delivery/deploy/local/ManagedDeployments");
const EphemeralProgressLog_1 = require("@atomist/sdm/api-helper/log/EphemeralProgressLog");
const commonGoals_1 = require("@atomist/sdm/goal/common/commonGoals");
const httpServiceGoals_1 = require("@atomist/sdm/goal/common/httpServiceGoals");
const libraryGoals_1 = require("@atomist/sdm/goal/common/libraryGoals");
const npmGoals_1 = require("@atomist/sdm/goal/common/npmGoals");
const dockerPushTests_1 = require("@atomist/sdm/mapping/pushtest/docker/dockerPushTests");
const lookFor200OnEndpointRootGet_1 = require("@atomist/sdm/util/verify/lookFor200OnEndpointRootGet");
const cloudFoundrySupport_1 = require("../pack/pcf/cloudFoundrySupport");
/**
* Assemble a machine that supports Java, Spring and Node and deploys to Cloud Foundry
* See generatorConfig.ts to customize generation defaults.
* @return {SoftwareDeliveryMachine}
*/
function cloudFoundryMachine(configuration) {
const sdm = machineFactory_1.createSoftwareDeliveryMachine({
name: "CloudFoundry software delivery machine",
configuration,
}, sdm_1.given(jvmPushTests_1.IsMaven).itMeans("Maven")
.then(sdm_1.whenPushSatisfies(springPushTests_1.HasSpringBootApplicationClass, sdm_1.not(materialChangeToJavaRepo_1.MaterialChangeToJavaRepo))
.itMeans("No material change to Java")
.setGoals(commonGoals_1.NoGoals), sdm_1.whenPushSatisfies(sdm_1.ToDefaultBranch, springPushTests_1.HasSpringBootApplicationClass, cloudFoundryManifestPushTest_1.HasCloudFoundryManifest, toPublicRepo_1.ToPublicRepo, sdm_1.not(sdm_1.NamedSeedRepo), sdm_1.not(sdm_1.FromAtomist), sdm_1.IsDeployEnabled)
.itMeans("Spring Boot service to deploy")
.setGoals(httpServiceGoals_1.HttpServiceGoals), sdm_1.whenPushSatisfies(springPushTests_1.HasSpringBootApplicationClass, sdm_1.not(sdm_1.FromAtomist))
.itMeans("Spring Boot service local deploy")
.setGoals(localDeploymentGoals_1.LocalDeploymentGoals), sdm_1.onAnyPush.itMeans("Build Java library")
.set(libraryGoals_1.LibraryGoals)), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, sdm_1.not(materialChangeToNodeRepo_1.MaterialChangeToNodeRepo))
.itMeans("No material change to Node")
.setGoals(commonGoals_1.NoGoals), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, cloudFoundryManifestPushTest_1.HasCloudFoundryManifest, sdm_1.IsDeployEnabled, sdm_1.ToDefaultBranch)
.itMeans("Build and deploy Node")
.setGoals(npmGoals_1.NpmDeployGoals), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, dockerPushTests_1.HasDockerfile, sdm_1.ToDefaultBranch, sdm_1.IsDeployEnabled)
.itMeans("Docker deploy Node")
.setGoals(npmGoals_1.NpmKubernetesDeployGoals), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, dockerPushTests_1.HasDockerfile)
.itMeans("Docker build Node")
.setGoals(npmGoals_1.NpmDockerGoals), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, sdm_1.not(dockerPushTests_1.HasDockerfile))
.itMeans("Build Node")
.setGoals(npmGoals_1.NpmBuildGoals));
const hasPackageLock = sdm_1.hasFile("package-lock.json");
sdm.addBuildRules(build.when(nodePushTests_1.HasAtomistBuildFile)
.itMeans("Custom build script")
.set(NpmDetectBuildMapping_1.npmCustomBuilder(configuration.artifactStore, configuration.projectLoader)), build.when(nodePushTests_1.IsNode, sdm_1.ToDefaultBranch, hasPackageLock)
.itMeans("npm run build")
.set(npmBuilder_1.nodeBuilder(configuration.projectLoader, "npm ci", "npm run build")), build.when(nodePushTests_1.IsNode, hasPackageLock)
.itMeans("npm run compile")
.set(npmBuilder_1.nodeBuilder(configuration.projectLoader, "npm ci", "npm run compile")), build.when(nodePushTests_1.IsNode, sdm_1.ToDefaultBranch)
.itMeans("npm run build - no package lock")
.set(npmBuilder_1.nodeBuilder(configuration.projectLoader, "npm i", "npm run build")), build.when(nodePushTests_1.IsNode)
.itMeans("npm run compile - no package lock")
.set(npmBuilder_1.nodeBuilder(configuration.projectLoader, "npm i", "npm run compile")), build.setDefault(new MavenBuilder_1.MavenBuilder(configuration.artifactStore, EphemeralProgressLog_1.createEphemeralProgressLog, configuration.projectLoader)));
sdm.addDeployRules(deploy.when(jvmPushTests_1.IsMaven)
.deployTo(sdm_1.StagingDeploymentGoal, sdm_1.StagingEndpointGoal, commonGoals_1.StagingUndeploymentGoal)
.using({
deployer: localSpringBootDeployers_1.LocalExecutableJarDeployer,
targeter: ManagedDeployments_1.ManagedDeploymentTargeter,
}), deploy.when(jvmPushTests_1.IsMaven)
.deployTo(sdm_1.ProductionDeploymentGoal, sdm_1.ProductionEndpointGoal, sdm_1.ProductionUndeploymentGoal)
.using(cloudFoundryDeploy_1.cloudFoundryProductionDeploySpec(configuration.sdm)), deploy.when(nodePushTests_1.IsNode)
.itMeans("node run test")
.deployTo(sdm_1.StagingDeploymentGoal, sdm_1.StagingEndpointGoal, commonGoals_1.StagingUndeploymentGoal)
.using(cloudFoundryDeploy_1.cloudFoundryStagingDeploySpec(configuration.sdm)));
sdm.addDisposalRules(sdm_1.whenPushSatisfies(jvmPushTests_1.IsMaven, springPushTests_1.HasSpringBootApplicationClass, cloudFoundryManifestPushTest_1.HasCloudFoundryManifest)
.itMeans("Java project to undeploy from PCF")
.setGoals(httpServiceGoals_1.UndeployEverywhereGoals), sdm_1.whenPushSatisfies(nodePushTests_1.IsNode, cloudFoundryManifestPushTest_1.HasCloudFoundryManifest)
.itMeans("Node project to undeploy from PCF")
.setGoals(httpServiceGoals_1.UndeployEverywhereGoals), sdm_1.whenPushSatisfies(sdm_1.AnyPush)
.itMeans("We can always delete the repo")
.setGoals(httpServiceGoals_1.RepositoryDeletionGoals));
sdm.addChannelLinkListeners(suggestAddingCloudFoundryManifest_1.SuggestAddingCloudFoundryManifest)
.addSupportingCommands(SetDeployEnablement_1.enableDeploy, SetDeployEnablement_1.disableDeploy, DisplayDeployEnablement_1.isDeployEnabledCommand)
.addPushReactions(cloudFoundryDeploy_1.EnableDeployOnCloudFoundryManifestAddition)
.addEndpointVerificationListeners(lookFor200OnEndpointRootGet_1.lookFor200OnEndpointRootGet());
sdm.addExtensionPacks(demoEditors_1.DemoEditors, springSupport_1.SpringSupport, sentrySupport_1.SentrySupport, cloudReadiness_1.CloudReadinessChecks, javaSupport_1.JavaSupport, nodeSupport_1.NodeSupport, cloudFoundrySupport_1.CloudFoundrySupport);
teamPolicies_1.addTeamPolicies(sdm);
// DemoPolicies(sdm, configuration);
return sdm;
}
exports.cloudFoundryMachine = cloudFoundryMachine;
//# sourceMappingURL=cloudFoundryMachine.js.map