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

Commit a91a742

Browse files
authored
Add infra-generation-pipeline.yml and docs (#195)
1 parent 41a6015 commit a91a742

17 files changed

+325
-11
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
trigger:
2+
branches:
3+
include:
4+
- master
5+
6+
pool:
7+
vmImage: 'ubuntu-latest'
8+
9+
variables:
10+
- group: 'spk-infra-hld-vg'
11+
12+
steps:
13+
- checkout: self
14+
persistCredentials: true
15+
clean: true
16+
17+
- bash: |
18+
curl $BEDROCK_BUILD_SCRIPT > build.sh
19+
chmod +x ./build.sh
20+
displayName: Download Bedrock orchestration script
21+
env:
22+
BEDROCK_BUILD_SCRIPT: https://raw.githubusercontent.com/Microsoft/bedrock/master/gitops/azure-devops/build.sh
23+
24+
- script: |
25+
dpkg --configure -a
26+
curl -sL https://aka.ms/InstallAzureCLIDeb | bash
27+
az extension add --name azure-devops
28+
az --version
29+
wget https://releases.hashicorp.com/terraform/$(tf_version)/terraform_$(tf_version)_linux_amd64.zip -q
30+
unzip -q terraform_$(tf_version)_linux_amd64.zip
31+
sudo mv terraform /usr/local/bin
32+
terraform -version
33+
displayName: 'Install az-cli, az devops extension, and Terraform'
34+
35+
- script: |
36+
. build.sh --source-only
37+
init
38+
get_os_spk
39+
get_spk_version
40+
download_spk
41+
echo 'SPK Version: '
42+
spk --version
43+
set -e
44+
echo "GENERATING $PROJECT_DIRECTORY"
45+
cd $PROJECT_DIRECTORY
46+
spk infra generate -p $CLUSTER
47+
env:
48+
ARM_CLIENT_ID: $(ARM_CLIENT_ID)
49+
ARM_CLIENT_SECRET: $(ARM_CLIENT_SECRET)
50+
ARM_TENANT_ID: $(ARM_TENANT_ID)
51+
ARM_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)
52+
displayName: 'SPK'
53+
54+
- script: |
55+
. build.sh --source-only
56+
init
57+
cd $PROJECT_DIRECTORY-generated/$CLUSTER
58+
terraform init -backend-config=./backend.tfvars
59+
displayName: 'Terraform init'
60+
61+
- script: |
62+
. build.sh --source-only
63+
init
64+
cd $PROJECT_DIRECTORY-generated/$CLUSTER
65+
terraform plan -var-file=./spk.tfvars
66+
env:
67+
ARM_CLIENT_ID: $(ARM_CLIENT_ID)
68+
ARM_CLIENT_SECRET: $(ARM_CLIENT_SECRET)
69+
ARM_TENANT_ID: $(ARM_TENANT_ID)
70+
ARM_SUBSCRIPTION_ID: $(ARM_SUBSCRIPTION_ID)
71+
displayName: 'Terraform plan'
72+
73+
- script: |
74+
# Exit on error
75+
set -e
76+
77+
# Retrieve most recent commit hash from HLD repo
78+
commit_hash=$(git rev-parse HEAD)
79+
echo "Commit Hash: $commit_hash"
80+
81+
# Clone Generated Repo and copy generated components over
82+
echo "Cloning Generated Repo: $GENERATED_REPO"
83+
git clone $GENERATED_REPO
84+
repo_url=$GENERATED_REPO
85+
86+
# Extract repo name from url
87+
repo_url=$GENERATED_REPO
88+
repo=${repo_url##*/}
89+
repo_name=${repo%.*}
90+
91+
cd "$repo_name"
92+
rsync -rv --exclude=.terraform $HOME/$PROJECT_DIRECTORY-generated .
93+
94+
# Set git identity
95+
git config user.email "admin@azuredevops.com"
96+
git config user.name "Automated Account"
97+
98+
# Following variables have to be set for TeamCity
99+
export GIT_AUTHOR_NAME="Automated Account"
100+
export GIT_COMMITTER_NAME="Automated Account"
101+
export EMAIL="admin@azuredevops.com"
102+
103+
# Add generated files to repository
104+
git status
105+
git add .
106+
git commit -m "Adding generated components for $PROJECT_DIRECTORY/$CLUSTER"
107+
108+
# Create a new branch
109+
PR_BRANCH_NAME=pr_$commit_hash
110+
git checkout -b $PR_BRANCH_NAME
111+
112+
# Git Push
113+
repo_url=$GENERATED_REPO
114+
repo_url="${repo_url#http://}"
115+
repo_url="${repo_url#https://}"
116+
echo "$repo_url"
117+
echo "GIT PUSH: https://<ACCESS_TOKEN_SECRET>@$repo_url"
118+
git push "https://$ACCESS_TOKEN_SECRET@$repo_url" $PR_BRANCH_NAME
119+
120+
# Create PR
121+
# If using GitHub repos:
122+
echo "CREATE PULL REQUEST"
123+
if [[ $GENERATED_REPO == *"github"* ]]; then
124+
echo "Installing Hub"
125+
sudo add-apt-repository ppa:cpick/hub
126+
sudo apt-get update
127+
sudo apt-get install hub
128+
export GITHUB_TOKEN=$ACCESS_TOKEN_SECRET
129+
hub pull-request -m "Adding Generated Components for $PROJECT_DIRECTORY/$CLUSTER"
130+
elif [[ $GENERATED_REPO == *"azure"* ]] || [[ $GENERATED_REPO == *"visualstudio"* ]]; then
131+
# If using AzDo repos:
132+
# You will need to specify variables $AZDO_ORG_NAME and $AZDO_PROJECT_NAME
133+
export AZURE_DEVOPS_EXT_PAT=$ACCESS_TOKEN_SECRET
134+
az devops configure --defaults organization=$AZDO_ORG_NAME project=$AZDO_PROJECT_NAME
135+
echo "Making pull request for $PR_BRANCH_NAME against master"
136+
az repos pr create --description "Automated PR for $PR_BRANCH_NAME against master"
137+
else
138+
echo "Unable to create pull request."
139+
exit 1
140+
fi
141+
env:
142+
ACCESS_TOKEN_SECRET: $(ACCESS_TOKEN_SECRET)
143+
displayName: 'Commit and Push to Generated Repository'

docs/cloud-infra-management.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Cloud Infra Management
22

33
Manage and update Bedrock infrastructure. For more information on the
4-
`spk infra` design, refer to the infrasrtucture design docs
4+
`spk infra` design, refer to the infrastructure design docs
55
[here](./infra/README.md).
66

77
Usage:
@@ -86,15 +86,13 @@ Options:
8686
-h, --help Usage information
8787
```
8888

89-
#### scaffold sample
89+
#### scaffold example
9090

9191
```
9292
spk infra scaffold --name discovery-service --source https://github.com/microsoft/bedrock --version "v0.12.0" --template /cluster/environments/azure-simple
9393
```
9494

95-
Output:
96-
97-
definition.yaml
95+
definition.yaml output:
9896

9997
```yaml
10098
name: discovery-service
@@ -139,11 +137,9 @@ variables:
139137
140138
### generate
141139
142-
Generates a deployment folder based on scaffolded project with a definition.yaml
143-
144140
Generates a deployment folder of an infrastructure scaffolded project containing
145-
a `definition.yaml` that contains a `source`, `template` and `version` to obtain
146-
and complete the terraform template files.
141+
a `definition.yaml` with a `source`, `template` and `version` to obtain and
142+
complete the Terraform template files.
147143

148144
It will do the following:
149145

290 KB
Loading

docs/images/spk-infra-azdo.png

338 KB
Loading
763 KB
Loading
214 KB
Loading

docs/images/spk-infra-github.png

274 KB
Loading
345 KB
Loading
298 KB
Loading
625 KB
Loading

0 commit comments

Comments
 (0)