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

Commit e12df0a

Browse files
mtarngbnookala
authored andcommitted
Enabling spk ring commands, documentation, smoke tests
1 parent f1f90d0 commit e12df0a

File tree

7 files changed

+99
-85
lines changed

7 files changed

+99
-85
lines changed

docs/commands/data.json

+18
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,24 @@
476476
],
477477
"markdown": "## Description\n\nDeploy the HLD Lifecycle pipeline for the bedrock project. This should be run\nafter merging the `hld-lifecycle.yaml` generated by `spk project init` to the\nproject repository to master. The command will add the required pipeline\nvariables.\n"
478478
},
479+
"ring create": {
480+
"command": "create <ring-name>",
481+
"alias": "c",
482+
"description": "Create a new ring for the current working directory project repository. This will affect all services within the project repository.",
483+
"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"
484+
},
485+
"ring delete": {
486+
"command": "delete <ring-name>",
487+
"alias": "d",
488+
"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.",
489+
"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"
490+
},
491+
"ring set-default": {
492+
"command": "set-default <ring-name>",
493+
"alias": "s",
494+
"description": "Set a ring as the default for the current working directory project repository. This will affect all services within the project repository.",
495+
"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"
496+
},
479497
"service create-revision": {
480498
"command": "create-revision",
481499
"alias": "cr",
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"command": "create <ring-name>",
33
"alias": "c",
4-
"description": "Create a new ring for the current working directory project repository. This will affect all services within the project repository.",
5-
"disabled": true
4+
"description": "Create a new ring for the current working directory project repository. This will affect all services within the project repository."
65
}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"command": "delete <ring-name>",
33
"alias": "d",
4-
"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.",
5-
"disabled": true
4+
"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."
65
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"command": "set-default <ring-name>",
33
"alias": "s",
4-
"description": "Set a ring as the default for the current working directory project repository. This will affect all services within the project repository.",
5-
"disabled": true
4+
"description": "Set a ring as the default for the current working directory project repository. This will affect all services within the project repository."
65
}

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const commandModules = [
2525
"hld",
2626
"infra",
2727
"project",
28-
// "ring", // Uncomment when ready to add rings
28+
"ring",
2929
"service",
3030
"variable-group",
3131
];

tests/.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
spk-env/
2-
infra-generation-pipeline.yml
2+
infra-generation-pipeline.yml
3+
file.json

tests/validations.sh

+75-77
Original file line numberDiff line numberDiff line change
@@ -356,92 +356,92 @@ validate_file "$TEST_WORKSPACE/$manifests_dir/prod/$mono_repo_dir/$FrontEndCompl
356356
# Get the current pipeline/build id at this stage. This will be used by the introspection integration test.
357357
pipeline1id=$(az pipelines build list --definition-ids $pipeline_id --organization $AZDO_ORG_URL --project $AZDO_PROJECT | jq '.[0].id')
358358

359-
# ##################################
360-
# # App Mono Repo create ring
361-
# ##################################
362-
# echo "Create ring in mono repo"
363-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 400 15 2
364-
# echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
365-
# approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Reconciling HLD"
359+
##################################
360+
# App Mono Repo create ring
361+
##################################
362+
echo "Create ring in mono repo"
363+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 400 15 2
364+
echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
365+
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Reconciling HLD"
366366

367-
# # Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
368-
# echo "Wait for fabrikam-hld-to-fabrikam-manifests pipeline"
369-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 500 15 4
370-
# ring_name=qa-ring
367+
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
368+
echo "Wait for fabrikam-hld-to-fabrikam-manifests pipeline"
369+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 500 15 4
370+
ring_name=qa-ring
371371

372-
# cd $TEST_WORKSPACE
373-
# cd $mono_repo_dir
372+
cd $TEST_WORKSPACE
373+
cd $mono_repo_dir
374374

375-
# echo "Create ring"
376-
# git checkout master
377-
# git pull origin master
378-
# spk ring create $ring_name
379-
# git add -A
380-
# git commit -m "Adding test ring"
381-
# git push -u origin --all
375+
echo "Create ring"
376+
git checkout master
377+
git pull origin master
378+
spk ring create $ring_name
379+
git add -A
380+
git commit -m "Adding test ring"
381+
git push -u origin --all
382382

383-
# # Wait for the lifecycle pipeline to finish and approve the pull request
384-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 300 15 3
385-
# echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
386-
# approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Reconciling HLD"
383+
# Wait for the lifecycle pipeline to finish and approve the pull request
384+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $lifecycle_pipeline_name 300 15 3
385+
echo "Finding pull request that $lifecycle_pipeline_name pipeline created..."
386+
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Reconciling HLD"
387387

388-
# # Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
389-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 5
388+
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
389+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 5
390390

391-
# # Verify the file was added in the manifest repository
392-
# cd $TEST_WORKSPACE
393-
# cd $manifests_dir
391+
# Verify the file was added in the manifest repository
392+
cd $TEST_WORKSPACE
393+
cd $manifests_dir
394394

395-
# git pull origin master
395+
git pull origin master
396396

