Skip to content

Commit 8a601fd

Browse files
authored
feat: Add new flags for Function runtime and Function version (#562)
* feat: Add new flags for Function runtime and Function version * feat: add func language and version support in swa init * test: modify tests for new flags * nit changes * feat: add select option for apiLanguage flags * more changes * fix tests * Change flag to av * refactor: moved functions versions to core * Merge main to current branch * chore: resolve comments * nit: revert const changes * chore: merge main to current * chore: resolve merge conflicts * fix: index.ts in tests * feat: Added support for new languages and versions * nit: resolve comments * fix: dotnetIsolated naming * refactor: added utils functions * nit: add default versions
1 parent 97da365 commit 8a601fd

21 files changed

Lines changed: 439 additions & 35 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ Breaking Change section should start with the phrase "BREAKING CHANGE: " followe
362362
Similarly, a Deprecation section should start with "DEPRECATED: " followed by a short description of what is deprecated, a blank line, and a detailed description of the deprecation that also mentions the recommended update path.
363363

364364
### Merging Pull requests (For Code owners)
365+
365366
While merging pull requests, the following guidelines should be followed:
366367

367368
- Before merging, make sure there is at least one approval from the Code-owners.

docs/www/docs/cli/env-vars.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,19 @@ title: Environment Variables
3434

3535
## Deploy settings
3636

37-
| Environment Variable | Purpose | Read Only? | Default Value |
38-
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------- | ------------- |
39-
| SWA_CLI_APP_NAME | Project name | | |
40-
| SWA_CLI_DEPLOYMENT_TOKEN | Secret token used to authenticate with the Static Web Apps | | |
41-
| SWA_CLI_DEPLOY_DRY_RUN | Simulate a deploy process without actually running it (`true` or `false`) | | `false` |
42-
| SWA_CLI_DEPLOY_BINARY_VERSION | Deployment binary version to use | | `stable` |
43-
| SWA_CLI_DEPLOY_BINARY | Absoluate path to the deploy binary | Yes | |
44-
| SWA_CLI_DEPLOY_ENV | the type of deployment environment where to deploy the project | | `preview` |
37+
| Environment Variable | Purpose | Read Only? | Default Value |
38+
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------- | ------------- |
39+
| SWA_CLI_APP_NAME | Project name | | |
40+
| SWA_CLI_DEPLOYMENT_TOKEN | Secret token used to authenticate with the Static Web Apps | | |
41+
| SWA_CLI_DEPLOY_DRY_RUN | Simulate a deploy process without actually running it (`true` or `false`) | | `false` |
42+
| SWA_CLI_DEPLOY_BINARY_VERSION | Deployment binary version to use | | `stable` |
43+
| SWA_CLI_DEPLOY_BINARY | Absoluate path to the deploy binary | Yes | |
44+
| SWA_CLI_DEPLOY_ENV | the type of deployment environment where to deploy the project | | `preview` |
4545
| AZURE_REGION_LOCATION | Azure region where to deploy the project. Available regions are: `westus2,centralus,eastus2,westeurope,eastasia` | | `westus2` |
46-
| AZURE_RESOURCE_GROUP | Azure resource group | | |
47-
| AZURE_SUBSCRIPTION_ID | Azure subscription ID | | |
46+
| AZURE_RESOURCE_GROUP | Azure resource group | | |
47+
| AZURE_SUBSCRIPTION_ID | Azure subscription ID | | |
48+
| SWA_CLI_API_LANGUAGE | Runtime Language of the function | | `node` |
49+
| SWA_CLI_API_VERSION | Version of the function runtime language | | `16` |
4850

4951
## Runtime settings
5052

docs/www/docs/cli/swa-deploy.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ To deploy both the front-end app and an API to Azure Static Web Apps, use the fo
7272

7373
1. If your front-end application requires a build step, run [`swa build`](./swa-build) or refer to your application build instructions.
7474

75-
2. Make sure the[ API language runtime version](https://docs.microsoft.com/en-us/azure/static-web-apps/configuration#platform) in the `staticwebapp.config.json` file is set correctly, for example:
75+
2. Use the flags `--api-language` and `--api-version` to specify the language and the runtime version of the backend api.
76+
77+
```json
78+
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
79+
```
80+
81+
Alternatively you can [configure](https://docs.microsoft.com/en-us/azure/static-web-apps/configuration#platform) the `apiRuntime` in the `staticwebapp.config.json` file
7682

7783
```json
7884
{
@@ -157,6 +163,8 @@ Here are the options you can use with `swa deploy`:
157163
- `-a, --app-location <path>`: the folder containing the source code of the front-end application (default: "`.`")
158164
- `-i, --api-location <path>`: the folder containing the source code of the API application
159165
- `-O, --output-location <path>`: the folder containing the built source of the front-end application. The path is relative to `--app-location` (default: "`.`")
166+
- `--api-language <apiLanguage>`: the runtime language of the function (default: "`node`")
167+
- `--api-version <apiVersion>`: the version of the function runtime language (default: "`16`")
160168
- `-w, --swa-config-location <swaConfigLocation>`: the directory where the staticwebapp.config.json file is located
161169
- `-d, --deployment-token <secret>`: the secret token used to authenticate with the Static Web Apps
162170
- `-dr, --dry-run`: simulate a deploy process without actually running it (default: `false`)
@@ -200,6 +208,12 @@ Print the deployment token
200208
swa deploy --print-token
201209
```
202210

211+
Provide function language and version
212+
213+
```bash
214+
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
215+
```
216+
203217
Deploy to a specific environment
204218

205219
```bash

docs/www/docs/contribute/3-contributors.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ Thanks goes to these wonderful people 🎉
7777
<!-- ALL-CONTRIBUTORS-LIST:END -->
7878

7979
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
80+
8081
[![All Contributors](https://img.shields.io/badge/all_contributors-37-orange.svg?style=flat-square)](#contributors-)
82+
8183
<!-- ALL-CONTRIBUTORS-BADGE:END -->
8284

8385
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

docs/www/docs/contribute/99-troubleshooting.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This page lists frequently-asked questions and solutions to help troubleshoot co
1414

1515
### Context
1616

17+
`swa deploy` currently has a small bug which is being actively worked on by the team. When a user tries to `swa deploy` from within the `app-location`, the deploy command currently fails with an unknown error. This is being tracked in GitHub issue #[514]((https://github.com/Azure/static-web-apps-cli/issues/514).
1718
`swa deploy` currently has a small bug which is being actively worked on by the team. When a user tries to `swa deploy` from within the `app-location`, the deploy command currently fails with an unknown error. This is being tracked in GitHub issue #[514]((https://github.com/Azure/static-web-apps-cli/issues/514).
1819

1920
### Solution
@@ -24,6 +25,7 @@ While the team is currently working on the fix, we recommend users to use the ot
2425

2526
### Context
2627

28+
When using `swa login`, the flag `--use-keychain` is enabled by default because we encrypt and store your credentials in your native Keychain (aka. the built-in password manager of your operating system). This operation depends on a system dependency called `libsecret`. If your system doesn't come bundled `libsecret` (most systems do provide it by default), you will then encounter this error.
2729
When using `swa login`, the flag `--use-keychain` is enabled by default because we encrypt and store your credentials in your native Keychain (aka. the built-in password manager of your operating system). This operation depends on a system dependency called `libsecret`. If your system doesn't come bundled `libsecret` (most systems do provide it by default), you will then encounter this error.
2830

2931
### Why do I need to `swa login`?
@@ -45,6 +47,201 @@ In order to avoid this issue, you have a few options:
4547

4648
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
4749

50+
- blob.core.windows.net
51+
- azurestaticapps.net
52+
- swalocaldeploy.azureedge.net
53+
54+
## `Unable to download StaticSitesClient binary (File Not Found 404 - 403)`
55+
56+
### Context
57+
58+
SWA CLI uses an external binary `StaticSitesClient` to deploy apps to Azure Static Web Apps. This binary is downloaded on demand when users run `swa deploy` for the first time. SWA CLI then detects the host OS in order to download the right binary version from https://swalocaldeploy.azureedge.net/downloads/versions.json.
59+
60+
It can happen that the host firewall can block downloading these binaries. If users can't configure the firewall rules to allow SWA CLI accessing https://swalocaldeploy.azureedge.net/, as a workaround, they can manually download `StaticSitesClient`.
61+
62+
### Solution
63+
64+
1. Visit https://swalocaldeploy.azureedge.net/downloads/versions.json
65+
2. Copy the `stable` JSON content, for eg:
66+
67+
```json
68+
{
69+
"version": "stable",
70+
"buildId": "1.0.020761",
71+
"publishDate": "2022-09-07T17:34:35.4261936Z",
72+
"files": {
73+
"linux-x64": {
74+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient",
75+
"sha": "871ae9f154ddb8123e24c507e39dfc11c99f34815e59b178051a6e44a870e308"
76+
},
77+
"win-x64": {
78+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe",
79+
"sha": "360b76959c68cc0865b1aea144c8eb2aa413f4856e55c781a83bd7e1ad352362"
80+
},
81+
"osx-x64": {
82+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient",
83+
"sha": "1a90511003609af378ff3628feaf3115f9d7e335085a925045e9f206359fdb90"
84+
}
85+
}
86+
}
87+
```
88+
89+
3. Based on your operating system, download the right binary from the provided URLs:
90+
1. Linux: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient
91+
2. Windows: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe
92+
3. macOS: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient
93+
1. Copy this binary to `$HOME/.swa/deploy/VERSION/StaticSiteClient` (add `.exe` for Windows). For eg:
94+
`/home/USER/.swa/deploy/1.0.020761/StaticSiteClient`
95+
1. Create a file at `$HOME/.swa/deploy/StaticSitesClient.json` with the following content:
96+
97+
```json
98+
{
99+
"metadata": PASTE STABLE JSON CONTENT,
100+
"binary": ABSOLUTE PATH TO STATIC SITE CLIENT BINARY,
101+
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
102+
}
103+
```
104+
105+
For eg:
106+
107+
```json
108+
{
109+
"metadata": {
110+
"version": "stable",
111+
"buildId": "1.0.020761",
112+
...
113+
},
114+
"binary":"/home/USER/.swa/deploy/1.0.020761/StaticSitesClient",
115+
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
116+
}
117+
```
118+
119+
**IMPORTANT: Make sure the `StaticSitesClient.json#checksum` and `StaticSitesClient.json#metadata.files.[OS].sha` values match!** 6. For Linux and macOS, run `chmod +x /home/USER/.swa/deploy/1.0.020761/StaticSitesClient` 7. Run `swa deploy --verbose silly` and make sure `SWA_CLI_DEPLOY_BINARY` is set correctly. If everything was configured correctly, the deploy should work.
120+
121+
How to compute SHA256 checksum:
122+
123+
1. On Windows using Powershell:
124+
125+
```
126+
PS C:\Users\USER> (Get-fileHash -Algorithm SHA256 .\.swa\deploy\VERSION\StaticSitesClient.exe).Hash.ToLower()
127+
```
128+
129+
2. On Linux:
130+
131+
```
132+
➜ sha256sum ~/.swa/deploy/VERSION/StaticSitesClient | head -c 64
133+
```
134+
135+
3. On macOS:
136+
137+
```
138+
➜ openssl sha256 ~/.swa/deploy/VERSION/StaticSitesClient | awk '{print $2}'
139+
```
140+
141+
## SWA CLI - Domains that need Firewall access
142+
143+
### Context
144+
145+
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
146+
147+
- blob.core.windows.net
148+
- azurestaticapps.net
149+
- swalocaldeploy.azureedge.net
150+
- dataapibuilder.azureedge.net
151+
152+
## `Unable to download StaticSitesClient binary (File Not Found 404 - 403)`
153+
154+
### Context
155+
156+
SWA CLI uses an external binary `StaticSitesClient` to deploy apps to Azure Static Web Apps. This binary is downloaded on demand when users run `swa deploy` for the first time. SWA CLI then detects the host OS in order to download the right binary version from https://swalocaldeploy.azureedge.net/downloads/versions.json.
157+
158+
It can happen that the host firewall can block downloading these binaries. If users can't configure the firewall rules to allow SWA CLI accessing https://swalocaldeploy.azureedge.net/, as a workaround, they can manually download `StaticSitesClient`.
159+
160+
### Solution
161+
162+
1. Visit https://swalocaldeploy.azureedge.net/downloads/versions.json
163+
2. Copy the `stable` JSON content, for eg:
164+
165+
```json
166+
{
167+
"version": "stable",
168+
"buildId": "1.0.020761",
169+
"publishDate": "2022-09-07T17:34:35.4261936Z",
170+
"files": {
171+
"linux-x64": {
172+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient",
173+
"sha": "871ae9f154ddb8123e24c507e39dfc11c99f34815e59b178051a6e44a870e308"
174+
},
175+
"win-x64": {
176+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe",
177+
"sha": "360b76959c68cc0865b1aea144c8eb2aa413f4856e55c781a83bd7e1ad352362"
178+
},
179+
"osx-x64": {
180+
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient",
181+
"sha": "1a90511003609af378ff3628feaf3115f9d7e335085a925045e9f206359fdb90"
182+
}
183+
}
184+
}
185+
```
186+
187+
3. Based on your operating system, download the right binary from the provided URLs:
188+
1. Linux: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient
189+
2. Windows: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe
190+
3. macOS: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient
191+
1. Copy this binary to `$HOME/.swa/deploy/VERSION/StaticSiteClient` (add `.exe` for Windows). For eg:
192+
`/home/USER/.swa/deploy/1.0.020761/StaticSiteClient`
193+
1. Create a file at `$HOME/.swa/deploy/StaticSitesClient.json` with the following content:
194+
195+
```json
196+
{
197+
"metadata": PASTE STABLE JSON CONTENT,
198+
"binary": ABSOLUTE PATH TO STATIC SITE CLIENT BINARY,
199+
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
200+
}
201+
```
202+
203+
For eg:
204+
205+
```json
206+
{
207+
"metadata": {
208+
"version": "stable",
209+
"buildId": "1.0.020761",
210+
...
211+
},
212+
"binary":"/home/USER/.swa/deploy/1.0.020761/StaticSitesClient",
213+
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
214+
}
215+
```
216+
217+
**IMPORTANT: Make sure the `StaticSitesClient.json#checksum` and `StaticSitesClient.json#metadata.files.[OS].sha` values match!** 6. For Linux and macOS, run `chmod +x /home/USER/.swa/deploy/1.0.020761/StaticSitesClient` 7. Run `swa deploy --verbose silly` and make sure `SWA_CLI_DEPLOY_BINARY` is set correctly. If everything was configured correctly, the deploy should work.
218+
219+
How to compute SHA256 checksum:
220+
221+
1. On Windows using Powershell:
222+
223+
```
224+
PS C:\Users\USER> (Get-fileHash -Algorithm SHA256 .\.swa\deploy\VERSION\StaticSitesClient.exe).Hash.ToLower()
225+
```
226+
227+
2. On Linux:
228+
229+
```
230+
➜ sha256sum ~/.swa/deploy/VERSION/StaticSitesClient | head -c 64
231+
```
232+
233+
3. On macOS:
234+
235+
```
236+
➜ openssl sha256 ~/.swa/deploy/VERSION/StaticSitesClient | awk '{print $2}'
237+
```
238+
239+
## SWA CLI - Domains that need Firewall access
240+
241+
### Context
242+
243+
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
244+
48245
- blob.core.windows.net
49246
- azurestaticapps.net
50247
- swalocaldeploy.azureedge.net

docs/www/docs/use/1-install.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ sidebar_position: 1
77
You can install the Static Web Apps CLI using [`npm`](https://docs.npmjs.com/cli/v6/commands/npm-install), [`yarn`](https://classic.yarnpkg.com/lang/en/docs/cli/install/) or [`pnpm`](https://pnpm.io/cli/install).
88

99
:::info Note
10-
SWA CLI currently only supports runtime Node versions 16 and below. Kindly check and set your runtime to the same in order to have a smooth SWA CLI experience.
10+
SWA CLI currently only supports runtime Node versions 16 and below. Kindly check and set your runtime to the same in order to have a smooth SWA CLI experience.
1111

1212
:::
1313

schema/swa-cli.config.schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
"description": "The folder containing the source code of the API application",
250250
"type": "string"
251251
},
252-
"dataApiLocation":{
252+
"dataApiLocation": {
253253
"description": "The folder containing configurations for database connections",
254254
"type": "string"
255255
},
@@ -268,6 +268,14 @@
268268
"dryRun": {
269269
"description": "Simulate a deploy process without actually running it",
270270
"type": "boolean"
271+
},
272+
"apiLanguage": {
273+
"description": "The runtime language of the API",
274+
"type": "string"
275+
},
276+
"apiVersion": {
277+
"description": "The version of the API runtime language",
278+
"type": "string"
271279
}
272280
},
273281
"type": "object"

0 commit comments

Comments
 (0)