Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/hld-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ invoke "manifest generation"
and configuration into Kubernetes yaml.

```
Usage: hld install-manifest-pipeline|m [options]
Usage: hld install-manifest-pipeline|p [options]

Install the manifest generation pipeline to your Azure DevOps instance. Default values are set in spk-config.yaml and can be loaded via spk init or overriden via option flags.

Expand All @@ -89,6 +89,7 @@ Options:
-u, --hld-url <hld-url> HLD Repository URL
-m, --manifest-url <manifest-url> Manifest Repository URL
-d, --devops-project <devops-project> Azure DevOps Project
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
-h, --help output usage information
```

Expand Down
1 change: 1 addition & 0 deletions docs/project-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ Options:
-u, --repo-url <repo-url> Repository URL
-e, --hld-url <hld-url> HLD Repository URL
-d, --devops-project <devops-project> Azure DevOps Project
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
-h, --help output usage information
```
3 changes: 2 additions & 1 deletion docs/service-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ https://docs.microsoft.com/en-us/azure/devops/pipelines/process/stages?view=azur
```
Usage: service install-build-pipeline|p [options] <service-name>

Install the build and push to acr pipeline for a service to your Azure DevOps instance.
Install the build and push to acr pipeline for a service to your Azure DevOps instance

Options:
-n, --pipeline-name <pipeline-name> Name of the pipeline to be created
Expand All @@ -74,6 +74,7 @@ Options:
-r, --repo-name <repo-name> Repository Name in Azure DevOps
-u, --repo-url <repo-url> Repository URL
-d, --devops-project <devops-project> Azure DevOps Project
-b, --build-script <build-script-url> Build Script URL. By default it is 'https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh'.
-l, --packages-dir <packages-dir> The mono-repository directory containing this service definition. ie. '--packages-dir packages' if my-service is located under ./packages/my-service. Omitting this option implies this is a not a mono-repository.
-h, --help output usage information
```
Expand Down
73 changes: 44 additions & 29 deletions src/commands/hld/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,26 @@ afterAll(() => {
});

describe("required pipeline variables", () => {
it("should use access token and repo as pipeline vars", () => {
const variables = requiredPipelineVariables("foo", "bar");
it("should use have the proper pipeline vars vars", () => {
const variables = requiredPipelineVariables(
"somePAT",
"buildScriptUrl",
"manifestRepoUrl"
);

expect(Object.keys(variables).length).toBe(3);

expect(Object.keys(variables).length).toBe(2);
expect(variables.PAT.value).toBe("foo");
expect(variables.PAT.value).toBe("somePAT");
expect(variables.PAT.isSecret).toBe(true);
expect(variables.PAT.allowOverride).toBe(true);

expect(variables.BUILD_SCRIPT_URL.value).toBe("buildScriptUrl");
expect(variables.BUILD_SCRIPT_URL.isSecret).toBe(false);
expect(variables.BUILD_SCRIPT_URL.allowOverride).toBe(true);

expect(variables.MANIFEST_REPO.value).toBe("bar");
expect(variables.MANIFEST_REPO.value).toBe("manifestRepoUrl");
expect(variables.MANIFEST_REPO.isSecret).toBe(false);
expect(variables.MANIFEST_REPO.allowOverride).toBe(true);
});
});

Expand All @@ -40,13 +51,14 @@ describe("create hld to manifest pipeline test", () => {

const exitFn = jest.fn();
await installHldToManifestPipeline(
"foo",
"bar",
"wow",
"amazing",
"meow",
"baz",
"orgName",
"personalAccessToken",
"hldRepoName",
"hldRepoUrl",
"manifestRepoUrl",
"project",
"pipelineName",
"buildScriptUrl",
exitFn
);

Expand All @@ -58,13 +70,14 @@ describe("create hld to manifest pipeline test", () => {

const exitFn = jest.fn();
await installHldToManifestPipeline(
"foo",
"bar",
"baz",
"wow",
"wao",
"baz",
"orgName",
"personalAccessToken",
"hldRepoName",
"hldRepoUrl",
"manifestRepoUrl",
"project",
"pipelineName",
"buildScriptUrl",
exitFn
);

Expand All @@ -79,13 +92,14 @@ describe("create hld to manifest pipeline test", () => {

const exitFn = jest.fn();
await installHldToManifestPipeline(
"foo",
"bar",
"baz",
"wow",
"wao",
"baz",
"orgName",
"personalAccessToken",
"hldRepoName",
"hldRepoUrl",
"manifestRepoUrl",
"project",
"pipelineName",
"buildScriptUrl",
exitFn
);

Expand All @@ -99,13 +113,14 @@ describe("create hld to manifest pipeline test", () => {

const exitFn = jest.fn();
await installHldToManifestPipeline(
"foo",
"bar",
"baz",
"wow",
"wao",
"baz",
"orgName",
"personalAccessToken",
"hldRepoName",
"hldRepoUrl",
"manifestRepoUrl",
"project",
"pipelineName",
"buildScriptUrl",
exitFn
);

Expand Down
35 changes: 31 additions & 4 deletions src/commands/hld/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "azure-devops-node-api/interfaces/BuildInterfaces";
import commander from "commander";
import { Config } from "../../config";
import { BUILD_SCRIPT_URL } from "../../lib/constants";
import { getRepositoryName } from "../../lib/gitutils";
import {
createPipelineForDefinition,
Expand All @@ -20,7 +21,7 @@ export const installHldToManifestPipelineDecorator = (
): void => {
command
.command("install-manifest-pipeline")
.alias("m")
.alias("p")
.description(
"Install the manifest generation pipeline to your Azure DevOps instance. Default values are set in spk-config.yaml and can be loaded via spk init or overriden via option flags."
)
Expand All @@ -37,6 +38,10 @@ export const installHldToManifestPipelineDecorator = (
.option("-u, --hld-url <hld-url>", "HLD Repository URL")
.option("-m, --manifest-url <manifest-url>", "Manifest Repository URL")
.option("-d, --devops-project <devops-project>", "Azure DevOps Project")
.option(
"-b, --build-script <build-script-url>",
`Build Script URL. By default it is '${BUILD_SCRIPT_URL}'.`
)
.action(async opts => {
const { azure_devops } = Config();

Expand All @@ -52,7 +57,8 @@ export const installHldToManifestPipelineDecorator = (
personalAccessToken = azure_devops && azure_devops.access_token,
devopsProject = azure_devops && azure_devops.project,
hldName = getRepositoryName(hldUrl),
pipelineName = hldName + "-to-" + manifestRepoName
pipelineName = hldName + "-to-" + manifestRepoName,
buildScriptUrl = BUILD_SCRIPT_URL
} = opts;

logger.debug(`orgName: ${orgName}`);
Expand All @@ -62,6 +68,7 @@ export const installHldToManifestPipelineDecorator = (
logger.debug(`manifestUrl: ${manifestUrl}`);
logger.debug(`hldName: ${hldName}`);
logger.debug(`hldUrl: ${hldUrl}`);
logger.debug(`buildScriptUrl: ${buildScriptUrl}`);

try {
if (typeof pipelineName !== "string") {
Expand Down Expand Up @@ -105,6 +112,11 @@ export const installHldToManifestPipelineDecorator = (
`--devops-project must be of type 'string', ${typeof devopsProject} given.`
);
}
if (typeof buildScriptUrl !== "string") {
throw new Error(
`--build-script must be of type 'string', ${typeof buildScriptUrl} given.`
);
}
} catch (err) {
logger.error(
`Error occurred validating inputs for hld install-manifest-pipeline`
Expand All @@ -122,6 +134,7 @@ export const installHldToManifestPipelineDecorator = (
manifestUrl,
devopsProject,
pipelineName,
buildScriptUrl,
process.exit
);
} catch (err) {
Expand All @@ -143,6 +156,8 @@ export const installHldToManifestPipelineDecorator = (
* @param hldRepoUrl URL to the HLD repository
* @param manifestRepoUrl URL to the materialized manifest repository
* @param project Azure DevOps project that the HLD and Materialized manifest repository is in
* @param pipelineName Name of this build pipeline in AzDo
* @param buildScriptUrl Build Script URL
*/
export const installHldToManifestPipeline = async (
orgName: string,
Expand All @@ -152,6 +167,7 @@ export const installHldToManifestPipeline = async (
manifestRepoUrl: string,
project: string,
pipelineName: string,
buildScriptUrl: string,
exitFn: (status: number) => void
) => {
let devopsClient;
Expand All @@ -172,7 +188,11 @@ export const installHldToManifestPipeline = async (
pipelineName: pipelineName,
repositoryName: hldRepoName,
repositoryUrl: hldRepoUrl,
variables: requiredPipelineVariables(personalAccessToken, manifestRepoUrl),
variables: requiredPipelineVariables(
personalAccessToken,
buildScriptUrl,
manifestRepoUrl
),
yamlFileBranch: "master",
yamlFilePath: `manifest-generation.yaml`
} as IAzureRepoPipelineConfig);
Expand Down Expand Up @@ -208,14 +228,21 @@ export const installHldToManifestPipeline = async (
/**
* Builds and returns variables required for the HLD to Manifest pipeline.
* @param accessToken Access token with access to the manifest repository.
* @param buildScriptUrl Build Script URL
* @param manifestRepoUrl URL to the materialized manifest repository.
* @returns Object containing the necessary run-time variables for the HLD to Manifest repository.
* @returns Object containing the necessary run-time variables for the HLD to Manifest pipeline.
*/
export const requiredPipelineVariables = (
accessToken: string,
buildScriptUrl: string,
manifestRepoUrl: string
): { [key: string]: BuildDefinitionVariable } => {
return {
BUILD_SCRIPT_URL: {
allowOverride: true,
isSecret: false,
value: buildScriptUrl
},
MANIFEST_REPO: {
allowOverride: true,
isSecret: false,
Expand Down
41 changes: 36 additions & 5 deletions src/commands/project/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import {
queueBuild
} from "../../lib/pipelines/pipelines";

import { installPipeline } from "./pipeline";
import {
installLifecyclePipeline,
requiredPipelineVariables
} from "./pipeline";

beforeAll(() => {
enableVerboseLogging();
Expand All @@ -18,19 +21,44 @@ afterAll(() => {
disableVerboseLogging();
});

describe("required pipeline variables", () => {
it("should use have the proper pipeline vars vars", () => {
const variables = requiredPipelineVariables(
"somePAT",
"buildScriptUrl",
"hldRepoUrl"
);

expect(Object.keys(variables).length).toBe(3);

expect(variables.PAT.value).toBe("somePAT");
expect(variables.PAT.isSecret).toBe(true);
expect(variables.PAT.allowOverride).toBe(true);

expect(variables.BUILD_SCRIPT_URL.value).toBe("buildScriptUrl");
expect(variables.BUILD_SCRIPT_URL.isSecret).toBe(false);
expect(variables.BUILD_SCRIPT_URL.allowOverride).toBe(true);

expect(variables.HLD_REPO.value).toBe("hldRepoUrl");
expect(variables.HLD_REPO.isSecret).toBe(false);
expect(variables.HLD_REPO.allowOverride).toBe(true);
});
});

describe("create hld to manifest pipeline test", () => {
it("should create a pipeline", async () => {
(createPipelineForDefinition as jest.Mock).mockReturnValue({ id: 10 });

const exitFn = jest.fn();
await installPipeline(
await installLifecyclePipeline(
"orgName",
"PAT",
"pipelineName",
"repoName",
"repoUrl",
"hldRepoUrl",
"azDoProject",
"buildScriptUrl",
exitFn
);

Expand All @@ -41,14 +69,15 @@ describe("create hld to manifest pipeline test", () => {
(getBuildApiClient as jest.Mock).mockReturnValue(Promise.reject());

const exitFn = jest.fn();
await installPipeline(
await installLifecyclePipeline(
"orgName",
"PAT",
"pipelineName",
"repoName",
"repoUrl",
"hldRepoUrl",
"azDoProject",
"buildScriptUrl",
exitFn
);

Expand All @@ -62,14 +91,15 @@ describe("create hld to manifest pipeline test", () => {
);

const exitFn = jest.fn();
await installPipeline(
await installLifecyclePipeline(
"orgName",
"PAT",
"pipelineName",
"repoName",
"repoUrl",
"hldRepoUrl",
"azDoProject",
"buildScriptUrl",
exitFn
);

Expand All @@ -82,14 +112,15 @@ describe("create hld to manifest pipeline test", () => {
(queueBuild as jest.Mock).mockReturnValue(Promise.reject());

const exitFn = jest.fn();
await installPipeline(
await installLifecyclePipeline(
"orgName",
"PAT",
"pipelineName",
"repoName",
"repoUrl",
"hldRepoUrl",
"azDoProject",
"buildScriptUrl",
exitFn
);

Expand Down
Loading