397-
# ring_dir="prod/$mono_repo_dir/fabrikam-acme-frontend/$ring_name"
398-
# if [ ! -d "$ring_dir" ]; then
399-
# echo "Directory '$ring_dir' does not exist"
400-
# exit 1
401-
# fi
397+
ring_dir="prod/$mono_repo_dir/fabrikam-acme-frontend/$ring_name"
398+
if [ ! -d "$ring_dir" ]; then
399+
echo "Directory '$ring_dir' does not exist"
400+
exit 1
401+
fi
402402

403-
# echo "Validating ingress routes"
403+
echo "Validating ingress routes"
404404

405-
# validate_file "$ring_dir/static.yaml" "'PathPrefix(\`/fabrikam-acme-frontend\`) && Headers(\`Ring\`, \`qa-ring\`)'"
405+
validate_file "$ring_dir/static.yaml" "'PathPrefix(\`/fabrikam-acme-frontend\`) && Headers(\`Ring\`, \`qa-ring\`)'"
406406

407-
# echo "Successfully created a ring."
407+
echo "Successfully created a ring."
408408

409-
# ##################################
410-
# # App Mono Repo update ring
411-
# ##################################
412-
# echo "Update ring."
413-
# cd $TEST_WORKSPACE
414-
# cd $mono_repo_dir
415-
# git branch $ring_name
416-
# git checkout $ring_name
417-
# cd services/$FrontEnd
418-
# echo "Ring doc" >> ringDoc.md
419-
# git add ringDoc.md
420-
# git commit -m "Adding ring doc file"
421-
# git push --set-upstream origin $ring_name
422-
423-
# # Verify frontend service pipeline run was successful
424-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 3
425-
# #complete merge
426-
# echo "Finding pull request that $frontend_pipeline_name pipeline created..."
427-
# approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Updating fabrikam.acme.frontend image tag to qa-ring"
428-
429-
# # Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
430-
# echo "Wait for hld to fabrikam manifests"
431-
# verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 400 15 6
432-
433-
# echo "Validating ring image tag in manifest repo"
434-
# cd $TEST_WORKSPACE/$hld_dir
435-
# git pull
436-
# cd $mono_repo_dir/$FrontEndCompliant/$ring_name/config
437-
# image_repository=$(grep -A3 'image:' common.yaml | tail -n3 | awk '{print $2}' | head -n1 )
438-
# image_tag=$(grep -A3 'image:' common.yaml | tail -n2 | awk '{print $2}' | head -n 1)
439-
# cd $TEST_WORKSPACE/$manifests_dir
440-
# git pull
441-
# validate_commit $image_tag
442-
# validate_file "$TEST_WORKSPACE/$manifests_dir/prod/$mono_repo_dir/$FrontEndCompliant/$ring_name/chart.yaml" "image: $image_repository:$image_tag"
443-
444-
# echo "Successfully updated a ring."
409+
##################################
410+
# App Mono Repo update ring
411+
##################################
412+
echo "Update ring."
413+
cd $TEST_WORKSPACE
414+
cd $mono_repo_dir
415+
git branch $ring_name
416+
git checkout $ring_name
417+
cd services/$FrontEnd
418+
echo "Ring doc" >> ringDoc.md
419+
git add ringDoc.md
420+
git commit -m "Adding ring doc file"
421+
git push --set-upstream origin $ring_name
422+
423+
# Verify frontend service pipeline run was successful
424+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $frontend_pipeline_name 300 15 3
425+
#complete merge
426+
echo "Finding pull request that $frontend_pipeline_name pipeline created..."
427+
approve_pull_request $AZDO_ORG_URL $AZDO_PROJECT "Updating fabrikam.acme.frontend image tag to qa-ring"
428+
429+
# Wait for fabrikam-hld-to-fabrikam-manifests pipeline to finish
430+
echo "Wait for hld to fabrikam manifests"
431+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 400 15 6
432+
433+
echo "Validating ring image tag in manifest repo"
434+
cd $TEST_WORKSPACE/$hld_dir
435+
git pull
436+
cd $mono_repo_dir/$FrontEndCompliant/$ring_name/config
437+
image_repository=$(grep -A3 'image:' common.yaml | tail -n3 | awk '{print $2}' | head -n1 )
438+
image_tag=$(grep -A3 'image:' common.yaml | tail -n2 | awk '{print $2}' | head -n 1)
439+
cd $TEST_WORKSPACE/$manifests_dir
440+
git pull
441+
validate_commit $image_tag
442+
validate_file "$TEST_WORKSPACE/$manifests_dir/prod/$mono_repo_dir/$FrontEndCompliant/$ring_name/chart.yaml" "image: $image_repository:$image_tag"
443+
444+
echo "Successfully updated a ring."
445445
# --------------------------------
446446

447447
echo "Successfully reached the end of the service validations scripts."
@@ -450,11 +450,9 @@ echo "Successfully reached the end of the service validations scripts."
450450
# SPK Introspection Validation START
451451
##################################
452452

453-
pipeline1id=$(az pipelines build list --definition-ids $pipeline_id --organization $AZDO_ORG_URL --project $AZDO_PROJECT | jq '.[0].id')
454-
455453
# Verify hld to manifest pipeline run was successful, to verify the full end-end capture of
456454
# introspection data
457-
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 3
455+
verify_pipeline_with_poll $AZDO_ORG_URL $AZDO_PROJECT $hld_to_manifest_pipeline_name 300 15 6
458456

459457
cd $TEST_WORKSPACE
460458
cd ..

0 commit comments

Comments
 (0)