Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit c624b62

Browse files
authored
[FEATURE] Completing spk setup command (#464)
* create storage account * stage * prompt merging second PR * Update setup.md * finishing touch * update config.yaml with repo info * Update jest.config.js * added storage tests * minor fixes * add docker image in config,yaml * final touch * fix unit test * Update setup.test.ts * Update validator.test.ts * Update pipeline.test.ts
1 parent 44c9970 commit c624b62

26 files changed

+942
-331
lines changed

Diff for: docs/commands/data.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"description": "Path to the file that contains answers to the questions."
2727
}
2828
],
29-
"markdown": "## Description\n\nThis command assists in creating resources in Azure DevOps so that you can get\nstarted with using Bedrock. It creates\n\n1. An Azure DevOps project.\n\nBy Default, it runs in an interactive mode where you are prompted for answers\nfor a few questions\n\n1. Azure DevOps Organization Name\n2. Azure DevOps Project Name, the project to be created.\n3. Azure DevOps Personal Access Token. The token needs to have these permissions\n 1. Read and write projects.\n 2. Read and write codes.\n4. To create a sample application Repo\n 1. If Yes, a Azure Service Principal is needed. You have 2 options\n 1. have the command line tool to create it. Azure command line tool shall\n be used. You will be prompted to select a subscription identifier.\n 2. Provide the Service Principal Id, Password, and Tenant Id. From this\n information, the tool will retrieve the subscription identifier.\n\nIt can also run in a non interactive mode by providing a file that contains\nanswers to the above questions.\n\n```\nspk setup --file <file-name>\n```\n\nContent of this file is as follow\n\n```\nazdo_org_name=<Azure DevOps Organization Name>\nazdo_project_name=<Azure DevOps Project Name>\nazdo_pat=<Azure DevOps Personal Access Token>\naz_create_app=<true to create sample service app>\naz_create_sp=<true to have command line to create service principal>\naz_sp_id=<sevice principal Id need if az_create_app=true and az_create_sp=false>\naz_sp_password=<sevice principal password need if az_create_app=true and az_create_sp=false>\naz_sp_tenant=<sevice principal tenant Id need if az_create_app=true and az_create_sp=false>\naz_subscription_id=<subscription id>\naz_acr_name=<name of azure container registry>\n```\n\n`azdo_project_name` is optional and default value is `BedrockRocks`.\n\nThe followings shall be created\n\n1. A working directory, `quick-start-env`\n2. Project shall not be created if it already exists.\n3. A Git Repo, `quick-start-hld`, it shall be deleted and recreated if it\n already exists.\n 1. And initial commit shall be made to this repo\n4. A Git Repo, `quick-start-manifest`, it shall be deleted and recreated if it\n already exists.\n 1. And initial commit shall be made to this repo\n5. A High Level Definition (HLD) to Manifest pipeline.\n6. If user chose to create sample app repo\n 1. A Service Principal (if requested)\n 2. A resource group, `quick-start-rg` if it does not exist.\n 3. A Azure Container Registry, `quickStartACR` in resource group,\n `quick-start-rg` if it does not exist.\n 4. A Git Repo, `quick-start-helm`, it shall be deleted and recreated if is\n already exists.\n 5. A Git Repo, `quick-start-app`, it shall be deleted and recreated if is\n already exists.\n 6. A Lifecycle pipeline.\n 7. A Build pipeline.\n\n## Setup log\n\nA `setup.log` file is created after running this command. This file contains\ninformation about what are created and the execution status (completed or\nincomplete). This file will not be created if input validation failed.\n\n## Note\n\nTo remove the service principal that it is created by the tool, you can do the\nfollowings:\n\n1. Get the identifier from `setup.log` (look for `az_sp_id`)\n2. run on terminal `az ad sp delete --id <the sp id>`\n"
29+
"markdown": "## Description\n\nThis command assists in creating resources in Azure DevOps so that you can get\nstarted with using Bedrock. It creates\n\n1. An Azure DevOps project.\n\nBy Default, it runs in an interactive mode where you are prompted for answers\nfor a few questions\n\n1. Azure DevOps Organization Name\n2. Azure DevOps Project Name, the project to be created.\n3. Azure DevOps Personal Access Token. The token needs to have these permissions\n 1. Read and write projects.\n 2. Read and write codes.\n4. To create a sample application Repo\n 1. If Yes, a Azure Service Principal is needed. You have 2 options\n 1. have the command line tool to create it. Azure command line tool shall\n be used. You will be prompted to select a subscription identifier.\n 2. Provide the Service Principal Id, Password, and Tenant Id. From this\n information, the tool will retrieve the subscription identifier.\n\nIt can also run in a non interactive mode by providing a file that contains\nanswers to the above questions.\n\nAfter this command is successfully executed, you can launch the introspection\ndashboard to view the status of pipelines.\n\n```\nspk setup --file <file-name>\n```\n\nContent of this file is as follow\n\n```\nazdo_org_name=<Azure DevOps Organization Name>\nazdo_project_name=<Azure DevOps Project Name>\nazdo_pat=<Azure DevOps Personal Access Token>\naz_create_app=<true to create sample service app>\naz_create_sp=<true to have command line to create service principal>\naz_sp_id=<sevice principal Id need if az_create_app=true and az_create_sp=false>\naz_sp_password=<sevice principal password need if az_create_app=true and az_create_sp=false>\naz_sp_tenant=<sevice principal tenant Id need if az_create_app=true and az_create_sp=false>\naz_subscription_id=<subscription id>\naz_acr_name=<name of azure container registry>\n```\n\n`azdo_project_name` is optional and default value is `BedrockRocks`.\n\nThe followings shall be created\n\n1. A working directory, `quick-start-env`\n2. Project shall not be created if it already exists.\n3. A Git Repo, `quick-start-hld`, it shall be deleted and recreated if it\n already exists.\n 1. And initial commit shall be made to this repo\n4. A Git Repo, `quick-start-manifest`, it shall be deleted and recreated if it\n already exists.\n 1. And initial commit shall be made to this repo\n5. A High Level Definition (HLD) to Manifest pipeline.\n6. If user chose to create sample app repo\n 1. A Service Principal (if requested)\n 1. A resource group, `quick-start-rg` if it does not exist.\n 1. A storage account if it does not exist. Storage Account name has to be\n unqiue acess Azure.\n 1. A storage table in the storage account.\n 1. A Azure Container Registry, `quickStartACR` in resource group,\n `quick-start-rg` if it does not exist.\n 1. A Git Repo, `quick-start-helm`, it shall be deleted and recreated if is\n already exists.\n 1. A Git Repo, `quick-start-app`, it shall be deleted and recreated if is\n already exists.\n 1. A Lifecycle pipeline.\n 1. A Build pipeline.\n\n## Setup log\n\nA `setup.log` file is created after running this command. This file contains\ninformation about what are created and the execution status (completed or\nincomplete). This file will not be created if input validation failed.\n\n## Note\n\nTo remove the service principal that it is created by the tool, you can do the\nfollowings:\n\n1. Get the identifier from `setup.log` (look for `az_sp_id`)\n2. run on terminal `az ad sp delete --id <the sp id>`\n"
3030
},
3131
"deployment create": {
3232
"command": "create",

Diff for: guides/contributing.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const Sheep = ({ says, legs }: IAnimal) => {
213213
says: () => "bahhh",
214214
legs: 4,
215215
says,
216-
legs
216+
legs,
217217
};
218218
};
219219
```
@@ -305,7 +305,7 @@ function foo(bar: number): string {
305305
}
306306

307307
// Don't do
308-
const foo = function(bar: number): string {
308+
const foo = function (bar: number): string {
309309
return bar.toString();
310310
};
311311

@@ -339,10 +339,10 @@ const promiseBasedReadFile = promisify(readFile);
339339

340340
// Full promise based
341341
promiseBasedReadFile("/etc/passwd")
342-
.then(data => {
342+
.then((data) => {
343343
console.log(data);
344344
})
345-
.catch(err => {
345+
.catch((err) => {
346346
console.error(err);
347347
return Promise.reject(err);
348348
});

Diff for: jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module.exports = {
22
preset: "ts-jest",
3-
testEnvironment: "node"
3+
testEnvironment: "node",
44
};

Diff for: src/commands/hld/pipeline.test.ts

+23-39
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ afterAll(() => {
5858
disableVerboseLogging();
5959
});
6060

61-
jest.spyOn(azdo, "validateRepository").mockReturnValue(Promise.resolve());
61+
jest.spyOn(azdo, "validateRepository").mockResolvedValue();
6262

6363
describe("test emptyStringIfUndefined function", () => {
6464
it("pass in undefined", () => {
@@ -73,6 +73,7 @@ describe("test emptyStringIfUndefined function", () => {
7373
});
7474

7575
const orgNameTest = (hasVal: boolean): void => {
76+
jest.spyOn(config, "Config").mockReturnValueOnce({});
7677
const data = {
7778
buildScriptUrl: "",
7879
devopsProject: "project",
@@ -97,6 +98,7 @@ const orgNameTest = (hasVal: boolean): void => {
9798
};
9899

99100
const projectNameTest = (hasVal: boolean): void => {
101+
jest.spyOn(config, "Config").mockReturnValueOnce({});
100102
const data = {
101103
buildScriptUrl: "",
102104
devopsProject: hasVal ? "project\\abc" : "",
@@ -122,11 +124,7 @@ const projectNameTest = (hasVal: boolean): void => {
122124

123125
describe("test populateValues function", () => {
124126
it("with all values in command opts", () => {
125-
jest.spyOn(config, "Config").mockImplementationOnce(
126-
(): ConfigYaml => {
127-
return MOCKED_CONFIG;
128-
}
129-
);
127+
jest.spyOn(config, "Config").mockReturnValueOnce(MOCKED_CONFIG);
130128
const mockedObject = getMockObject();
131129
expect(populateValues(mockedObject)).toEqual(mockedObject);
132130
});
@@ -195,15 +193,11 @@ describe("test populateValues function", () => {
195193

196194
describe("test execute function", () => {
197195
it("positive test", async () => {
198-
jest.spyOn(config, "Config").mockImplementationOnce(
199-
(): ConfigYaml => {
200-
return MOCKED_CONFIG;
201-
}
202-
);
196+
jest.spyOn(config, "Config").mockReturnValueOnce(MOCKED_CONFIG);
203197
const exitFn = jest.fn();
204198
jest
205199
.spyOn(pipeline, "installHldToManifestPipeline")
206-
.mockReturnValueOnce(Promise.resolve());
200+
.mockResolvedValueOnce();
207201

208202
await execute(MOCKED_VALUES, exitFn);
209203
expect(exitFn).toBeCalledTimes(1);
@@ -243,43 +237,33 @@ describe("required pipeline variables", () => {
243237

244238
describe("create hld to manifest pipeline test", () => {
245239
it("should create a pipeline", async () => {
246-
(createPipelineForDefinition as jest.Mock).mockReturnValue({ id: 10 });
240+
(createPipelineForDefinition as jest.Mock).mockReturnValueOnce({ id: 10 });
247241
await installHldToManifestPipeline(getMockObject());
248242
});
249243

250244
it("should fail if the build client cant be instantiated", async () => {
251-
(getBuildApiClient as jest.Mock).mockReturnValue(Promise.reject("Error"));
252-
try {
253-
await installHldToManifestPipeline(getMockObject());
254-
expect(true).toBe(false);
255-
} catch (err) {
256-
expect(err).toBeDefined();
257-
}
245+
(getBuildApiClient as jest.Mock).mockRejectedValueOnce(Error("Error"));
246+
await expect(installHldToManifestPipeline(getMockObject())).rejects.toThrow(
247+
"Error"
248+
);
258249
});
259250

260251
it("should fail if the pipeline definition cannot be created", async () => {
261-
(getBuildApiClient as jest.Mock).mockReturnValue({});
262-
(createPipelineForDefinition as jest.Mock).mockReturnValue(
263-
Promise.reject("Error")
252+
(getBuildApiClient as jest.Mock).mockReturnValueOnce({});
253+
(createPipelineForDefinition as jest.Mock).mockRejectedValueOnce(
254+
Error("Error")
255+
);
256+
await expect(installHldToManifestPipeline(getMockObject())).rejects.toThrow(
257+
"Error"
264258
);
265-
try {
266-
await installHldToManifestPipeline(getMockObject());
267-
expect(true).toBe(false);
268-
} catch (err) {
269-
expect(err).toBeDefined();
270-
}
271259
});
272260

273261
it("should fail if a build cannot be queued on the pipeline", async () => {
274-
(getBuildApiClient as jest.Mock).mockReturnValue({});
275-
(createPipelineForDefinition as jest.Mock).mockReturnValue({ id: 10 });
276-
(queueBuild as jest.Mock).mockReturnValue(Promise.reject("Error"));
277-
278-
try {
279-
await installHldToManifestPipeline(getMockObject());
280-
expect(true).toBe(false);
281-
} catch (err) {
282-
expect(err).toBeDefined();
283-
}
262+
(getBuildApiClient as jest.Mock).mockReturnValueOnce({});
263+
(createPipelineForDefinition as jest.Mock).mockReturnValueOnce({ id: 10 });
264+
(queueBuild as jest.Mock).mockRejectedValueOnce(Error("Error"));
265+
await expect(installHldToManifestPipeline(getMockObject())).rejects.toThrow(
266+
"Error"
267+
);
284268
});
285269
});

Diff for: src/commands/setup.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ for a few questions
2323
It can also run in a non interactive mode by providing a file that contains
2424
answers to the above questions.
2525

26+
After this command is successfully executed, you can launch the introspection
27+
dashboard to view the status of pipelines.
28+
2629
```
2730
spk setup --file <file-name>
2831
```
@@ -57,15 +60,18 @@ The followings shall be created
5760
5. A High Level Definition (HLD) to Manifest pipeline.
5861
6. If user chose to create sample app repo
5962
1. A Service Principal (if requested)
60-
2. A resource group, `quick-start-rg` if it does not exist.
61-
3. A Azure Container Registry, `quickStartACR` in resource group,
63+
1. A resource group, `quick-start-rg` if it does not exist.
64+
1. A storage account if it does not exist. Storage Account name has to be
65+
unqiue acess Azure.
66+
1. A storage table in the storage account.
67+
1. A Azure Container Registry, `quickStartACR` in resource group,
6268
`quick-start-rg` if it does not exist.
63-
4. A Git Repo, `quick-start-helm`, it shall be deleted and recreated if is
69+
1. A Git Repo, `quick-start-helm`, it shall be deleted and recreated if is
6470
already exists.
65-
5. A Git Repo, `quick-start-app`, it shall be deleted and recreated if is
71+
1. A Git Repo, `quick-start-app`, it shall be deleted and recreated if is
6672
already exists.
67-
6. A Lifecycle pipeline.
68-
7. A Build pipeline.
73+
1. A Lifecycle pipeline.
74+
1. A Build pipeline.
6975

7076
## Setup log
7177

0 commit comments

Comments
 (0)