This is an opinionated repository demonstrating Cloud Build based builds of Bank-of-Anthos main-line along with secure CI/CD principles applied. This demonstration uses Bank of Anthos to simulate a company building and deploying services to a multi-tier kubernetes cluster using asynchronous GitOps.
- 0-bootstrap executed successfully.
- 1-org executed successfully.
- 2-environments executed successfully.
- 3-networks executed successfully.
- 4-projects executed successfully.
- 5-infrastructure executed successfully.
- Namespace repos created from 6-anthos-install created successfully.
- frontend
- accounts
- transactions
- Change directory to outside
terraform-example-foundation-app
usingcd ..
, to confirm you runls
and you should seeterraform-example-foundation-app
listed. - Clone Bank of Anthos repo.
git clone https://github.com/GoogleCloudPlatform/bank-of-anthos.git
- Delete the
.git
folder from the Github Bank of Anthos Repo.rm -rf bank-of-anthos/.git
- Clone bank-of-anthos-source repo. Replace the Cloudbuild project id by the correct one (you can rerun
terraform output app_cicd_project_id
in thegcp-projects/business_unit_1/shared
folder)gcloud source repos clone bank-of-anthos-source --project=prj-bu1-c-app-cicd-<random>
- Navigate into the repo.
cd bank-of-anthos-source
- Create main branch.
git checkout -b main
- Copy contents of Bank of Anthos Github Repo to new repo (modify accordingly based on your current directory).
cp -RT ../bank-of-anthos .
- Copy file
cloudbuild-build-boa.yaml
andpolicies
folder from 7-app-build-deploy to new repo (modify accordingly based on your current directory).cp -RT ../terraform-example-foundation-app/7-app-build-deploy .
- Run the following command at the root folder level while replacing the region from
boa-infra/business_unit_1/shared
and project fromgcp-projects/business_unit_1/shared
stage.export REGION=<your_region> export PROJECT_ID=prj-bu1-c-app-cicd-<random> sed -i.bak \ "s|gcr.io/bank-of-anthos-ci|${REGION}-docker.pkg.dev/${PROJECT_ID}/${PROJECT_ID}-boa-image-repo|g" skaffold.yaml && \ sed -i.bak "s|gitCommit: {}|sha256: {}|g" skaffold.yaml
- Commit and push the changes.
git add . git commit -m 'Your message' git push origin main
- Cloudbuild will automatically run on push, confirm all stages of pipeline complete with a green check in https://console.cloud.google.com/cloud-build/builds?project=prj-bu1-c-app-cicd-xxxx
- Check files mentioned in proceeding section have been changed in their respective repos (https://source.cloud.google.com/prj-bu1-c-app-cicd-xxxx).
prj-bu1-c-app-cicd-xxxx/
└── frontend
├── frontend.yaml
├── loadgenerator.yaml
└── accounts
├── contacts.yaml
├── userservice.yaml
└── transactions
├── balancereader.yaml
├── ledgerwriter.yaml
├── trasactionhistory.yaml
This is a diagram of the entire CI/CD flow with labeled stages. Each subsection (labeled as "phases") will target one or more of the subsections.
This first stage will build all candidate artifacts (docker-based images).
- Unit tests - Run unit tests for all source code
- Static code analysis (PMD, Checkstyle, Linting) - Run static analysis for all source code
- Secrets scanner - Look for secrets embedded in source
- Code coverage - Pull code coverage numbers and make decision based on results
- Fail fast if any of the steps fail
- Validate source code for artifact build
NOTE: The conclusion of this stage will have all docker images created in the Artifact Repo or GAR. Additionally, an attestation will be created.
This next stage is to verify the artifact before it has been deployed
- Container Structure Tests - Verify that the container built conforms to the organizational standards
- Container Analysis - Verify that the container does not contain Common Vulnerabilities or Exposures (CVEs) per the organization's standards
- Fail fast if any of the steps fail
- Validate the artifact build to be ready for lower-level environments
- Artifact passes basic organization policy regulations
The final phase is to create an Attestation to attest to the fact that the container has successfully completed the previous steps.
- Create Attestation - The only step in this phase is to create an attestation for the artifact. This requires the artifact's image-digest as well as access to the Actor/Signer for automated security.
- Create an attestation using the Security attestor
NOTE: Pipeline runs where image does not change / does not require a change will fail at the last step and is a postive failure