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

Commit

Permalink
Fix: Migrate Ring functions to new schema
Browse files Browse the repository at this point in the history
- `spk ring create` and `spk ring delete` were expecting the legacy bedrock.yaml
  schema where services were a map indexed by path -- it is now a list with a
  `path` property. Ring commands have been updated to reflect the new schema.
  • Loading branch information
evanlouie committed Apr 7, 2020
1 parent ce12b9f commit 6321208
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions docs/commands/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@
"command": "create <ring-name>",
"alias": "c",
"description": "Create a new ring for the current working directory project repository. This will affect all services within the project repository.",
"markdown": "## Description\n\nSPK command to create a ring into an initialized bedrock project.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring create stage` will result in a few changes:\n\n1. `stage` will be added into `bedrock.yaml` rings component:\n ```yaml\n rings:\n dev:\n isDefault: true\n qa:\n prod:\n stage:\n services:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n2. Each of the referenced services within `bedrock.yaml` will have their\n `build-update-hld.yaml` updated to include the new ring, `stage` in their\n branch triggers:\n\n ```yaml\n trigger:\n branches:\n include:\n - dev\n - qa\n - prod\n - stage <-- NEW -->\n variables:\n - group: fabrikam-vg\n …\n ```\n\n3. Commiting these changes will trigger the project's lifecycle pipeline, which\n will then scaffold out the newly created ring, along with the appropriate\n IngressRoutes in the linked HLD repository.\n"
"markdown": "## Description\n\nSPK command to create a ring into an initialized bedrock project.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring create stage` will result in a few changes:\n\n1. `stage` will be added into `bedrock.yaml` rings component:\n ```yaml\n rings:\n dev:\n isDefault: true\n qa:\n prod:\n stage:\n services:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n2. Each of the referenced services within `bedrock.yaml` will have their\n `build-update-hld.yaml` updated to include the new ring, `stage` in their\n branch triggers:\n\n ```yaml\n trigger:\n branches:\n include:\n - dev\n - qa\n - prod\n - stage <-- NEW -->\n variables:\n - group: fabrikam-vg\n …\n ```\n\n3. Commiting these changes will trigger the project's lifecycle pipeline, which\n will then scaffold out the newly created ring, along with the appropriate\n IngressRoutes in the linked HLD repository.\n"
},
"ring delete": {
"command": "delete <ring-name>",
"alias": "d",
"description": "Delete a ring from the current working directory project repository. This will affect all services within the project repository. The default ring cannot be deleted.",
"markdown": "## Description\n\nSPK command to remove a ring from an initialized bedrock project.\n\n_Note:_ A default ring cannot be removed. First set another ring as the default\nvia `spk ring set-default` before deleting.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring delete prod` will result in a few changes:\n\n1. `prod` will be removed from `bedrock.yaml`:\n ```yaml\n rings:\n dev:\n isDefault: true\n qa:\n services:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n2. Each of the referenced services within `bedrock.yaml` will have their\n `build-update-hld.yaml` updated to remove the ring, `prod` in their branch\n triggers:\n\n ```yaml\n trigger:\n branches:\n include:\n - dev\n - qa\n # - prod <-- THIS WILL BE DELETED! -->\n variables:\n - group: fabrikam-vg\n …\n ```\n\n3. Commiting these changes will trigger the project's lifecycle pipeline, which\n will then remove the ring from linked services in this project,\n [pending this epic](https://github.com/microsoft/bedrock/issues/858).\n"
"markdown": "## Description\n\nSPK command to remove a ring from an initialized bedrock project.\n\n_Note:_ A default ring cannot be removed. First set another ring as the default\nvia `spk ring set-default` before deleting.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring delete prod` will result in a few changes:\n\n1. `prod` will be removed from `bedrock.yaml`:\n ```yaml\n rings:\n dev:\n isDefault: true\n qa:\n services:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n2. Each of the referenced services within `bedrock.yaml` will have their\n `build-update-hld.yaml` updated to remove the ring, `prod` in their branch\n triggers:\n\n ```yaml\n trigger:\n branches:\n include:\n - dev\n - qa\n # - prod <-- THIS WILL BE DELETED! -->\n variables:\n - group: fabrikam-vg\n …\n ```\n\n3. Commiting these changes will trigger the project's lifecycle pipeline, which\n will then remove the ring from linked services in this project,\n [pending this epic](https://github.com/microsoft/bedrock/issues/858).\n"
},
"ring set-default": {
"command": "set-default <ring-name>",
"alias": "s",
"description": "Set a ring as the default for the current working directory project repository. This will affect all services within the project repository.",
"markdown": "## Description\n\nSPK command to set a ring as the default for an initialized bedrock project.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring set-default prod` will result in:\n\n1. `prod` will be set as the default in `bedrock.yaml`:\n\n ```yaml\n rings:\n dev:\n qa:\n prod:\n isDefault: true\n services:\n ./:\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n\n2. Commiting these changes will trigger the project's lifecycle pipeline, which\n may update the default \"no-ring\" IngressRoutes to route to the `prod` service\n in the linked HLD repository,\n [pending the work in this issue](https://github.com/microsoft/bedrock/issues/1084).\n"
"markdown": "## Description\n\nSPK command to set a ring as the default for an initialized bedrock project.\n\n## Example\n\nFor a bedrock.yaml file that looks like this:\n\n```yaml\nrings:\n dev:\n isDefault: true\n qa:\n prod:\nservices:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\nvariableGroups:\n - fabrikam-vg\n```\n\nrunning `spk ring set-default prod` will result in:\n\n1. `prod` will be set as the default in `bedrock.yaml`:\n\n ```yaml\n rings:\n dev:\n qa:\n prod:\n isDefault: true\n services:\n - path: ./\n displayName: \"fabrikam\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/fabrikam/frontend/_git/charts\"\n path: frontend\n k8sBackend: \"fabrikam-k8s-svc\"\n k8sBackendPort: 80\n middlewares: []\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n variableGroups:\n - fabrikam-vg\n ```\n\n2. Commiting these changes will trigger the project's lifecycle pipeline, which\n may update the default \"no-ring\" IngressRoutes to route to the `prod` service\n in the linked HLD repository,\n [pending the work in this issue](https://github.com/microsoft/bedrock/issues/1084).\n"
},
"service create-revision": {
"command": "create-revision",
Expand Down
4 changes: 2 additions & 2 deletions src/commands/ring/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export const execute = async (
const newRings = Object.entries(bedrockFile.rings).map(([ring]) => ring);
logger.info(`Updated project rings: ${newRings}`);

const servicePathDirectories = Object.entries(bedrockFile.services).map(
([serviceRelativeDir]) => serviceRelativeDir
const servicePathDirectories = bedrockFile.services.map(
(service) => service.path
);

servicePathDirectories.forEach((s) => {
Expand Down
6 changes: 3 additions & 3 deletions src/commands/ring/delete.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ describe("test execute function and logic", () => {

// updateTriggerBranchesForServiceBuildAndUpdatePipeline should be called
// once per service
const numberOfServices = Object.keys(bedrockConfig.services).length;
const numberOfServices = bedrockConfig.services.length;
const updatedRingList = Object.keys(
bedrock.removeRing(bedrockConfig, ringToDelete).rings
);
expect(
fileUtils.updateTriggerBranchesForServiceBuildAndUpdatePipeline
).toBeCalledTimes(numberOfServices);
for (const serviceName of Object.keys(bedrockConfig.services)) {
for (const { path: servicePath } of bedrockConfig.services) {
expect(
fileUtils.updateTriggerBranchesForServiceBuildAndUpdatePipeline
).toBeCalledWith(updatedRingList, serviceName);
).toBeCalledWith(updatedRingList, servicePath);
}
expect(exitFn.mock.calls).toEqual([[0]]);
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/ring/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const execute = async (

// Delete ring from all linked service build pipelines' branch triggers
const ringBranches = Object.keys(bedrockWithoutRing.rings);
for (const servicePath of Object.keys(bedrockConfig.services)) {
for (const { path: servicePath } of bedrockConfig.services) {
updateTriggerBranchesForServiceBuildAndUpdatePipeline(
ringBranches,
servicePath
Expand Down

0 comments on commit 6321208

Please sign in to comment.