Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1186 - Use bicep to develop, build arm templates #1540

Merged
merged 2 commits into from
Nov 17, 2022
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
20 changes: 16 additions & 4 deletions .github/workflows/arm-ttk.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Validate ARM templates
name: Validate Bicep templates

on:
pull_request:
branches: [ main, v3-dev ]
branches: [ main ]
paths:
- 'templates/**'
push:
Expand All @@ -24,6 +24,7 @@ on:

jobs:
validate_arm_templates:
name: Build Bicep and Validate ARM Templates
runs-on: ubuntu-latest

steps:
Expand All @@ -45,9 +46,20 @@ jobs:
with:
repository: Azure/arm-ttk
path: arm-ttk


- name: Checkout Azure/iotedge-lorawan-starterkit
uses: actions/checkout@v3.1.0
with:
repository: Azure/iotedge-lorawan-starterkit
ref: dev
path: iotedge-lorawan-starterkit

- name: Generate ARM file
working-directory: templates
run: az bicep build --file azuredeploy.bicep --outfile azuredeploy.json

- name: Run arm-ttk
shell: pwsh
run: |
Import-Module ./arm-ttk/arm-ttk/arm-ttk.psd1
Test-AzTemplate -TemplatePath ./templates
Test-AzTemplate -TemplatePath ./templates/azuredeploy.json -Skip 'Template Should Not Contain Blanks','URIs Should Be Properly Constructed'
68 changes: 66 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ env:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
name: Build & Push Solution
# The type of runner that the job will run on
Expand Down Expand Up @@ -67,4 +66,69 @@ jobs:
BUILD_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
GITHUB_RUN_NUMBER=${{ github.run_number }}
tags:
${{ steps.meta.outputs.tags }}
${{ steps.meta.outputs.tags }}

arm_templates:
name: Publish ARM templates
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3.1.0
with:
path: IoT-Hub-Portal

- name: Checkout Azure/iotedge-lorawan-starterkit
uses: actions/checkout@v3.1.0
with:
repository: Azure/iotedge-lorawan-starterkit
ref: dev
path: iotedge-lorawan-starterkit

- uses: actions/checkout@v3.1.0
with:
ref: arm/main
path: arm-templates

- name: Generate app token
id: generate_app_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}

