Skip to content

Commit

Permalink
[DEVOPS-535] Install jq requirement in Azure Function Deploy workflow (
Browse files Browse the repository at this point in the history
…#150)

<details open>
<summary><a href="https://amuniversal.atlassian.net/browse/DEVOPS-535"
title="DEVOPS-535" target="_blank">DEVOPS-535</a></summary>
  <br />
  <table>
    <tr>
      <th>Summary</th>
      <td>Recurly Notification Manager deployment failed</td>
    </tr>
    <tr>
      <th>Type</th>
      <td>
<img alt="Bug"
src="https://amuniversal.atlassian.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10308?size=medium"
/>
        Bug
      </td>
    </tr>
    <tr>
      <th>Status</th>
      <td>In Development Env</td>
    </tr>
    <tr>
      <th>Points</th>
      <td>N/A</td>
    </tr>
    <tr>
      <th>Labels</th>
      <td>-</td>
    </tr>
  </table>
</details>
<!--
do not remove this marker as it will break action-jira-linter's
functionality.
  added_by_jira_lint
-->
---

<!-- Please make sure you read the contribution guidelines and then fill
out the blanks below.

Please format the PR title appropriately based on the type of change:
  [JIRA-XXX]: <description>
-->

## Description

- Install jq requirement in Azure Function Deploy workflow

## Related Links

<!-- List any links related to this pull request here

Replace "JIRA-XXX" with the your Jira issue key -->

- Jira Issue: DEVOPS-535
  • Loading branch information
ebronson68 committed Sep 17, 2024
1 parent cb7ab1a commit a074ccc
Showing 1 changed file with 56 additions and 60 deletions.
116 changes: 56 additions & 60 deletions .github/workflows/azfunction-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ jobs:
uses: actions/checkout@v4
with:
ref: ${{ inputs.checkoutRef }}

- uses: awalsh128/cache-apt-pkgs-action@latest

- name: Install jq apt package
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: jq

Expand Down Expand Up @@ -184,22 +185,19 @@ jobs:
- name: Get Azure Function Managed Identity
id: identity
uses: azure/cli@v2
with:
inlineScript: |
set -eu
if [[ "${{ inputs.environment }}" == "production" ]]; then
IDENTITY=$(az functionapp identity show \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" | tee)
else
IDENTITY=$(az functionapp identity show \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot "${{ inputs.environment }}" | tee)
fi
PRINCIPAL_ID=$(echo "$IDENTITY" | grep -o '"principalId": *"[^"]*"' | sed 's/.*: *"\([^"]*\)".*/\1/')
echo "functionAppIdentity=$PRINCIPAL_ID" >> $GITHUB_ENV
run: |
set -eu
if [[ "${{ inputs.environment }}" == "production" ]]; then
IDENTITY=$(az functionapp identity show \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" | tee)
else
IDENTITY=$(az functionapp identity show \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot "${{ inputs.environment }}" | tee)
fi
echo "functionAppIdentity=$(echo $IDENTITY | jq -r '.principalId')" >> $GITHUB_ENV
- name: Retrieve key vault name
uses: azure/cli@v2
Expand Down Expand Up @@ -244,55 +242,53 @@ jobs:
environmentVariableSeparator: "\n"

- name: Add environment variables to function app
uses: azure/cli@v2
with:
inlineScript: |
set -eu
# Store the environment variables output into a separate variable
ENV_VARS_OUTPUT='${{ steps.get-envs.outputs.environmentVariables }}'
run: |
set -eu
# Store the environment variables output into a separate variable
ENV_VARS_OUTPUT='${{ steps.get-envs.outputs.environmentVariables }}'
# Get current app settings
if [[ "${{ inputs.environment }}" == "production" ]]; then
APPSETTINGS=$(az functionapp config appsettings list \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}")
else
APPSETTINGS=$(az functionapp config appsettings list \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot "${{ inputs.environment }}")
fi
# Get current app settings
# Use a while loop to read and process each environment variable and trim output
echo "$ENV_VARS_OUTPUT" | sed '$ d' | while IFS='=' read -r key value; do
echo "Processing variable: $key=$value"
VARIABLE_LC=$(echo "$key" | tr '[:upper:]' '[:lower:]' | tr "_" "-")
# Search for the key in app settings
APPSETTING_VALUE=$(echo "${APPSETTINGS}" | jq -r ".[] | select(.name == \"$key\") | .value")
# Check if the value is set to a keyvault reference
if [[ "${APPSETTING_VALUE}" == "@Microsoft.KeyVault"* ]]; then
echo "Skipping $key as it is already a keyvault reference"
continue
fi
echo "Adding $key to app settings"
if [[ "${{ inputs.environment }}" == "production" ]]; then
APPSETTINGS=$(az functionapp config appsettings list \
az functionapp config appsettings set \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}")
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot-settings "$key=@Microsoft.KeyVault(VaultName=${{ env.keyVaultName }};SecretName=${VARIABLE_LC})" >/dev/null && \
echo "Successfully added $key to app settings"
else
APPSETTINGS=$(az functionapp config appsettings list \
az functionapp config appsettings set \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot "${{ inputs.environment }}")
--slot "${{ inputs.environment }}" \
--slot-settings "$key=@Microsoft.KeyVault(VaultName=${{ env.keyVaultName }};SecretName=${VARIABLE_LC})" >/dev/null && \
echo "Successfully added $key to app settings"
fi
# Use a while loop to read and process each environment variable and trim output
echo "$ENV_VARS_OUTPUT" | sed '$ d' | while IFS='=' read -r key value; do
echo "Processing variable: $key=$value"
VARIABLE_LC=$(echo "$key" | tr '[:upper:]' '[:lower:]' | tr "_" "-")
# Search for the key in app settings
APPSETTING_VALUE=$(echo "${APPSETTINGS}" | jq -r ".[] | select(.name == \"$key\") | .value")
# Check if the value is set to a keyvault reference
if [[ "${APPSETTING_VALUE}" == "@Microsoft.KeyVault"* ]]; then
echo "Skipping $key as it is already a keyvault reference"
continue
fi
echo "Adding $key to app settings"
if [[ "${{ inputs.environment }}" == "production" ]]; then
az functionapp config appsettings set \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot-settings "$key=@Microsoft.KeyVault(VaultName=${{ env.keyVaultName }};SecretName=${VARIABLE_LC})" >/dev/null && \
echo "Successfully added $key to app settings"
else
az functionapp config appsettings set \
-g "${{ inputs.AZURE_FUNCTIONAPP_RESOURCEGROUP }}" \
-n "${{ inputs.AZURE_FUNCTIONAPP_NAME }}" \
--slot "${{ inputs.environment }}" \
--slot-settings "$key=@Microsoft.KeyVault(VaultName=${{ env.keyVaultName }};SecretName=${VARIABLE_LC})" >/dev/null && \
echo "Successfully added $key to app settings"
fi
done
done
- name: Remove GitHub Runner IP from Whitelist
if: always()
Expand Down

0 comments on commit a074ccc

Please sign in to comment.