@atomist/sdm-pack-docker
Version:
Extension Pack for an Atomist SDM to integrate Docker
75 lines • 3.54 kB
JavaScript
;
/*
* Copyright © 2019 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.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const sdm_1 = require("@atomist/sdm");
const DockerPerBranchDeployer_1 = require("./DockerPerBranchDeployer");
/**
* Goal definition for deployment using Docker
*/
exports.DockerDeployGoal = new sdm_1.Goal({
uniqueName: "docker-deploy",
displayName: "docker deploy",
environment: sdm_1.IndependentOfEnvironment,
workingDescription: "Deploying using Docker",
completedDescription: "Deployed with Docker",
failedDescription: "Docker deployment failed",
});
/**
* This goal will deploy the Docker image built by the `DockerBuild` goal. Deployments mapped
* to free ports and a deployment will be done per branch.
*/
class DockerDeploy extends sdm_1.FulfillableGoalWithRegistrations {
constructor(goalDetailsOrUniqueName = sdm_1.DefaultGoalNameGenerator.generateName("docker-deploy"), ...dependsOn) {
super(Object.assign({}, exports.DockerDeployGoal.definition, sdm_1.getGoalDefinitionFrom(goalDetailsOrUniqueName, sdm_1.DefaultGoalNameGenerator.generateName("docker-deploy")), { displayName: "version" }), ...dependsOn);
this.goalDetailsOrUniqueName = goalDetailsOrUniqueName;
}
with(registration) {
this.addFulfillment(Object.assign({ goalExecutor: executeDockerRun({
successPatterns: registration.successPatterns,
lowerPort: registration.lowerPort ? registration.lowerPort : 9090,
baseUrl: registration.baseUrl ? registration.baseUrl : "http://127.0.0.1",
sourcePort: registration.sourcePort,
}), name: sdm_1.DefaultGoalNameGenerator.generateName("docker-runner") }, registration));
return this;
}
}
exports.DockerDeploy = DockerDeploy;
function executeDockerRun(options) {
const deployer = new DockerPerBranchDeployer_1.DockerPerBranchDeployer(options);
return (goalInvocation) => __awaiter(this, void 0, void 0, function* () {
return deployer.deployProject(goalInvocation).then(deployment => {
return {
code: 0,
targetUrl: deployment.endpoint,
};
}).catch(reason => {
return {
code: 1,
message: reason,
};
});
});
}
//# sourceMappingURL=DockerDeploy.js.map