Skip to content

Commit

Permalink
Add Redis External Cache (#4)
Browse files Browse the repository at this point in the history
* add external redis cache

* add CI validation on PR

* set branch

* try to fix paramater error

* split cachesTemplate into its own file

* fix dependsOn

* fix template name

* fix branch for PR workflow

* fix branch for PR workflow #2

* fix branch environment variables

* fix branch environment variables

* fix default vaule for redis connection string

* try removing parameters

* Revert "try removing parameters"

This reverts commit 8706ae7.

* remove paramters from -apim you idiot

* add redis connection string

* update job names to be more specific
  • Loading branch information
nosvalds authored Jul 28, 2021
1 parent 1abfb35 commit 8fdb5e1
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 8 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/apim-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Validate_APIM_On_PR_to_Dev

on:
pull_request:
branches:
- develop
paths:
- "service/**"
- ".github/workflows/apim-ci.yml"
- ".github/workflows/apim-develop.yml"

jobs:
validate-apim:
runs-on: ubuntu-latest

env:
Environment: dev
UrlEnvPrefix: dev-
SubscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
resourceGroup: rg-apim-dev
AZURE_CREDENTIALS: ${{ secrets.DEV_AZURE_CREDENTIALS }}
ApimServiceName: apim-iati-dev
ApimGatewayHostname: dev-api.iatistandard.org
ApimDevPortalHostname: dev-developer.iatistandard.org
ApimSKU: Developer
ApimCapacity: 1
repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway
repoApimPath: service
RedisConnectionString: ${{ secrets.DEV_REDIS_CONNECTION_STRING }}

steps:
- name: "Checkout GitHub Action"
uses: actions/checkout@v2

- name: "Login to Azure"
uses: azure/[email protected]
with:
creds: ${{ env.AZURE_CREDENTIALS }}

# ARM deployment tasks
- name: Validate APIM ARM Templates with what-if
working-directory: ./service
env:
LinkedTemplatesBaseUrl: ${{ env.repoUrl }}/${{ github.HEAD_REF }}/${{ env.repoApimPath }}
PolicyXMLBaseUrl: ${{ env.repoUrl }}/${{ github.HEAD_REF }}/${{ env.repoApimPath }}/policies
deploymentName: --name GH_what_if_deployment_apim
rg: --resource-group ${{ env.resourceGroup }}
apiNamePrefix: apim-iati-dev
run: |
az deployment group what-if ${{env.deploymentName}} \
${{env.rg}} \
--template-file ./${{env.apiNamePrefix}}-master.template.json \
--parameters ./${{env.apiNamePrefix}}-parameters.json \
--parameters ApimServiceName=${{ env.ApimServiceName }} \
--parameters LinkedTemplatesBaseUrl=${{ env.LinkedTemplatesBaseUrl }} \
--parameters PolicyXMLBaseUrl=${{ env.PolicyXMLBaseUrl }} \
--parameters Environment=${{ env.Environment }} \
--parameters UrlEnvPrefix=${{ env.UrlEnvPrefix }} \
--parameters SubscriptionId=${{ env.SubscriptionId }} \
--parameters ApimSKU=${{ env.ApimSKU }} \
--parameters ApimCapacity=${{ env.ApimCapacity }} \
--parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \
--parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \
--parameters RedisConnectionString=${{ env.RedisConnectionString }}
6 changes: 4 additions & 2 deletions .github/workflows/apim-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- ".github/workflows/apim-develop.yml"

jobs:
validate-deploy-apim:
deploy-apim-dev:
runs-on: ubuntu-latest

env:
Expand All @@ -26,6 +26,7 @@ jobs:
repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway
repoBranch: ${GITHUB_REF##*/}
repoApimPath: service
RedisConnectionString: ${{ secrets.DEV_REDIS_CONNECTION_STRING }}

steps:
- name: "Checkout GitHub Action"
Expand Down Expand Up @@ -59,4 +60,5 @@ jobs:
--parameters ApimSKU=${{ env.ApimSKU }} \
--parameters ApimCapacity=${{ env.ApimCapacity }} \
--parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \
--parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }}
--parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \
--parameters RedisConnectionString=${{ env.RedisConnectionString }}
6 changes: 4 additions & 2 deletions .github/workflows/apim-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
types: [published]

