Skip to content

Commit 7a1ceac

Browse files
committed
feat: linked backend
1 parent 8b6f3a0 commit 7a1ceac

File tree

6 files changed

+176
-41
lines changed

6 files changed

+176
-41
lines changed

.devcontainer/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node/.devcontainer/base.Dockerfile
2-
3-
# [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
4-
ARG VARIANT="16-bullseye"
1+
# [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
2+
ARG VARIANT=16-bullseye
53
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}
64

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

15-
# [Optional] Uncomment if you want to install more global node modules
16-
# RUN su node -c "npm install -g <your-package-list-here>"
13+
# [Optional] Uncomment if you want to install more global node packages
14+
# RUN su node -c "npm install -g <your-package-list -here>"

.devcontainer/base.Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# [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
2+
ARG VARIANT=16-bullseye
3+
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
4+
5+
# Install tslint, typescript. eslint is installed by javascript image
6+
ARG NODE_MODULES="tslint-to-eslint-config typescript"
7+
COPY library-scripts/meta.env /usr/local/etc/vscode-dev-containers
8+
RUN su node -c "umask 0002 && npm install -g ${NODE_MODULES}" \
9+
&& npm cache clean --force > /dev/null 2>&1
10+
11+
# [Optional] Uncomment this section to install additional OS packages.
12+
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
13+
# && apt-get -y install --no-install-recommends <your-package-list-here>
14+
15+
# [Optional] Uncomment if you want to install an additional version of node using nvm
16+
# ARG EXTRA_NODE_VERSION=10
17+
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

.devcontainer/devcontainer.json

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2-
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/typescript-node
33
{
4-
"name": "Node.js",
5-
"build": {
6-
"dockerfile": "Dockerfile",
7-
// Update 'VARIANT' to pick a Node version: 16, 14, 12.
8-
// Append -bullseye or -buster to pin to an OS version.
9-
// Use -bullseye variants on local arm64/Apple Silicon.
10-
"args": { "VARIANT": "16" }
11-
},
4+
"name": "Node.js & TypeScript",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Update 'VARIANT' to pick a Node version: 18, 16, 14.
8+
// Append -bullseye or -buster to pin to an OS version.
9+
// Use -bullseye variants on local on arm64/Apple Silicon.
10+
"args": {
11+
"VARIANT": "16-bullseye"
12+
}
13+
},
1214

13-
// Set *default* container specific settings.json values on container create.
14-
"settings": {},
15+
// Configure tool-specific properties.
16+
"customizations": {
17+
// Configure properties specific to VS Code.
18+
"vscode": {
19+
// Add the IDs of extensions you want installed when the container is created.
20+
"extensions": [
21+
"dbaeumer.vscode-eslint",
22+
"esbenp.prettier-vscode",
23+
"ms-azuretools.vscode-bicep"
24+
]
25+
}
26+
},
1527

16-
// Add the IDs of extensions you want installed when the container is created.
17-
"extensions": [
18-
"dbaeumer.vscode-eslint",
19-
"esbenp.prettier-vscode",
20-
"ms-azuretools.vscode-bicep"
21-
],
28+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
29+
// "forwardPorts": [],
2230

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

26-
// Use 'postCreateCommand' to run commands after the container is created.
27-
"postCreateCommand": "az bicep install",
28-
29-
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
30-
"remoteUser": "node",
31-
"features": {
32-
"azure-cli": "latest"
33-
}
34+
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
35+
"remoteUser": "node",
36+
"features": {
37+
"azure-cli": "latest"
38+
}
3439
}

.github/workflows/build-and-deploy.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ env:
1919
RESOURCE_GROUP: rg-blog-johnnyreilly-com
2020
LOCATION: westeurope
2121
STATICWEBAPPNAME: blog.johnnyreilly.com
22+
FUNCTIONAPPNAME: func-blog-johnnyreilly-com
23+
HOSTINGPLANNAME: ASP-rgblogjohnnyreillycom-a345
24+
STORAGEACCOUNTNAME: stblogjohnnyreilly
25+
CUSTOMDOMAINNAME: blog.johnnyreilly.com
2226
TAGS: '{"owner":"johnnyreilly", "email":"johnny_reilly@hotmail.com"}'
2327

