This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
196 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
echo "GITHUB_REPO_NAME: $GITHUB_REPO_NAME" | ||
DESCRIPTION="github/$GITHUB_REPO_NAME" | ||
PRID=$SYSTEM_PULLREQUEST_PULLREQUESTNUMBER | ||
echo "PRID: $PRID" | ||
echo "PULLREQUEST_PULLREQUESTNUMBER: $SYSTEM_PULLREQUEST_PULLREQUESTNUMBER" | ||
|
||
if [ -n "$PRID" ]; then | ||
DESCRIPTION="(PR-$PRID) $DESCRIPTION" | ||
PROJECT_NAME=${PROJECT_NAME}-pr-${PRID} | ||
export DOCKER_IMAGE_TAG="pr-$PRID" | ||
else | ||
echo "Non-PR: $BUILD_SOURCEBRANCH" | ||
exit 1 | ||
fi | ||
|
||
./scripts/devops/install-rancher | ||
|
||
echo "Deploying to Rancher at: $PROJECT_NAME" | ||
cd "./rancher-config" || exit | ||
../rancher --debug --url "$RANCHER_URL" --wait up --force-upgrade --pull -d --upgrade --confirm-upgrade --stack "$PROJECT_NAME" --description "$DESCRIPTION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
get_vault_data() { | ||
VAULT_PATH="$1" | ||
|
||
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -H "X-Vault-Token: $VAULT_TOKEN" -X GET "https://${VAULT_SERVER}${VAULT_PATH}") | ||
echo "Retrieving variables from path: '$VAULT_PATH}'. Got status: '$HTTP_STATUS}'." | ||
if [ "$HTTP_STATUS" = "200" ]; then | ||
DATA=$( curl -s \ | ||
-H "X-Vault-Token: $VAULT_TOKEN}" \ | ||
-X GET \ | ||
"https://${VAULT_SERVER}${VAULT_PATH}" \ | ||
) | ||
fi | ||
echo "$DATA" | jq -r '.data | to_entries[] | [ .key, .value|tostring ] | ("##vso[task.setvariable variable="+.[0]+"]"+.[1])' | ||
} | ||
|
||
# CHECK VAULT PATH EXISTS | ||
if [ -z "$VAULT_SERVER" ]; then | ||
echo "VAULT_SERVER not set, skipping vault config" | ||
SKIP="1" | ||
fi | ||
|
||
# CHECK VALUT TOKEN EXISTS | ||
if [ -z "$VAULT_TOKEN" ]; then | ||
echo "VAULT_TOKEN not set, skipping vault config" | ||
SKIP="1" | ||
fi | ||
|
||
# CHECK ENVIRONMENT NAME EXISTS | ||
# Within Vault this is the name of the environment e.g. dev, production, staging, etc. | ||
# The name of stage to which deployment is currently in progress | ||
if [ -z "$RELEASE_ENVIRONMENTNAME" ]; then | ||
echo "RELEASE_ENVIRONMENTNAME not set, skipping environment config" | ||
SKIP="1" | ||
fi | ||
|
||
# WHEN RELEASE_ENVIRONMENTNAME=review, USE DEV | ||
# This saves having to setup a secret within /review but allows the differentiation | ||
# between review apps and those built from master branch | ||
if [ "$RELEASE_ENVIRONMENTNAME" == "review" ]; then | ||
RELEASE_ENVIRONMENTNAME="dev" | ||
fi | ||
|
||
# CHECK PROJECT NAME EXISTS | ||
# Within Vault this is the name of the secret (or application) e.g. nhsuk.apim-blue-green-deploy | ||
# The name of the build pipeline | ||
if [ -z "$BUILD_DEFINITIONNAME" ]; then | ||
echo "BUILD_DEFINITIONNAME not set, skipping environment config" | ||
SKIP="1" | ||
fi | ||
|
||
if [ "$SKIP" != "1" ]; then | ||
# GET DEFAULT VARIABLES | ||
VAULT_PATH="/v1/secret/defaults" | ||
get_vault_data "$VAULT_PATH" | ||
|
||
# GET DEFAULT ENVIRONMENT VARIABLES | ||
VAULT_PATH="/v1/secret/$RELEASE_ENVIRONMENTNAME/defaults" | ||
get_vault_data "$VAULT_PATH" | ||
|
||
# GET APPLICATION VARIABLES | ||
VAULT_PATH="/v1/secret/defaults/$BUILD_DEFINITIONNAME/env-vars" | ||
get_vault_data "$VAULT_PATH" | ||
|
||
# GET ENVIRONMENT SPECIFIC APPLICATION VARIABLES | ||
VAULT_PATH="/v1/secret/${RELEASE_ENVIRONMENTNAME}/$BUILD_DEFINITIONNAME/env-vars" | ||
get_vault_data "$VAULT_PATH" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/bash | ||
|
||
if [ ! -f "./rancher" ] ; then | ||
RANCHER_VERSION='v0.6.13' | ||
|
||
echo "Installing Rancher (${RANCHER_VERSION})" | ||
curl -Ls https://github.com/rancher/cli/releases/download/${RANCHER_VERSION}/rancher-linux-amd64-${RANCHER_VERSION}.tar.gz \ | ||
| tar xzf - | ||
mv rancher-${RANCHER_VERSION}/rancher ./rancher | ||
rm -r rancher-${RANCHER_VERSION} | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters