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

Commit ce12b9f

Browse files
committed
bedrock.yaml refactor & service create spec update
- Updated bedrock.yaml `services` to contain a list of services instead of a map indexed by path. - Auto-migration of bedrock.yaml is hooked into `read()` function of the `bedrockYaml.ts` file. - `read()` is now the only function used for loading the bedrock.yaml file; `Bedrock()` in `config.ts` is now noted as deprecated and now calls `read()` under the hood. - `path` property for a service now tracks the path to the service. - Documentation references all updated. - `spk service create <service-name>` now follows the spec `spk service create <service-name> <service-path>` - Documentation references all updated. - Integration tests updated.
1 parent ea3f483 commit ce12b9f

39 files changed

+774
-371
lines changed

docs/commands/data.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
"alias": "r",
335335
"description": "Reconcile a HLD with the services tracked in bedrock.yaml.",
336336
"options": [],
337-
"markdown": "## Description\n\nThe reconcile feature scaffolds a HLD with the services in the `bedrock.yaml`\nfile at the root level of the application repository. Recall that in a\nmono-repo, `spk service create` will add an entry into the `bedrock.yaml`\ncorresponding to all tracked services. When the service has been merged into\n`master` of the application repository, a pipeline (see `hld-lifecycle.yaml`,\ncreated by `spk project init`) runs `spk hld reconcile` to add any _new_\nservices tracked in `bedrock.yaml` to the HLD.\n\nThis command is _intended_ to be run in a pipeline (see the generated\n`hld-lifecycle.yaml` created from `spk project init`), but can be run by the\nuser in a CLI for verification.\n\nFor a `bedrock.yaml` file that contained within the\n`https://dev.azure.com/foo/bar/_git` repository, that has the following\nstructure:\n\n```yaml\nrings:\n master:\n isDefault: true\nservices:\n ./services/fabrikam:\n displayName: \"fabrikam\"\n k8sBackendPort: 8001\n k8sBackend: \"fabrikam-k8s-svc\"\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/foo/bar/_git\"\n path: stable/fabrikam-application\n middlewares:\n - \"\"\nvariableGroups:\n - fabrikam-vg\n```\n\nA HLD is produced that resembles the following:\n\n```\n├── component.yaml\n└── fabrikam\n ├── access.yaml\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── fabrikam\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── master\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── static\n ├── ingress-route.yaml\n └── middlewares.yaml\n```\n\nWith the `ingress-route.yaml` representing a\n[Traefik2 Ingress Route](https://docs.traefik.io/routing/providers/kubernetes-crd/#kind-ingressroute)\nbacked by a Kubernetes Service, and the `middlewares.yaml` representing a\n[Traefik2 Middleware](https://docs.traefik.io/routing/providers/kubernetes-crd/#kind-middleware)\nthat strips path prefixes.\n\nFor the `bedrock.yaml` shown above, the `ingress-route.yaml` produced is:\n\n```yaml\napiVersion: traefik.containo.us/v1alpha1\nkind: IngressRoute\nmetadata:\n name: fabrikam-master\nspec:\n routes:\n - kind: Rule\n match: \"PathPrefix(`/v1/fabrikam-service`) && Headers(`Ring`, `master`)\"\n middlewares:\n - name: fabrikam-master\n services:\n - name: fabrikam-k8s-svc-master\n port: 8001\n```\n\nAnd the `middlewares.yaml` produced is:\n\n```yaml\napiVersion: traefik.containo.us/v1alpha1\nkind: Middleware\nmetadata:\n name: fabrikam-master\nspec:\n stripPrefix:\n forceSlash: false\n prefixes:\n - /v1/fabrikam-service\n```\n\nNote that there exists a third generated file, `access.yaml`. For the above\n`bedrock.yaml`, `access.yaml` contains a single line, which represents a\n[Fabrikate access.yaml definition](https://github.com/microsoft/fabrikate/blob/master/docs/auth.md#accessyaml),\nallowing Fabrikate to pull Helm Charts that are contained within the same\napplication repository:\n\n```yaml\n\"https://dev.azure.com/foo/bar/_git\": ACCESS_TOKEN_SECRET\n```\n\nWhen `fabrikate` is invoked in the HLD to Manifest pipeline, it will utilize the\n`ACCESS_TOKEN_SECRET` environment variable injected at pipeline run-time as a\nPersonal Access Token to pull any referenced helm charts from the application\nrepository.\n"
337+
"markdown": "## Description\n\nThe reconcile feature scaffolds a HLD with the services in the `bedrock.yaml`\nfile at the root level of the application repository. Recall that in a\nmono-repo, `spk service create` will add an entry into the `bedrock.yaml`\ncorresponding to all tracked services. When the service has been merged into\n`master` of the application repository, a pipeline (see `hld-lifecycle.yaml`,\ncreated by `spk project init`) runs `spk hld reconcile` to add any _new_\nservices tracked in `bedrock.yaml` to the HLD.\n\nThis command is _intended_ to be run in a pipeline (see the generated\n`hld-lifecycle.yaml` created from `spk project init`), but can be run by the\nuser in a CLI for verification.\n\nFor a `bedrock.yaml` file that contained within the\n`https://dev.azure.com/foo/bar/_git` repository, that has the following\nstructure:\n\n```yaml\nrings:\n master:\n isDefault: true\nservices:\n - path: ./services/fabrikam\n displayName: \"fabrikam\"\n k8sBackendPort: 8001\n k8sBackend: \"fabrikam-k8s-svc\"\n pathPrefix: \"fabrikam-service\"\n pathPrefixMajorVersion: \"v1\"\n helm:\n chart:\n branch: master\n git: \"https://dev.azure.com/foo/bar/_git\"\n path: stable/fabrikam-application\n middlewares:\n - \"\"\nvariableGroups:\n - fabrikam-vg\n```\n\nA HLD is produced that resembles the following:\n\n```\n├── component.yaml\n└── fabrikam\n ├── access.yaml\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── fabrikam\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── master\n ├── component.yaml\n ├── config\n │ └── common.yaml\n └── static\n ├── ingress-route.yaml\n └── middlewares.yaml\n```\n\nWith the `ingress-route.yaml` representing a\n[Traefik2 Ingress Route](https://docs.traefik.io/routing/providers/kubernetes-crd/#kind-ingressroute)\nbacked by a Kubernetes Service, and the `middlewares.yaml` representing a\n[Traefik2 Middleware](https://docs.traefik.io/routing/providers/kubernetes-crd/#kind-middleware)\nthat strips path prefixes.\n\nFor the `bedrock.yaml` shown above, the `ingress-route.yaml` produced is:\n\n```yaml\napiVersion: traefik.containo.us/v1alpha1\nkind: IngressRoute\nmetadata:\n name: fabrikam-master\nspec:\n routes:\n - kind: Rule\n match: \"PathPrefix(`/v1/fabrikam-service`) && Headers(`Ring`, `master`)\"\n middlewares:\n - name: fabrikam-master\n services:\n - name: fabrikam-k8s-svc-master\n port: 8001\n```\n\nAnd the `middlewares.yaml` produced is:\n\n```yaml\napiVersion: traefik.containo.us/v1alpha1\nkind: Middleware\nmetadata:\n name: fabrikam-master\nspec:\n stripPrefix:\n forceSlash: false\n prefixes:\n - /v1/fabrikam-service\n```\n\nNote that there exists a third generated file, `access.yaml`. For the above\n`bedrock.yaml`, `access.yaml` contains a single line, which represents a\n[Fabrikate access.yaml definition](https://github.com/microsoft/fabrikate/blob/master/docs/auth.md#accessyaml),\nallowing Fabrikate to pull Helm Charts that are contained within the same\napplication repository:\n\n```yaml\n\"https://dev.azure.com/foo/bar/_git\": ACCESS_TOKEN_SECRET\n```\n\nWhen `fabrikate` is invoked in the HLD to Manifest pipeline, it will utilize the\n`ACCESS_TOKEN_SECRET` environment variable injected at pipeline run-time as a\nPersonal Access Token to pull any referenced helm charts from the application\nrepository.\n"
338338
},
339339
"infra generate": {
340340
"command": "generate",
@@ -556,7 +556,7 @@
556556
"markdown": "## Description\n\nGenerate a PR in Azure DevOps against default ring branches\n"
557557
},
558558
"service create": {
559-
"command": "create <service-name>",
559+
"command": "create <service-name> <service-path>",
560560
"alias": "c",
561561
"description": "Add a new service into this initialized spk project repository",
562562
"options": [
@@ -595,11 +595,6 @@
595595
"description": "The directory containing the mono-repo packages.",
596596
"defaultValue": ""
597597
},
598-
{
599-
"arg": "-n, --display-name <display-name>",
600-
"description": "Display name of the service.",
601-
"defaultValue": ""
602-
},
603598
{
604599
"arg": "-m, --maintainer-name <maintainer-name>",
605600
"description": "The name of the primary maintainer for this service.",
@@ -641,7 +636,7 @@
641636
"defaultValue": ""
642637
}
643638
],
644-
"markdown": "## Description\n\nAdd a new service into this initialized spk project repository.\n\n## Example\n\n```bash\nspk service create . \\\n --display-name $app_name \\\n --helm-config-path $path_to_chart_in_repo \\\n --helm-config-git $helm_repo_url \\ # Needs to start with https and not contain user name\n --helm-config-branch master \\\n --helm-chart-access-token-variable $ENV_VAR_NAME\n```\n\n## Note\n\n- `--helm-chart-*` and `--helm-config-*` settings are mutually-exclusive. **You\n may only use one.**\n - If the git repository referenced in `--helm-config-git` is a private\n repository, you can specify an environment variable in your\n HLD-to-Materialized pipeline containing your a PAT to authenticate with via\n the `--helm-chart-access-token-variable` option.\n- `--middlewares`, `--k8s-backend-port`, `--path-prefix`,\n `--path-prefix-major-version`, and `--k8s-backend` are all used to configure\n the generated Traefik2 IngressRoutes. i.e.\n\n ```sh\n spk service create my-example-documents-service \\\n --middlewares middleware \\\n --k8s-backend-port 3001 \\\n --k8s-backend docs-service \\\n --path-prefix documents \\\n --path-prefix-major-version v2\n ```\n\n will result in an IngressRoute that looks like:\n\n ```yaml\n apiVersion: traefik.containo.us/v1alpha1\n kind: IngressRoute\n metadata:\n name: my-example-documents-service-master\n spec:\n routes:\n - kind: Rule\n match: \"PathPrefix(`/v2/documents`) && Headers(`Ring`, `master`)\"\n middlewares:\n - name: my-example-documents-service-master\n - name: middlewareA\n services:\n - name: docs-service\n port: 3001\n ```\n"
639+
"markdown": "## Description\n\nAdd a new service into this initialized spk project repository.\n\n## Example\n\n```bash\nspk service create my-service . \\\n --display-name $app_name \\\n --helm-config-path $path_to_chart_in_repo \\\n --helm-config-git $helm_repo_url \\ # Needs to start with https and not contain user name\n --helm-config-branch master \\\n --helm-chart-access-token-variable $ENV_VAR_NAME\n```\n\n## Note\n\n- `--helm-chart-*` and `--helm-config-*` settings are mutually-exclusive. **You\n may only use one.**\n - If the git repository referenced in `--helm-config-git` is a private\n repository, you can specify an environment variable in your\n HLD-to-Materialized pipeline containing your a PAT to authenticate with via\n the `--helm-chart-access-token-variable` option.\n- `--middlewares`, `--k8s-backend-port`, `--path-prefix`,\n `--path-prefix-major-version`, and `--k8s-backend` are all used to configure\n the generated Traefik2 IngressRoutes. i.e.\n\n ```sh\n spk service create my-example-documents-service path/to/my/service \\\n --middlewares middleware \\\n --k8s-backend-port 3001 \\\n --k8s-backend docs-service \\\n --path-prefix documents \\\n --path-prefix-major-version v2\n ```\n\n will result in an IngressRoute that looks like:\n\n ```yaml\n apiVersion: traefik.containo.us/v1alpha1\n kind: IngressRoute\n metadata:\n name: my-example-documents-service-master\n spec:\n routes:\n - kind: Rule\n match: \"PathPrefix(`/v2/documents`) && Headers(`Ring`, `master`)\"\n middlewares:\n - name: my-example-documents-service-master\n - name: middlewareA\n services:\n - name: docs-service\n port: 3001\n ```\n"
645640
},
646641
"service install-build-pipeline": {
647642
"command": "install-build-pipeline <service-name>",

guides/auth-private-helm-repos.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ can make it aware of it via the `--helm-config-access-token-variable` flag in
3636
the `spk service create` command.
3737

3838
```sh
39-
spk service create my-service \
39+
spk service create my-service ./path/to/service \
4040
--helm-config-git https://dev.azure.com/my-org/my-project/_git/my-repo \
4141
--helm-config-branch master \
4242
--helm-config-path my-service-helm-chart \
@@ -57,8 +57,8 @@ rings:
5757
master:
5858
isDefault: true
5959
services:
60-
./my-service:
61-
displayName: ""
60+
- path: ./path/to/service
61+
displayName: my-service
6262
helm:
6363
chart:
6464
accessTokenVariable: MY_ENV_VAR # Note: this is where the environment variable gets tracked

guides/bedrock-end-to-end-dx.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,20 @@ The core `discovery-service` microservice already exists, so he grandfathers it
7272
into the Bedrock workflow with:
7373

7474
```bash
75-
$ spk service create discovery-service -d services
75+
$ spk service create discovery-service ./path/to/discovery/service -d services
7676
```
7777

7878
This updates the bedrock.yaml file to include this service:
7979

8080
```bash
8181
$ cat bedrock.yaml
8282
services:
83-
./services/discovery-service:
84-
helm:
85-
chart:
86-
branch: ''
87-
git: ''
88-
path: ''
89-
83+
- path: ./services/discovery-service
84+
helm:
85+
chart:
86+
branch: ''
87+
git: ''
88+
path: ''
9089
```
9190

9291
and adds a `build-update-hld.yaml` file in `services/discovery-service` to build

guides/building-helm-charts-for-spk.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ rings:
3838
dev:
3939
isDefault: true
4040
services:
41-
./:
42-
displayName: "fabrikam"
41+
- displayName: "fabrikam"
42+
path: ./
4343
helm:
4444
chart:
4545
branch: master
@@ -58,7 +58,7 @@ The above service `fabrikam` was added to `bedrock.yaml` by invoking
5858
`spk service create` with the requisite parameters ie:
5959

6060
```sh
61-
spk service create . \
61+
spk service create fabrikam . \
6262
--display-name fabrikam \
6363
--helm-config-git https://dev.azure.com/fabrikam/frontend/_git/charts \
6464
--helm-config-path frontend \
@@ -152,9 +152,9 @@ rings:
152152
dev:
153153
isDefault: true
154154
services:
155-
./
156-
...
155+
- path: ./
157156
k8sBackend: 'fabrikam-k8s-svc'
157+
...
158158
```
159159

160160
The `serviceName` is generated from a combination of the `k8sBackend`,
@@ -179,7 +179,7 @@ rings:
179179
dev:
180180
isDefault: true
181181
services:
182-
./
182+
- path: ./
183183
...
184184
displayName: 'fabrikam'
185185
k8sBackend: 'fabrikam-k8s-svc'

guides/manual-guide-to-rings.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ rings:
3535
qa:
3636
prod:
3737
services:
38-
./:
38+
- path: ./
3939
displayName: "fabrikam"
4040
helm:
4141
chart:
@@ -87,7 +87,7 @@ rings:
8787
prod:
8888
test-new-homepage: <-- NEW -->
8989
services:
90-
./:
90+
- path: ./
9191
displayName: "fabrikam"
9292
helm:
9393
chart:

guides/project-service-management-guide.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ application repositories
235235
flag parameters can be used if `spk` was not intialized)
236236
```
237237
SERVICE_NAME=<my-new-service-name>
238-
spk service create . --display-name $SERVICE_NAME ...
238+
spk service create $SERVICE_NAME . ...
239239
git add -A
240240
git commit -m "Adding $SERVICE_NAME to the repository."
241241
git push -u origin --all
@@ -286,8 +286,8 @@ As an `spk` user, if you would like to incorporate helm charts from a well known
286286
public repository, you may simply run `spk` the following `helm-chart`
287287
arguments:
288288

289-
```
290-
spk service create --helm-chart-chart stable/nginx --helm-chart-repository github.com/helm/charts
289+
```sh
290+
spk service create nginx my-nginx-service --helm-chart-chart stable/nginx --helm-chart-repository github.com/helm/charts
291291
```
292292

293293
##### Helm Charts in a distinct Git Repository from Application Sources in the same Azure DevOps Project
@@ -296,7 +296,7 @@ If your Helm Charts are in their own distinct Git Repository in the _same_ Azure
296296
DevOps project, you can use the `helm-config` arguments to configure `spk`:
297297

298298
```
299-
spk service create \
299+
spk service create fabrikam path/to/fabrikam \
300300
--helm-config-git https://dev.azure.com/fabrikam/fabrikam-project/_git/fabrikam-helm-charts
301301
--helm-config-branch master \
302302
--helm-path /charts/fabrikam
@@ -340,7 +340,7 @@ the environment variable containing the Personal Access Token to access the git
340340
repository in `helm-config-git`:
341341

342342
```
343-
spk service create \
343+
spk service create fabrikam path/to/fabrikam \
344344
--helm-config-git https://dev.azure.com/fabrikam/fabrikam-helm-charts-project/_git/fabrikam-helm-charts \
345345
--helm-config-branch master \
346346
--helm-path /charts/fabrikam \

guides/rings-101.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ rings:
136136
isDefault: false
137137
qa: {} # isDefault not present is same as isDefault: false
138138
services:
139-
./my-service-foo:
139+
- path: my-service-foo
140140
displayName: fancy-service
141141
helm:
142142
chart:
@@ -212,7 +212,7 @@ rings:
212212
develop:
213213
isDefault: false
214214
services:
215-
./foo:
215+
- path: ./foo
216216
displayName: ""
217217
helm:
218218
chart:
@@ -225,7 +225,7 @@ services:
225225
middlewares: []
226226
pathPrefix: ""
227227
pathPrefixMajorVersion: ""
228-
./bar:
228+
- path: bar
229229
displayName: ""
230230
helm:
231231
chart:

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"md-lint": "find guides -name \\*.md | xargs -n 1 markdown-link-check",
1414
"format": "prettier --write 'src/**/*.ts{,x}'",
1515
"test": "jest --rootDir src --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html",
16-
"test-watch": "jest --watchAll",
16+
"test-watch": "jest --rootDir src --watchAll",
1717
"postinstall": "cd node_modules/azure-devops-node-api && git apply ../../patches/001-azure-devops-node.patch || true",
1818
"test-coverage-html": "jest --coverage --coverageReporters=html"
1919
},

src/commands/hld/reconcile.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rings:
2121
master:
2222
isDefault: true
2323
services:
24-
./services/fabrikam:
24+
- path: ./services/fabrikam
2525
displayName: "fabrikam"
2626
k8sBackendPort: 8001
2727
k8sBackend: "fabrikam-k8s-svc"

0 commit comments

Comments
 (0)