This repository has been archived by the owner on Jul 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
lievendoclo
committed
Sep 11, 2018
1 parent
59953b1
commit 7fe55fb
Showing
6 changed files
with
285 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { | ||
DefaultGoalNameGenerator, | ||
ExecuteGoal, | ||
ExecuteGoalResult, | ||
FulfillableGoalDetails, | ||
FulfillableGoalWithRegistrations, | ||
getGoalDefintionFrom, | ||
Goal, | ||
GoalInvocation, | ||
ImplementationRegistration, | ||
IndependentOfEnvironment, | ||
} from "@atomist/sdm"; | ||
import { | ||
DockerPerBranchDeployer, | ||
DockerPerBranchDeployerOptions, | ||
} from "./DockerPerBranchDeployer"; | ||
|
||
/** | ||
* Options for Docker deployment goal | ||
*/ | ||
export interface DockerDeployRegistration extends Partial<ImplementationRegistration> { | ||
/** | ||
* Starting port to be scanned for free ports. Defaults to 9090 | ||
*/ | ||
lowerPort?: number; | ||
/** | ||
* Pattern that indicates that the container has started up correctly | ||
*/ | ||
successPatterns: RegExp[]; | ||
/** | ||
* Base URL for the docker container. Probably localhost or your Docker machine IP. Defaults to localhost | ||
*/ | ||
baseUrl?: string; | ||
/** | ||
* The exposed port in the Dockerfile to be mapped externally | ||
*/ | ||
sourcePort: number; | ||
} | ||
|
||
/** | ||
* Goal definition for deployment using Docker | ||
*/ | ||
export const DockerDeployGoal = new Goal({ | ||
uniqueName: "docker-deploy", | ||
displayName: "docker deploy", | ||
environment: 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. | ||
*/ | ||
export class DockerDeploy extends FulfillableGoalWithRegistrations<DockerDeployRegistration> { | ||
constructor(private readonly goalDetailsOrUniqueName: FulfillableGoalDetails | string = DefaultGoalNameGenerator.generateName("docker-deploy"), | ||
...dependsOn: Goal[]) { | ||
super({ | ||
...DockerDeployGoal.definition, | ||
...getGoalDefintionFrom(goalDetailsOrUniqueName, DefaultGoalNameGenerator.generateName("docker-deploy")), | ||
displayName: "version", | ||
}, ...dependsOn); | ||
} | ||
|
||
public with(registration: DockerDeployRegistration): this { | ||
this.addFulfillment({ | ||
goalExecutor: executeDockerRun( { | ||
successPatterns: registration.successPatterns, | ||
lowerPort: registration.lowerPort ? registration.lowerPort : 9090, | ||
baseUrl: registration.baseUrl ? registration.baseUrl : "http://localhost", | ||
sourcePort: registration.sourcePort, | ||
}), | ||
name: DefaultGoalNameGenerator.generateName("docker-runner"), | ||
...registration as ImplementationRegistration, | ||
}); | ||
return this; | ||
} | ||
} | ||
|
||
function executeDockerRun(options: DockerPerBranchDeployerOptions): ExecuteGoal { | ||
const deployer = new DockerPerBranchDeployer(options); | ||
return async (goalInvocation: GoalInvocation): Promise<ExecuteGoalResult> => { | ||
return await deployer.deployProject(goalInvocation).then(deployment => { | ||
return { | ||
code: 0, | ||
targetUrl: deployment.endpoint, | ||
}; | ||
}, | ||
).catch(reason => { | ||
return { | ||
code: 1, | ||
message: reason, | ||
}; | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.