Adding support for azure static webapp

Signed-off-by: Sujay Pillai <sujayopillai@gmail.com>
This commit is contained in:
Sujay Pillai 2021-09-10 12:41:45 +08:00 committed by Sam Alba
parent af1d06f503
commit 439fb4ee82
5 changed files with 168 additions and 0 deletions

View File

@ -12,6 +12,7 @@
- [aws/s3](./aws/s3.md) - AWS Simple Storage Service - [aws/s3](./aws/s3.md) - AWS Simple Storage Service
- [azure](./azure/README.md) - Azure base package - [azure](./azure/README.md) - Azure base package
- [azure/resourcegroup](./azure/resourcegroup.md) - - - [azure/resourcegroup](./azure/resourcegroup.md) - -
- [azure/staticwebapp](./azure/staticwebapp.md) - -
- [azure/storage](./azure/storage.md) - - - [azure/storage](./azure/storage.md) - -
- [dagger](./dagger/README.md) - Dagger core types - [dagger](./dagger/README.md) - Dagger core types
- [dagger/op](./dagger/op.md) - op: low-level operations for Dagger processing pipelines - [dagger/op](./dagger/op.md) - op: low-level operations for Dagger processing pipelines

View File

@ -0,0 +1,53 @@
---
sidebar_label: staticwebapp
---
# alpha.dagger.io/azure/staticwebapp
```cue
import "alpha.dagger.io/azure/staticwebapp"
```
## staticwebapp.#StaticWebApp
Create a static web app
### staticwebapp.#StaticWebApp Inputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*config.tenantId* | `dagger.#Secret` |AZURE tenant id |
|*config.subscriptionId* | `dagger.#Secret` |AZURE subscription id |
|*config.appId* | `dagger.#Secret` |AZURE app id for the service principal used |
|*config.password* | `dagger.#Secret` |AZURE password for the service principal used |
|*rgName* | `string` |ResourceGroup name in which to create static webapp |
|*stappLocation* | `string` |StaticWebApp location |
|*stappName* | `string` |StaticWebApp name |
|*remote* | `string` |GitHubRepository URL |
|*ref* | `*"main" \| string` |GitHub Branch |
|*appLocation* | `*"/" \| string` |Location of your application code |
|*buildLocation* | `*"build" \| string` |Location of your build artifacts |
|*authToken* | `dagger.#Secret` |GitHub Personal Access Token |
|*ctr.image.config.tenantId* | `dagger.#Secret` |AZURE tenant id |
|*ctr.image.config.subscriptionId* | `dagger.#Secret` |AZURE subscription id |
|*ctr.image.config.appId* | `dagger.#Secret` |AZURE app id for the service principal used |
|*ctr.image.config.password* | `dagger.#Secret` |AZURE password for the service principal used |
|*ctr.image.image.from* | `"mcr.microsoft.com/azure-cli:2.27.1@sha256:1e117183100c9fce099ebdc189d73e506e7b02d2b73d767d3fc07caee72f9fb1"` |Remote ref (example: "index.docker.io/alpine:latest") |
|*ctr.image.secret."/run/secrets/appId"* | `dagger.#Secret` |- |
|*ctr.image.secret."/run/secrets/password"* | `dagger.#Secret` |- |
|*ctr.image.secret."/run/secrets/tenantId"* | `dagger.#Secret` |- |
|*ctr.image.secret."/run/secrets/subscriptionId"* | `dagger.#Secret` |- |
|*ctr.env.AZURE_DEFAULTS_GROUP* | `string` |- |
|*ctr.env.AZURE_DEFAULTS_LOCATION* | `string` |- |
|*ctr.env.AZURE_STATICWEBAPP_NAME* | `string` |- |
|*ctr.env.GIT_URL* | `string` |- |
|*ctr.env.GIT_BRANCH* | `*"main" \| string` |- |
|*ctr.env.APP_LOCATION* | `*"/" \| string` |- |
|*ctr.env.BUILD_LOCATION* | `*"build" \| string` |- |
|*ctr.secret."/run/secrets/git_pat"* | `dagger.#Secret` |- |
### staticwebapp.#StaticWebApp Outputs
| Name | Type | Description |
| ------------- |:-------------: |:-------------: |
|*defaultHostName* | `string` |DefaultHostName generated by Azure |

View File

@ -0,0 +1,79 @@
package staticwebapp
import (
"alpha.dagger.io/azure"
"alpha.dagger.io/os"
"alpha.dagger.io/dagger"
)
// Create a static web app
#StaticWebApp: {
// Azure Config
config: azure.#Config
// ResourceGroup name in which to create static webapp
rgName: string & dagger.#Input
// StaticWebApp location
stappLocation: string & dagger.#Input
// StaticWebApp name
stappName: string & dagger.#Input
// GitHubRepository URL
remote: string & dagger.#Input
// GitHub Branch
ref: *"main" | string & dagger.#Input
// Location of your application code
appLocation: *"/" | string & dagger.#Input
// Location of your build artifacts
buildLocation: *"build" | string & dagger.#Input
// GitHub Personal Access Token
authToken: dagger.#Secret & dagger.#Input
// DefaultHostName generated by Azure
defaultHostName: string & dagger.#Output
// Container image
ctr: os.#Container & {
image: azure.#CLI & {
"config": config
}
always: true
command: #"""
az staticwebapp create -n "$AZURE_STATICWEBAPP_NAME" \
-g "$AZURE_DEFAULTS_GROUP" \
-l "$AZURE_DEFAULTS_LOCATION" \
-s "$GIT_URL" \
-b "$GIT_BRANCH" \
-t "$(cat /run/secrets/git_pat)" \
--app-location "$APP_LOCATION" \
--output-location "$BUILD_LOCATION" | jq -r '.defaultHostname' | tr -d "\n" > /defaultHostName
"""#
secret: "/run/secrets/git_pat": authToken
env: {
AZURE_DEFAULTS_GROUP: rgName
AZURE_DEFAULTS_LOCATION: stappLocation
AZURE_STATICWEBAPP_NAME: stappName
GIT_URL: remote
GIT_BRANCH: ref
APP_LOCATION: appLocation
BUILD_LOCATION: buildLocation
}
}
// DefaultHostName generated by Azure
defaultHostName: ({
os.#File & {
from: ctr
path: "/defaultHostName"
}
}).contents
}

View File

@ -0,0 +1,30 @@
package staticwebapp
import (
"alpha.dagger.io/azure"
"alpha.dagger.io/azure/resourcegroup"
"alpha.dagger.io/azure/staticwebapp"
"alpha.dagger.io/random"
"strings"
)
TestConfig: azConfig: azure.#Config & {
}
TestSuffix: random.#String & {
seed: "azrg"
}
TestRG: resourcegroup.#ResourceGroup & {
config: TestConfig.azConfig
rgName: "rg-test-\(TestSuffix.out)"
rgLocation: "eastus2"
}
TestSWA: staticwebapp.#StaticWebApp & {
config: TestRG.config
rgName: "\(strings.Split(TestRG.id, "/")[4])"
stappLocation: "eastus2"
stappName: "stapp-test-\(TestSuffix.out)"
remote: "https://github.com/sujaypillai/todoapp"
}

View File

@ -253,3 +253,8 @@ setup() {
assert_success assert_success
assert_output "\"Healthy\"" assert_output "\"Healthy\""
} }
@test "azure-stapp" {
skip "Azure CI infra not implemented yet - manually tested and working"
#dagger -e azure-stapp up
}