Skip to content

Commit

Permalink
feat: linked backends
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyreilly committed Oct 14, 2022
1 parent 8b6f3a0 commit 0e5db6a
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 41 deletions.
10 changes: 4 additions & 6 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node/.devcontainer/base.Dockerfile

# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 16, 14, 12, 16-bullseye, 14-bullseye, 12-bullseye, 16-buster, 14-buster, 12-buster
ARG VARIANT="16-bullseye"
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=16-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
Expand All @@ -12,5 +10,5 @@ FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node modules
# RUN su node -c "npm install -g <your-package-list-here>"
# [Optional] Uncomment if you want to install more global node packages
# RUN su node -c "npm install -g <your-package-list -here>"
17 changes: 17 additions & 0 deletions .devcontainer/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [Choice] Node.js version (use -bullseye variants on local arm64/Apple Silicon): 18, 16, 14, 18-bullseye, 16-bullseye, 14-bullseye, 18-buster, 16-buster, 14-buster
ARG VARIANT=16-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}

# Install tslint, typescript. eslint is installed by javascript image
ARG NODE_MODULES="tslint-to-eslint-config typescript"
COPY library-scripts/meta.env /usr/local/etc/vscode-dev-containers
RUN su node -c "umask 0002 && npm install -g ${NODE_MODULES}" \
&& npm cache clean --force > /dev/null 2>&1

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"
59 changes: 32 additions & 27 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/typescript-node
{
"name": "Node.js",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local arm64/Apple Silicon.
"args": { "VARIANT": "16" }
},
"name": "Node.js & TypeScript",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 18, 16, 14.
// Append -bullseye or -buster to pin to an OS version.
// Use -bullseye variants on local on arm64/Apple Silicon.
"args": {
"VARIANT": "16-bullseye"
}
},

// Set *default* container specific settings.json values on container create.
"settings": {},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-azuretools.vscode-bicep"
]
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"ms-azuretools.vscode-bicep"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "az bicep install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"azure-cli": "latest"
}
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",
"features": {
"azure-cli": "latest"
}
}
18 changes: 14 additions & 4 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ env:
RESOURCE_GROUP: rg-blog-johnnyreilly-com
LOCATION: westeurope
STATICWEBAPPNAME: blog.johnnyreilly.com
FUNCTIONAPPNAME: func-blog-johnnyreilly-com
HOSTINGPLANNAME: ASP-rgblogjohnnyreillycom-a345
STORAGEACCOUNTNAME: stblogjohnnyreilly
CUSTOMDOMAINNAME: blog.johnnyreilly.com
TAGS: '{"owner":"johnnyreilly", "email":"[email protected]"}'

jobs:
Expand Down Expand Up @@ -109,10 +113,13 @@ jobs:
--parameters \
branch='main' \
location='${{ env.LOCATION }}' \
name='${{ env.STATICWEBAPPNAME }}' \
staticWebAppName='${{ env.STATICWEBAPPNAME }}' \
functionAppName='${{ env.FUNCTIONAPPNAME }}' \
hostingPlanName='${{ env.HOSTINGPLANNAME }}' \
storageAccountName='${{ env.STORAGEACCOUNTNAME }}' \
tags='${{ env.TAGS }}' \
repositoryToken='${{ secrets.WORKFLOW_TOKEN }}' \
customDomainName='${{ env.STATICWEBAPPNAME }}'
customDomainName='${{ env.CUSTOMDOMAINNAME }}'
- name: Static Web App - deploy infra
id: static_web_app_deploy
Expand All @@ -127,10 +134,13 @@ jobs:
--parameters \
branch='main' \
location='${{ env.LOCATION }}' \
name='${{ env.STATICWEBAPPNAME }}' \
staticWebAppName='${{ env.STATICWEBAPPNAME }}' \
functionAppName='${{ env.FUNCTIONAPPNAME }}' \
hostingPlanName='${{ env.HOSTINGPLANNAME }}' \
storageAccountName='${{ env.STORAGEACCOUNTNAME }}' \
tags='${{ env.TAGS }}' \
repositoryToken='${{ secrets.WORKFLOW_TOKEN }}' \
customDomainName='${{ env.STATICWEBAPPNAME }}'
customDomainName='${{ env.CUSTOMDOMAINNAME }}'
- name: Static Web App - get API key for deployment
id: static_web_app_apikey
Expand Down
80 changes: 80 additions & 0 deletions infra/function.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
param functionAppName string
param location string
param hostingPlanName string
param storageAccountName string
param tags object

resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
name: functionAppName
kind: 'functionapp,linux'
location: location
tags: tags
properties: {
siteConfig: {
appSettings: [
{
name: 'FUNCTIONS_EXTENSION_VERSION'
value: '~4'
}
{
name: 'FUNCTIONS_WORKER_RUNTIME'
value: 'node'
}
{
name: 'AzureWebJobsStorage'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
}
{
name: 'WEBSITE_CONTENTSHARE'
value: '${toLower(functionAppName)}a6e3'
}
]
cors: {
allowedOrigins: [
'https://portal.azure.com'
]
}
use32BitWorkerProcess: false
ftpsState: 'FtpsOnly'
linuxFxVersion: 'Node|16'
}
serverFarmId: serverFarm.id
clientAffinityEnabled: false
httpsOnly: true
}
}

resource serverFarm 'Microsoft.Web/serverfarms@2022-03-01' = {
name: hostingPlanName
location: location
kind: 'linux'
tags: {}
properties: {
reserved: true
}
sku: {
tier: 'Dynamic'
name: 'Y1'
}
dependsOn: []
}

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
name: storageAccountName
location: location
tags: {}
sku: {
name: 'Standard_LRS'
}
properties: {
supportsHttpsTrafficOnly: true
minimumTlsVersion: 'TLS1_2'
}
kind: 'StorageV2'
}

output functionAppResourceId string = functionApp.id
33 changes: 29 additions & 4 deletions infra/main.bicep
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
param location string
param branch string
param name string
param staticWebAppName string
param functionAppName string
param hostingPlanName string
param storageAccountName string
param tags object
@secure()
param repositoryToken string
param customDomainName string

module functionApp 'function.bicep' = {
name: 'functionApp'
params: {
location: location
tags: tags
functionAppName: functionAppName
hostingPlanName: hostingPlanName
storageAccountName: storageAccountName
}
}

resource staticWebApp 'Microsoft.Web/staticSites@2021-02-01' = {
name: name
name: staticWebAppName
location: location
tags: tags
sku: {
name: 'Free'
tier: 'Free'
name: 'Standard'
tier: 'Standard'
// Free doesn't work with linked backends
// name: 'Free'
// tier: 'Free'
}
properties: {
repositoryUrl: 'https://github.com/johnnyreilly/blog.johnnyreilly.com'
Expand All @@ -33,6 +50,14 @@ resource customDomain 'Microsoft.Web/staticSites/customDomains@2021-02-01' = {
properties: {}
}

resource staticWebAppBackend 'Microsoft.Web/staticSites/linkedBackends@2022-03-01' = {
name: '${staticWebAppName}/backend'
properties: {
backendResourceId: functionApp.outputs.functionAppResourceId
region: location
}
}

output staticWebAppDefaultHostName string = staticWebApp.properties.defaultHostname // eg gentle-bush-0db02ce03.azurestaticapps.net
output staticWebAppId string = staticWebApp.id
output staticWebAppName string = staticWebApp.name

0 comments on commit 0e5db6a

Please sign in to comment.