Skip to content

Commit

Permalink
Merge pull request #236 from aztfmod/fix.tags_caf
Browse files Browse the repository at this point in the history
Fix rover support for tags caf_environment
  • Loading branch information
arnaudlh committed Jan 21, 2022
2 parents 0487670 + f971c71 commit 6d4be14
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 42 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/rover-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ jobs:
with:
username: aztfmod
password: ${{ secrets.docker_registry_password }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
- name: Build the rover
run: |
set -e
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/rover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ jobs:
with:
username: aztfmod
password: ${{ secrets.docker_registry_password }}
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# - name: Cache Docker layers
# uses: actions/cache@v2
# with:
# path: /tmp/.buildx-cache
# key: ${{ runner.os }}-buildx-${{ github.sha }}
# restore-keys: |
# ${{ runner.os }}-buildx-
- name: Build the rover
run: |
set -e
Expand Down
63 changes: 39 additions & 24 deletions scripts/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,19 @@ function build_rover_agents {
tag=${2}
registry=${3}

tag=${versionTerraform}-${tag_date_preview}

echo "@build_rover_agents"
echo "Building agents with:"
echo " - registry - ${registry}"
echo " - version Rover - ${rover_base}:${tag}"
echo " - tag - ${tag}"
echo " - strategy - ${strategy}"
echo " - tag_strategy - ${tag_strategy}"

tag=${versionTerraform}-${tag_date_preview}

case "${strategy}" in
"local")

echo " - tag - ${tag}"
platform=$(uname -m)

registry="" \
Expand All @@ -162,28 +162,43 @@ function build_rover_agents {
--set *.platform=linux/${platform} \
--load rover_agents
;;
"github")
tag=${versionTerraform}-${tag_date_release}
echo " - tag - ${tag}"

registry="${registry}" \
tag_strategy=${tag_strategy} \
versionRover="${rover_base}:${tag}" \
versionTerraform=${versionTerraform} \
tag="${tag}" \
docker buildx bake \
-f docker-bake-agents.hcl \
-f docker-bake.override.hcl \
--push rover_agents
;;
"ci")
echo " - tag - ${tag}"
registry="${registry}" \
tag_strategy=${tag_strategy} \
versionRover="${rover_base}:${tag}" \
versionTerraform=${versionTerraform} \
tag="${tag}" \
docker buildx bake \
-f docker-bake-agents.hcl \
-f docker-bake.override.hcl \
--push gitlab
;;
*)
if [ "$strategy" == "ci" ]; then
registry="${registry}" \
tag_strategy=${tag_strategy} \
versionRover="${rover_base}:${tag}" \
versionTerraform=${versionTerraform} \
tag="${tag}" \
docker buildx bake \
-f docker-bake-agents.hcl \
-f docker-bake.override.hcl \
--push gitlab
else
registry="${registry}" \
tag_strategy=${tag_strategy} \
versionRover="${rover_base}:${tag}" \
versionTerraform=${versionTerraform} \
tag="${tag}" \
docker buildx bake \
-f docker-bake-agents.hcl \
-f docker-bake.override.hcl \
--push rover_agents
fi
echo " - tag - ${tag}"
registry="${registry}" \
tag_strategy=${tag_strategy} \
versionRover="${rover_base}:${tag}" \
versionTerraform=${versionTerraform} \
tag="${tag}" \
docker buildx bake \
-f docker-bake-agents.hcl \
-f docker-bake.override.hcl \
--push rover_agents
;;
esac

Expand Down
12 changes: 8 additions & 4 deletions scripts/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,17 @@ function list_deployed_landingzones {
echo ""
}

function get_tfstate_keyvault_name {
keyvault=$(az graph query -q "Resources | where type == 'microsoft.keyvault/vaults' and ((tags.environment == '${TF_VAR_environment}' and tags.tfstate == '${TF_VAR_level}') or (tags.caf_environment == '${TF_VAR_environment}' and tags.caf_tfstate == '${TF_VAR_level}')) | project name" --query "data[0].name" -o tsv --subscriptions ${TF_VAR_tfstate_subscription_id})
}

function login_as_launchpad {
echo "@calling login_as_launchpad"

echo ""
echo "Getting launchpad coordinates from subscription: ${TF_VAR_tfstate_subscription_id}"

keyvault=$(az graph query -q "Resources | where type == 'microsoft.keyvault/vaults' and ((tags.environment == '${TF_VAR_environment}' and tags.tfstate == '${TF_VAR_level}') or (tags.caf_environment == '${TF_VAR_environment}' and tags.caf_tfstate == '${TF_VAR_level}')) | project name" --query "data[0].name" -o tsv --subscriptions ${TF_VAR_tfstate_subscription_id})
get_tfstate_keyvault_name
echo " - keyvault_name: ${keyvault}"

stg=$(az storage account show --ids ${id} -o json)
Expand Down Expand Up @@ -624,7 +628,7 @@ function get_logged_user_object_id {
unset TF_VAR_logged_user_objectId
export clientId=$(az account show --query user.name -o tsv)

export keyvault=$(az keyvault list --subscription ${TF_VAR_tfstate_subscription_id} --query "[?tags.tfstate=='${TF_VAR_level}' && tags.environment=='${TF_VAR_environment}']" -o json | jq -r .[0].name)
get_tfstate_keyvault_name

case "${clientId}" in
"systemAssignedIdentity")
Expand Down Expand Up @@ -707,13 +711,13 @@ function deploy {
fi
else
error ${LINENO} "You need to initialise a launchpad first with the command \n
rover /tf/caf/landingzones/launchpad [plan | apply | destroy] -launchpad" 1000
rover /tf/caf/landingzones/caf_launchpad [plan | apply | destroy] -launchpad" 1000
fi
;;
*)

# Get the launchpad version
caf_launchpad=$(az storage account show --ids $id -o json | jq -r .tags.launchpad)
caf_launchpad=$(az storage account show --ids $id -o json | jq -r ".tags | .caf_launchpad,.launchpad | select( . != null )")
echo ""
echo "${caf_launchpad} already installed"
echo ""
Expand Down

0 comments on commit 6d4be14

Please sign in to comment.