jobs:
validate-deploy-apim:
deploy-apim-prod:
runs-on: ubuntu-latest

env:
Expand All @@ -23,6 +23,7 @@ jobs:
repoUrl: https://raw.githubusercontent.com/iati/apim-iati-gateway
repoBranch: ${GITHUB_REF##*/}
repoApimPath: service
RedisConnectionString: ${{ secrets.PROD_REDIS_CONNECTION_STRING }}

steps:
- name: "Checkout GitHub Action"
Expand Down Expand Up @@ -56,4 +57,5 @@ jobs:
--parameters ApimSKU=${{ env.ApimSKU }} \
--parameters ApimCapacity=${{ env.ApimCapacity }} \
--parameters ApimGatewayHostname=${{ env.ApimGatewayHostname }} \
--parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }}
--parameters ApimDevPortalHostname=${{ env.ApimDevPortalHostname }} \
--parameters RedisConnectionString=${{ env.RedisConnectionString }}
31 changes: 31 additions & 0 deletions service/apim-iati-dev-caches.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ApimServiceName": {
"type": "string"
},
"Environment": {
"type": "string"
},
"RedisConnectionString": {
"type": "string"
},
"SubscriptionId": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/caches",
"apiVersion": "2020-12-01",
"name": "[concat(parameters('ApimServiceName'), '/uksouth')]",
"properties": {
"useFromLocation": "uksouth",
"description": "[concat('redis-iati-',parameters('Environment'),'.redis.cache.windows.net')]",
"connectionString": "[parameters('RedisConnectionString')]",
"resourceId": "[concat('https://management.azure.com/subscriptions/',parameters('SubscriptionId'),'/resourceGroups/rg-sharedresources-',parameters('Environment'), '/providers/Microsoft.Cache/Redis/redis-iati-', parameters('Environment'))]"
}
}
]
}
35 changes: 35 additions & 0 deletions service/apim-iati-dev-master.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
"metadata": {
"description": "Capacity of the APIM Instance"
}
},
"RedisConnectionString": {
"type": "string",
"metadata": {
"description": "Connection string for external redis cache"
}
}
},
"resources": [
Expand Down Expand Up @@ -121,6 +127,35 @@
"apiVersion": "2018-05-01",
"dependsOn": []
},
{
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[concat(parameters('LinkedTemplatesBaseUrl'), '/apim-iati-dev-caches.template.json')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"ApimServiceName": {
"value": "[parameters('ApimServiceName')]"
},
"Environment": {
"value": "[parameters('Environment')]"
},
"SubscriptionId": {
"value": "[parameters('SubscriptionId')]"
},
"RedisConnectionString": {
"value": "[parameters('RedisConnectionString')]"
}
}
},
"name": "cachesTemplate",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2018-05-01",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'apimTemplate')]"
]
},
{
"properties": {
"mode": "Incremental",
Expand Down
10 changes: 6 additions & 4 deletions service/apim-iati-dev-parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
"value": "dev-"
},
"LinkedTemplatesBaseUrl": {
"value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/main/service/"
"value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/develop/service/"
},
"PolicyXMLBaseUrl": {
"value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/main/service/policies/"
"value": "https://raw.githubusercontent.com/IATI/apim-iati-gateway/develop/service/policies/"
},
"SubscriptionId": {
"value": "bcaf7a00-7a14-4932-ac41-7bb0dee0d2a9"
Expand Down Expand Up @@ -51,7 +51,9 @@
},
"ApimCapacity": {
"value": 1
},
"RedisConnectionString": {
"value": "placeholderstring"
}
},
"resources": []
}
}

0 comments on commit 8fdb5e1

Please sign in to comment.