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
Show all changes
53 commits
Select commit Hold shift + click to select a range
120bdfb
[FEATURE] scaffold app and helm repo in spk setup command
dennisseah Mar 12, 2020
e1336f9
Merge branch 'master' into issue1113
dennisseah Mar 13, 2020
8f7cbf5
Merge branch 'master' into issue1113
dennisseah Mar 13, 2020
2bc0554
[FEATURE] lifecycle and build pipeline in spk setup command
dennisseah Mar 13, 2020
d12021f
Merge branch 'master' into issue1113
dennisseah Mar 14, 2020
b0b37bc
fix eslint error
dennisseah Mar 14, 2020
7cb19ec
Merge branch 'issue1113' into issue1113x
dennisseah Mar 14, 2020
8046f6e
fixed unit test
dennisseah Mar 14, 2020
23c8d7f
making acr name configurable that's not hardcode it
dennisseah Mar 15, 2020
a84c4ef
Merge branch 'issue1113' into issue1113x
dennisseah Mar 15, 2020
681ea40
added code to check if acr name is between 5 and 50 chars long
dennisseah Mar 16, 2020
8d9162a
Merge branch 'issue1113' into issue1113x
dennisseah Mar 16, 2020
2c8c613
Changes to get build pipeline working in branch issue1113x (#402)
andrebriggs Mar 16, 2020
09d82be
minor fixes
dennisseah Mar 16, 2020
37baac3
Merge branch 'master' into issue1113
dennisseah Mar 16, 2020
676fb8e
Merge branch 'issue1113' into issue1113x
dennisseah Mar 16, 2020
67aacfb
Merge branch 'master' into issue1113
dennisseah Mar 16, 2020
60d5751
Merge branch 'issue1113' into issue1113x
dennisseah Mar 16, 2020
28663da
Merge branch 'master' into issue1113
dennisseah Mar 16, 2020
13bd099
Merge branch 'issue1113' into issue1113x
dennisseah Mar 16, 2020
704a4e1
Merge branch 'master' into issue1113
dennisseah Mar 17, 2020
6364158
Merge branch 'issue1113' into issue1113x
dennisseah Mar 17, 2020
2f52d08
Merge branch 'master' into issue1113
dennisseah Mar 17, 2020
8d6c2cb
fix test
dennisseah Mar 17, 2020
19daa29
Merge branch 'issue1113' into issue1113x
dennisseah Mar 17, 2020
729680f
Merge branch 'master' into issue1113
dennisseah Mar 17, 2020
1df4bc3
Merge branch 'issue1113' into issue1113x
dennisseah Mar 17, 2020
98d2eb1
Merge branch 'master' into issue1113
NathanielRose Mar 17, 2020
de9c0ca
Merge branch 'issue1113' into issue1113x
dennisseah Mar 17, 2020
8424333
Merge branch 'master' into issue1113
dennisseah Mar 18, 2020
5fe5c08
Merge branch 'master' into issue1113
dennisseah Mar 18, 2020
69c19b3
resolved conflicts
dennisseah Mar 18, 2020
b55d3a8
Merge branch 'issue1113' into issue1113x
dennisseah Mar 18, 2020
3aa02c0
fix lint
dennisseah Mar 18, 2020
f209ec3
Merge branch 'issue1113' into issue1113x
dennisseah Mar 18, 2020
dc4327e
Merge branch 'master' into issue1113
dennisseah Mar 18, 2020
6f136e0
Merge branch 'issue1113' into issue1113x
dennisseah Mar 18, 2020
ec3eae0
fix tests
dennisseah Mar 18, 2020
edb6e05
adding tests and prompt for subscriptionId before creating sp
dennisseah Mar 19, 2020
fc1489a
Merge branch 'master' into issue1113
dennisseah Mar 19, 2020
c9fb80f
rebase
dennisseah Mar 19, 2020
78dfc2c
Merge branch 'issue1113' into issue1113x
dennisseah Mar 19, 2020
4097e8f
fix eslint
dennisseah Mar 19, 2020
a807cc5
Merge branch 'master' into issue1113
dennisseah Mar 19, 2020
b6a5d63
Merge branch 'issue1113' into issue1113x
dennisseah Mar 19, 2020
c357ecc
Delete tslint.json
dennisseah Mar 19, 2020
0e56229
Merge branch 'master' into issue1113x
dennisseah Mar 19, 2020
3f8da2b
Merge branch 'master' into issue1113x
dennisseah Mar 19, 2020
e22ebb8
Merge branch 'master' into issue1113x
dennisseah Mar 19, 2020
d6375e7
Update subscriptionService.test.ts
dennisseah Mar 19, 2020
914b2ad
Merge branch 'master' into issue1113x
dennisseah Mar 20, 2020
cdf802a
Merge branch 'master' into issue1113x
dennisseah Mar 20, 2020
ea4c608
fixing labels and messages
dennisseah Mar 20, 2020
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: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@
"webpack-cli": "^3.3.9"
},
"prettier": {
"proseWrap": "always",
"quote-props": "preserve"
"proseWrap": "always"
},
"husky": {
"hooks": {
Expand Down
17 changes: 8 additions & 9 deletions src/commands/deployment/dashboard.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/camelcase */
jest.mock("open");
import open from "open";
jest.mock("../../config");
Expand Down Expand Up @@ -31,18 +30,18 @@ afterAll(() => {

const mockConfig = (): void => {
(Config as jest.Mock).mockReturnValueOnce({
azure_devops: {
access_token: uuid(),
"azure_devops": {
"access_token": uuid(),
org: uuid(),
project: uuid()
},
introspection: {
azure: {
account_name: uuid(),
"account_name": uuid(),
key: uuid(),
partition_key: uuid(),
source_repo_access_token: "test_token",
table_name: uuid()
"partition_key": uuid(),
"source_repo_access_token": "test_token",
"table_name": uuid()
}
}
});
Expand Down Expand Up @@ -209,8 +208,8 @@ describe("Fallback to azure devops access token", () => {
describe("Extract manifest repository information", () => {
test("Manifest repository information is successfully extracted", () => {
(Config as jest.Mock).mockReturnValue({
azure_devops: {
manifest_repository:
"azure_devops": {
"manifest_repository":
"https://dev.azure.com/bhnook/fabrikam/_git/materialized"
}
});
Expand Down
1 change: 0 additions & 1 deletion src/commands/deployment/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/camelcase */
// imports
import uuid from "uuid/v4";
import * as deploymenttable from "../../lib/azure/deploymenttable";
import {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/infra/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ export const generateConfigWithParentEqProjectPath = async (
writeTfvarsFile(spkTfvarsObject, parentDirectory, SPK_TFVARS);
await copyTfTemplate(templatePath, parentDirectory, true);
} else {
logger.warning(`Variables are not defined in the definition.yaml`);
logger.warn(`Variables are not defined in the definition.yaml`);
}
if (parentInfraConfig.backend) {
const backendTfvarsObject = generateTfvars(parentInfraConfig.backend);
checkTfvars(parentDirectory, BACKEND_TFVARS);
writeTfvarsFile(backendTfvarsObject, parentDirectory, BACKEND_TFVARS);
} else {
logger.warning(
logger.warn(
`A remote backend configuration is not defined in the definition.yaml`
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/commands/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ for a few questions
4. To create a sample application Repo
1. If Yes, a Azure Service Principal is needed. You have 2 options
1. have the command line tool to create it. Azure command line tool shall
be used
2. provide the Service Principal Id, Password and Tenant Id.
2. Subscription Id is automatically retrieved with the Service Principal
credential. In case, there are two or more subscriptions, you will be
prompt to select one of them.
be used. You will be prompted to select a subscription identifier.
2. Provide the Service Principal Id, Password, and Tenant Id. From this
information, the tool will retrieve the subscription identifier.

It can also run in a non interactive mode by providing a file that contains
answers to the above questions.
Expand All @@ -40,6 +38,8 @@ az_create_sp=<true to have command line to create service principal>
az_sp_id=<sevice principal Id need if az_create_app=true and az_create_sp=false>
az_sp_password=<sevice principal password need if az_create_app=true and az_create_sp=false>
az_sp_tenant=<sevice principal tenant Id need if az_create_app=true and az_create_sp=false>
az_subscription_id=<subscription id>
az_acr_name=<name of azure container registry>
```

`azdo_project_name` is optional and default value is `BedrockRocks`.
Expand All @@ -64,6 +64,8 @@ The followings shall be created
already exists.
5. A Git Repo, `quick-start-app`, it shall be deleted and recreated if is
already exists.
6. A Lifecycle pipeline.
7. A Build pipeline.

## Setup log

Expand Down
58 changes: 54 additions & 4 deletions src/commands/setup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import * as scaffold from "../lib/setup/scaffold";
import * as setupLog from "../lib/setup/setupLog";
import { deepClone } from "../lib/util";
import { ConfigYaml } from "../types";
import { createSPKConfig, execute, getErrorMessage } from "./setup";
import {
createAppRepoTasks,
createSPKConfig,
execute,
getErrorMessage
} from "./setup";
import * as setup from "./setup";

const mockRequestContext: RequestContext = {
Expand Down Expand Up @@ -83,11 +88,9 @@ const testExecuteFunc = async (
jest.spyOn(fsUtil, "createDirectory").mockReturnValueOnce();
jest.spyOn(scaffold, "hldRepo").mockResolvedValueOnce();
jest.spyOn(scaffold, "manifestRepo").mockResolvedValueOnce();
jest.spyOn(scaffold, "helmRepo").mockResolvedValueOnce();
jest.spyOn(scaffold, "appRepo").mockResolvedValueOnce();
jest
.spyOn(pipelineService, "createHLDtoManifestPipeline")
.mockReturnValueOnce(Promise.resolve());
.mockResolvedValueOnce();
jest.spyOn(resourceService, "create").mockResolvedValue(true);
jest.spyOn(azureContainerRegistryService, "create").mockResolvedValue(true);
jest.spyOn(setupLog, "create").mockReturnValueOnce();
Expand Down Expand Up @@ -309,3 +312,50 @@ describe("test getErrorMessage function", () => {
);
});
});

const testCreateAppRepoTasks = async (prApproved = true): Promise<void> => {
const mockRc: RequestContext = {
orgName: "org",
projectName: "project",
accessToken: "pat",
toCreateAppRepo: true,
servicePrincipalId: "fakeId",
servicePrincipalPassword: "fakePassword",
servicePrincipalTenantId: "tenant",
subscriptionId: "12344",
acrName: "acr",
workspace: "dummy"
};

jest.spyOn(resourceService, "create").mockResolvedValueOnce(true);
jest
.spyOn(azureContainerRegistryService, "create")
.mockResolvedValueOnce(true);
jest.spyOn(scaffold, "helmRepo").mockResolvedValueOnce();
jest.spyOn(scaffold, "appRepo").mockResolvedValueOnce();
jest
.spyOn(pipelineService, "createLifecyclePipeline")
.mockResolvedValueOnce();
jest
.spyOn(promptInstance, "promptForApprovingHLDPullRequest")
.mockResolvedValueOnce(prApproved);
if (prApproved) {
jest.spyOn(pipelineService, "createBuildPipeline").mockResolvedValueOnce();
}

const res = await createAppRepoTasks(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{} as any, // gitAPI
// eslint-disable-next-line @typescript-eslint/no-explicit-any
{} as any, // buildAPI
mockRc
);
expect(res).toBe(prApproved);
};

describe("test createAppRepoTasks function", () => {
it("positive test", async () => {
await testCreateAppRepoTasks();
await testCreateAppRepoTasks(false);
});
});
46 changes: 35 additions & 11 deletions src/commands/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable @typescript-eslint/camelcase */
import { IBuildApi } from "azure-devops-node-api/BuildApi";
import { IGitApi } from "azure-devops-node-api/GitApi";
import commander from "commander";
import fs from "fs";
import yaml from "js-yaml";
Expand All @@ -15,9 +17,17 @@ import {
} from "../lib/setup/constants";
import { createDirectory } from "../lib/setup/fsUtil";
import { getGitApi } from "../lib/setup/gitService";
import { createHLDtoManifestPipeline } from "../lib/setup/pipelineService";
import {
createBuildPipeline,
createHLDtoManifestPipeline,
createLifecyclePipeline
} from "../lib/setup/pipelineService";
import { createProjectIfNotExist } from "../lib/setup/projectService";
import { getAnswerFromFile, prompt } from "../lib/setup/prompt";
import {
getAnswerFromFile,
prompt,
promptForApprovingHLDPullRequest
} from "../lib/setup/prompt";
import {
appRepo,
helmRepo,
Expand All @@ -27,7 +37,6 @@ import {
import { create as createSetupLog } from "../lib/setup/setupLog";
import { logger } from "../logger";
import decorator from "./setup.decorator.json";
import { IGitApi } from "azure-devops-node-api/GitApi";

interface CommandOptions {
file: string | undefined;
Expand Down Expand Up @@ -87,8 +96,9 @@ export const getErrorMessage = (

export const createAppRepoTasks = async (
gitAPI: IGitApi,
buildAPI: IBuildApi,
rc: RequestContext
): Promise<void> => {
): Promise<boolean> => {
if (
rc.toCreateAppRepo &&
rc.servicePrincipalId &&
Expand Down Expand Up @@ -116,6 +126,18 @@ export const createAppRepoTasks = async (
);
await helmRepo(gitAPI, rc);
await appRepo(gitAPI, rc);
await createLifecyclePipeline(buildAPI, rc);
const approved = await promptForApprovingHLDPullRequest(rc);

if (approved) {
await createBuildPipeline(buildAPI, rc);
return true;
}

logger.warn("HLD Pull Request is not approved.");
return false;
} else {
return false;
}
};

Expand All @@ -134,21 +156,23 @@ export const execute = async (

try {
requestContext = opts.file ? getAnswerFromFile(opts.file) : await prompt();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const rc = requestContext!;
createDirectory(WORKSPACE, true);
createSPKConfig(requestContext);
createSPKConfig(rc);

const webAPI = await getWebApi();
const coreAPI = await webAPI.getCoreApi();
const gitAPI = await getGitApi(webAPI);
const buildAPI = await getBuildApi();

await createProjectIfNotExist(coreAPI, requestContext);
await hldRepo(gitAPI, requestContext);
await manifestRepo(gitAPI, requestContext);
await createHLDtoManifestPipeline(buildAPI, requestContext);
await createAppRepoTasks(gitAPI, requestContext);
await createProjectIfNotExist(coreAPI, rc);
await hldRepo(gitAPI, rc);
await manifestRepo(gitAPI, rc);
await createHLDtoManifestPipeline(buildAPI, rc);
await createAppRepoTasks(gitAPI, buildAPI, rc);

createSetupLog(requestContext);
createSetupLog(rc);
await exitFn(0);
} catch (err) {
const msg = getErrorMessage(requestContext, err);
Expand Down
41 changes: 38 additions & 3 deletions src/lib/azure/containerRegistryService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as restAuth from "@azure/ms-rest-nodeauth";
import {
create,
getContainerRegistries,
getContainerRegistry,
isExist
} from "./containerRegistryService";
import * as containerRegistryService from "./containerRegistryService";
Expand Down Expand Up @@ -109,7 +110,6 @@ describe("test container registries function", () => {
servicePrincipalPassword,
servicePrincipalTenantId,
subscriptionId,
RESOURCE_GROUP,
"test"
);
expect(res).toBeTruthy();
Expand All @@ -123,7 +123,6 @@ describe("test container registries function", () => {
servicePrincipalPassword,
servicePrincipalTenantId,
subscriptionId,
RESOURCE_GROUP,
"test"
);
expect(res).toBeFalsy();
Expand All @@ -143,7 +142,6 @@ describe("test container registries function", () => {
servicePrincipalPassword,
servicePrincipalTenantId,
subscriptionId,
RESOURCE_GROUP,
"test"
);
expect(res).toBeFalsy();
Expand Down Expand Up @@ -177,3 +175,40 @@ describe("test container registries function", () => {
expect(created).toBeTruthy();
});
});

describe("test getContainerRegistry function", () => {
it("match", async () => {
const entry = {
id:
"/subscriptions/dd831253-787f-4dc8-8eb0-ac9d052177d9/resourceGroups/quick-start-rg/providers/Microsoft.ContainerRegistry/registries/quickStartACR",
name: "quickStartACR",
resourceGroup: "quick-start-rg"
};
jest
.spyOn(containerRegistryService, "getContainerRegistries")
.mockResolvedValueOnce([entry]);
const reg = await getContainerRegistry(
servicePrincipalId,
servicePrincipalPassword,
servicePrincipalTenantId,
subscriptionId,
RESOURCE_GROUP,
"quickStartACR"
);
expect(reg).toStrictEqual(entry);
});
it("no matches", async () => {
jest
.spyOn(containerRegistryService, "getContainerRegistries")
.mockResolvedValueOnce([]);
const reg = await getContainerRegistry(
servicePrincipalId,
servicePrincipalPassword,
servicePrincipalTenantId,
subscriptionId,
RESOURCE_GROUP,
"quickStartACR"
);
expect(reg).toBeUndefined();
});
});
Loading