2428
jobs:
@@ -109,10 +113,13 @@ jobs:
109113
--parameters \
110114
branch='main' \
111115
location='${{ env.LOCATION }}' \
112-
name='${{ env.STATICWEBAPPNAME }}' \
116+
staticWebAppName='${{ env.STATICWEBAPPNAME }}' \
117+
functionAppName='${{ env.FUNCTIONAPPNAME }}' \
118+
hostingPlanName='${{ env.HOSTINGPLANNAME }}' \
119+
storageAccountName='${{ env.STORAGEACCOUNTNAME }}' \
113120
tags='${{ env.TAGS }}' \
114121
repositoryToken='${{ secrets.WORKFLOW_TOKEN }}' \
115-
customDomainName='${{ env.STATICWEBAPPNAME }}'
122+
customDomainName='${{ env.CUSTOMDOMAINNAME }}'
116123
117124
- name: Static Web App - deploy infra
118125
id: static_web_app_deploy
@@ -127,10 +134,13 @@ jobs:
127134
--parameters \
128135
branch='main' \
129136
location='${{ env.LOCATION }}' \
130-
name='${{ env.STATICWEBAPPNAME }}' \
137+
staticWebAppName='${{ env.STATICWEBAPPNAME }}' \
138+
functionAppName='${{ env.FUNCTIONAPPNAME }}' \
139+
hostingPlanName='${{ env.HOSTINGPLANNAME }}' \
140+
storageAccountName='${{ env.STORAGEACCOUNTNAME }}' \
131141
tags='${{ env.TAGS }}' \
132142
repositoryToken='${{ secrets.WORKFLOW_TOKEN }}' \
133-
customDomainName='${{ env.STATICWEBAPPNAME }}'
143+
customDomainName='${{ env.CUSTOMDOMAINNAME }}'
134144
135145
- name: Static Web App - get API key for deployment
136146
id: static_web_app_apikey

infra/function.bicep

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
param functionAppName string
2+
param location string
3+
param hostingPlanName string
4+
param storageAccountName string
5+
param tags object
6+
7+
resource functionApp 'Microsoft.Web/sites@2022-03-01' = {
8+
name: functionAppName
9+
kind: 'functionapp,linux'
10+
location: location
11+
tags: tags
12+
properties: {
13+
siteConfig: {
14+
appSettings: [
15+
{
16+
name: 'FUNCTIONS_EXTENSION_VERSION'
17+
value: '~4'
18+
}
19+
{
20+
name: 'FUNCTIONS_WORKER_RUNTIME'
21+
value: 'node'
22+
}
23+
{
24+
name: 'AzureWebJobsStorage'
25+
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
26+
}
27+
{
28+
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
29+
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
30+
}
31+
{
32+
name: 'WEBSITE_CONTENTSHARE'
33+
value: '${toLower(functionAppName)}a6e3'
34+
}
35+
]
36+
cors: {
37+
allowedOrigins: [
38+
'https://portal.azure.com'
39+
]
40+
}
41+
use32BitWorkerProcess: false
42+
ftpsState: 'FtpsOnly'
43+
linuxFxVersion: 'Node|16'
44+
}
45+
serverFarmId: serverFarm.id
46+
clientAffinityEnabled: false
47+
httpsOnly: true
48+
}
49+
}
50+
51+
resource serverFarm 'Microsoft.Web/serverfarms@2022-03-01' = {
52+
name: hostingPlanName
53+
location: location
54+
kind: 'linux'
55+
tags: {}
56+
properties: {
57+
reserved: true
58+
}
59+
sku: {
60+
tier: 'Dynamic'
61+
name: 'Y1'
62+
}
63+
dependsOn: []
64+
}
65+
66+
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = {
67+
name: storageAccountName
68+
location: location
69+
tags: {}
70+
sku: {
71+
name: 'Standard_LRS'
72+
}
73+
properties: {
74+
supportsHttpsTrafficOnly: true
75+
minimumTlsVersion: 'TLS1_2'
76+
}
77+
kind: 'StorageV2'
78+
}
79+
80+
output functionAppResourceId string = functionApp.id

infra/main.bicep

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
param location string
22
param branch string
3-
param name string
3+
param staticWebAppName string
4+
param functionAppName string
5+
param hostingPlanName string
6+
param storageAccountName string
47
param tags object
58
@secure()
69
param repositoryToken string
710
param customDomainName string
811

12+
module functionApp 'function.bicep' = {
13+
name: 'functionApp'
14+
params: {
15+
location: location
16+
tags: tags
17+
functionAppName: functionAppName
18+
hostingPlanName: hostingPlanName
19+
storageAccountName: storageAccountName
20+
}
21+
}
22+
923
resource staticWebApp 'Microsoft.Web/staticSites@2021-02-01' = {
10-
name: name
24+
name: staticWebAppName
1125
location: location
1226
tags: tags
1327
sku: {
14-
name: 'Free'
15-
tier: 'Free'
28+
name: 'Standard'
29+
tier: 'Standard'
30+
// Free doesn't work with linked backends
31+
// name: 'Free'
32+
// tier: 'Free'
1633
}
1734
properties: {
1835
repositoryUrl: 'https://github.com/johnnyreilly/blog.johnnyreilly.com'
@@ -33,6 +50,14 @@ resource customDomain 'Microsoft.Web/staticSites/customDomains@2021-02-01' = {
3350
properties: {}
3451
}
3552

53+
resource staticWebAppBackend 'Microsoft.Web/staticSites/linkedBackends@2022-03-01' = {
54+
name: '${staticWebAppName}/backend'
55+
properties: {
56+
backendResourceId: functionApp.outputs.functionAppResourceId
57+
region: location
58+
}
59+
}
60+
3661
output staticWebAppDefaultHostName string = staticWebApp.properties.defaultHostname // eg gentle-bush-0db02ce03.azurestaticapps.net
3762
output staticWebAppId string = staticWebApp.id
3863
output staticWebAppName string = staticWebApp.name

0 commit comments

Comments
 (0)