Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions azure-pipelines/templates/infra-generation-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,40 @@ steps:
set -e

# Retrieve most recent commit hash from HLD repo
commit_hash=$(git rev-parse HEAD)
commit_hash=$(git rev-parse HEAD | cut -c1-7)
echo "Commit Hash: $commit_hash"

# Clone Generated Repo and copy generated components over
echo "Cloning Generated Repo: $GENERATED_REPO"
git clone $GENERATED_REPO
repo_url=$GENERATED_REPO

# Extract repo name from url
repo_url=$GENERATED_REPO
repo=${repo_url##*/}
repo_name=${repo%.*}

cd "$repo_name"

git pull

rsync -rv --exclude=.terraform $HOME/$PROJECT_DIRECTORY-generated .

# Check if PR branch already exists:
pr_list=$(git ls-remote origin)
if [[ $pr_list == *"pr-$commit_hash"* ]]; then
echo "PR Branch already exist. Iterating..."
count=$(git ls-remote origin | grep "pr-$commit_hash" | wc -l | tr -d " ")
count=$((count + 1))
PR_BRANCH_NAME=pr-$commit_hash-$count
echo "PR BRANCH NAME: $PR_BRANCH_NAME"
git checkout -b $PR_BRANCH_NAME
else
echo "PR Branch does not exist. Creating a new PR Branch"
PR_BRANCH_NAME=pr-$commit_hash-1
echo "PR BRANCH NAME: $PR_BRANCH_NAME"
git checkout -b $PR_BRANCH_NAME
fi

# Set git identity
git config user.email "admin@azuredevops.com"
git config user.name "Automated Account"
Expand All @@ -101,7 +120,7 @@ steps:

# Format Terraform files
terraform fmt

# Add generated files to repository
git status
git add .
Expand Down Expand Up @@ -142,4 +161,4 @@ steps:
fi
env:
ACCESS_TOKEN_SECRET: $(ACCESS_TOKEN_SECRET)
displayName: 'Commit and Push to Generated Repository'
displayName: 'Commit and Push to Generated Repository'
11 changes: 8 additions & 3 deletions guides/infra/spk-infra-generation-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ orchestrator for your Infrastructure Generation workflow using `spk infra`.
## Prerequisites

1. _Permissions_: The ability to create Projects in your Azure DevOps
Organization.
Organization and set security permissions to "Contribute" and "Contribute to
Pull Requests" for git repositories.
2. _High Level Definitions_: Your own infrastructure high level definitions for
your deployment. You can refer to a sample repo
[here](https://github.com/yradsmikham/spk-infra-hld). You should be able to
Expand All @@ -28,6 +29,10 @@ two flavors:
- [Azure DevOps](https://github.com/microsoft/bedrock/blob/master/gitops/azure-devops/ADORepos.md)
- [GitHub](https://github.com/microsoft/bedrock/blob/master/gitops/azure-devops/GitHubRepos.md)

**Note**: If your git repos are in different Azure DevOps organizations and/or
pojects, be sure that the generated git repo has "Contribute" and "Contribute to
Pull Requests" permissions configured in the security settings.

### 2. Add Azure Pipeline Build YAML

The SPK repository has a
Expand Down Expand Up @@ -65,8 +70,8 @@ If using Azure DevOps repos, be sure to include the additional environment
variables:

```
AZDO_ORG_NAME: Azure DevOps organization url (i.e. https://dev.azure.com/org_name/)
AZDO_PROJECT_NAME: The name of the project in your Azure DevOps organization where the repository is hosted
AZDO_ORG_NAME: Azure DevOps organization url where the generated repo is hosted (i.e. https://dev.azure.com/org_name/)
AZDO_PROJECT_NAME: The name of the project in your Azure DevOps organization where the generated repo is hosted
```

You can use `spk` to create the Azure DevOps Variable Groups by executing
Expand Down