- name: Copy templates
working-directory: arm-templates
run: |
rm -rf ./templates/
mkdir -p templates/iotedge-lorawan-starterkit
touch ./templates/.gitkeep
cp -r ../IoT-Hub-Portal/templates/* ./templates/
cp -r ../iotedge-lorawan-starterkit/TemplateBicep/* ./templates/iotedge-lorawan-starterkit/
sed -r -i 's/..\/iotedge-lorawan-starterkit\/TemplateBicep\/main.bicep/.\/iotedge-lorawan-starterkit\/main.bicep/g' ./templates/azuredeploy.bicep

- name: Generate ARM file
working-directory: arm-templates/templates
run: az bicep build --file azuredeploy.bicep --outfile azuredeploy.json

- name: Upload templates to release assets
uses: AButler/upload-release-assets@v2.0
with:
files: 'arm-templates/templates/*.json'
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Create PR for template updates
uses: peter-evans/create-pull-request@v4
with:
base: 'arm/main'
branch: 'arm/feature/update-templates'
path: 'arm-templates'
commit-message: 'Update templates from release.'
token: ${{ steps.generate_app_token.outputs.token }}
title: '[ARM Templates] Update templates from release'
labels: |
arm-templates
automated pr
team-reviewers: '@CGI-FR/azure-iot-portal-authors'
body: |
Automated changes to the Azure templates.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The template will deploy in your Azure subscription the Following resources:

1. Press on the button here below to start your Azure Deployment.

[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FCGI-FR%2FIoT-Hub-Portal%2Fmain%2Ftemplates%2Fazuredeploy.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FCGI-FR%2FIoT-Hub-Portal%2Fmain%2Ftemplates%2FazuredeployUI.json)
[![Deploy to Azure](https://aka.ms/deploytoazurebutton)](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FCGI-FR%2FIoT-Hub-Portal%2Farm%2Fmain%2Ftemplates%2Fazuredeploy.json/uiFormDefinitionUri/https%3A%2F%2Fraw.githubusercontent.com%2FCGI-FR%2FIoT-Hub-Portal%2Farm%2Fmain%2Ftemplates%2FazuredeployUI.json)

1. You will get to a page asking you to fill the following fields :
* **Resource Group**: A logical "folder" where all the template resource would be put into, just choose a meaningful name.
Expand Down
7 changes: 4 additions & 3 deletions src/AzureIoTHub.Portal.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{3CA1
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{9EF190B3-41E2-48E1-BA4E-E129589DD250}"
ProjectSection(SolutionItems) = preProject
..\.github\workflows\arm-ttk.yml = ..\.github\workflows\arm-ttk.yml
..\.github\workflows\awesome-ideas.yml = ..\.github\workflows\awesome-ideas.yml
..\.github\workflows\build.yml = ..\.github\workflows\build.yml
..\.github\workflows\codeql.yml = ..\.github\workflows\codeql.yml
Expand All @@ -35,10 +36,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{3F7A2982-4F0B-45F9-9FCA-923D5A7A1511}"
ProjectSection(SolutionItems) = preProject
..\templates\azuredeploy.json = ..\templates\azuredeploy.json
..\templates\azuredeploy.bicep = ..\templates\azuredeploy.bicep
..\templates\azuredeployUI.json = ..\templates\azuredeployUI.json
..\templates\portalDeployWithLoRa.json = ..\templates\portalDeployWithLoRa.json
..\templates\portalDeployWithoutLoRa.json = ..\templates\portalDeployWithoutLoRa.json
..\templates\portalDeployWithLoRa.bicep = ..\templates\portalDeployWithLoRa.bicep
..\templates\portalDeployWithoutLoRa.bicep = ..\templates\portalDeployWithoutLoRa.bicep
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATES", "ISSUE_TEMPLATES", "{4B89F192-EA33-4121-9809-D99621C40F3B}"
Expand Down
132 changes: 132 additions & 0 deletions templates/azuredeploy.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
@description('The Azure resources location')
param location string = resourceGroup().location

@description('Prefix used for resource names. Should be unique as this will also be used for domain names.')
param uniqueSolutionPrefix string

@description('PostgreSQL user')
param pgsqlAdminLogin string

@description('PostgreSQL password')
@secure()
param pgsqlAdminPassword string

@description('The Open ID Authority')
param openIdAuthority string

@description('The Open ID metadata Url from the Identity provider')
param openIdMetadataURL string

@description('The client ID for the B2C tenant')
param clientId string

@description('The API client ID for the B2C tenant')
param apiClientId string

@description('The name of the Edge gateway')
param edgeGatewayName string = 'TestLoRaWANGateway'

@description('Provision a final LoRa device in the IoT hub in addition to the gateway')
param deployDevice bool = true

@description('Provide the reset pin value of your gateway. Please refer to the doc if you are unfamiliar with the value')
param resetPin int = 2

@description('In what region is your gateway deployed?')
@allowed([
'AS923-1'
'AS923-2'
'AS923-3'
'AU915'
'CN470RP1'
'CN470RP2'
'EU863'
'US902'
])
param region string = 'EU863'

@description('[In Mbps] Custom SPI speed for your gateway, currently only supported for ARM gateways')
@allowed([
8
2
])
param spiSpeed int = 8

@description('SPI Dev version for x86 based gateway')
@allowed([
1
2
])
param spiDev int = 2

@description('Enable LoRaWAN feature?')
param isLoRaFeatureEnabled bool = true

@description('To enable Awesome-Ideas feature when set to true')
param ideasEnabled bool = false

@description('Url of Awesome-Ideas, to publish ideas submitted by users. Required when ideasEnabled is true')
param ideasUrl string = ''

@description('Authentication header to interact with Awesome-Ideas. Required when ideasEnabled is true')
param ideasAuthenticationHeader string = 'Ocp-Apim-Subscription-Key'

@description('Authentication token to interact with Awesome-Ideas. Required when ideasEnabled is true')
param ideasAuthenticationToken string = ''

var starterKitDeploymentName = 'lorawan-starter-kit'
var portalWithLoRaDeploymentName = 'iothub-portal-with-lora'
var portalWithoutLoRaDeploymentName = 'iothub-portal-without-lora'

module starterKitDeployment '../iotedge-lorawan-starterkit/TemplateBicep/main.bicep' = if (isLoRaFeatureEnabled) {
name: starterKitDeploymentName
params: {
location: location
uniqueSolutionPrefix: uniqueSolutionPrefix
edgeGatewayName: edgeGatewayName
deployDevice: deployDevice
resetPin: resetPin
region: region
spiSpeed: spiSpeed
spiDev: spiDev
}
}

module portalWithLoRaDeployment './portalDeployWithLoRa.bicep' = if (isLoRaFeatureEnabled) {
name: portalWithLoRaDeploymentName
params: {
location: location
uniqueSolutionPrefix: uniqueSolutionPrefix
pgsqlAdminLogin: pgsqlAdminLogin
pgsqlAdminPassword: pgsqlAdminPassword
openIdAuthority: openIdAuthority
openIdMetadataURL: openIdMetadataURL
apiClientId: apiClientId
clientId: clientId
ideasEnabled: ideasEnabled
ideasUrl: ideasUrl
ideasAuthenticationHeader: ideasAuthenticationHeader
ideasAuthenticationToken: ideasAuthenticationToken
}
dependsOn: [
starterKitDeployment
]
}

module portalWithoutLoRaDeployment './portalDeployWithoutLoRa.bicep' = if (!isLoRaFeatureEnabled) {
name: portalWithoutLoRaDeploymentName
params: {
location: location
uniqueSolutionPrefix: uniqueSolutionPrefix
pgsqlAdminLogin: pgsqlAdminLogin
pgsqlAdminPassword: pgsqlAdminPassword
openIdAuthority: openIdAuthority
openIdMetadataURL: openIdMetadataURL
apiClientId: apiClientId
clientId: clientId
ideasEnabled: ideasEnabled
ideasUrl: ideasUrl
ideasAuthenticationHeader: ideasAuthenticationHeader
ideasAuthenticationToken: ideasAuthenticationToken
}
}
Loading