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
This commit is contained in:
Родитель
97da365490
Коммит
8a601fdc11
|
@ -362,6 +362,7 @@ Breaking Change section should start with the phrase "BREAKING CHANGE: " followe
|
|||
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.
|
||||
|
||||
### Merging Pull requests (For Code owners)
|
||||
|
||||
While merging pull requests, the following guidelines should be followed:
|
||||
|
||||
- Before merging, make sure there is at least one approval from the Code-owners.
|
||||
|
|
|
@ -35,7 +35,7 @@ title: Environment Variables
|
|||
## Deploy settings
|
||||
|
||||
| Environment Variable | Purpose | Read Only? | Default Value |
|
||||
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------- | ------------- |
|
||||
| ----------------------------- | ---------------------------------------------------------------------------------------------------------------- | ---------- | ------------- |
|
||||
| SWA_CLI_APP_NAME | Project name | | |
|
||||
| SWA_CLI_DEPLOYMENT_TOKEN | Secret token used to authenticate with the Static Web Apps | | |
|
||||
| SWA_CLI_DEPLOY_DRY_RUN | Simulate a deploy process without actually running it (`true` or `false`) | | `false` |
|
||||
|
@ -45,6 +45,8 @@ title: Environment Variables
|
|||
| AZURE_REGION_LOCATION | Azure region where to deploy the project. Available regions are: `westus2,centralus,eastus2,westeurope,eastasia` | | `westus2` |
|
||||
| AZURE_RESOURCE_GROUP | Azure resource group | | |
|
||||
| AZURE_SUBSCRIPTION_ID | Azure subscription ID | | |
|
||||
| SWA_CLI_API_LANGUAGE | Runtime Language of the function | | `node` |
|
||||
| SWA_CLI_API_VERSION | Version of the function runtime language | | `16` |
|
||||
|
||||
## Runtime settings
|
||||
|
||||
|
|
|
@ -72,7 +72,13 @@ To deploy both the front-end app and an API to Azure Static Web Apps, use the fo
|
|||
|
||||
1. If your front-end application requires a build step, run [`swa build`](./swa-build) or refer to your application build instructions.
|
||||
|
||||
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:
|
||||
2. Use the flags `--api-language` and `--api-version` to specify the language and the runtime version of the backend api.
|
||||
|
||||
```json
|
||||
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
|
||||
```
|
||||
|
||||
Alternatively you can [configure](https://docs.microsoft.com/en-us/azure/static-web-apps/configuration#platform) the `apiRuntime` in the `staticwebapp.config.json` file
|
||||
|
||||
```json
|
||||
{
|
||||
|
@ -157,6 +163,8 @@ Here are the options you can use with `swa deploy`:
|
|||
- `-a, --app-location <path>`: the folder containing the source code of the front-end application (default: "`.`")
|
||||
- `-i, --api-location <path>`: the folder containing the source code of the API application
|
||||
- `-O, --output-location <path>`: the folder containing the built source of the front-end application. The path is relative to `--app-location` (default: "`.`")
|
||||
- `--api-language <apiLanguage>`: the runtime language of the function (default: "`node`")
|
||||
- `--api-version <apiVersion>`: the version of the function runtime language (default: "`16`")
|
||||
- `-w, --swa-config-location <swaConfigLocation>`: the directory where the staticwebapp.config.json file is located
|
||||
- `-d, --deployment-token <secret>`: the secret token used to authenticate with the Static Web Apps
|
||||
- `-dr, --dry-run`: simulate a deploy process without actually running it (default: `false`)
|
||||
|
@ -200,6 +208,12 @@ Print the deployment token
|
|||
swa deploy --print-token
|
||||
```
|
||||
|
||||
Provide function language and version
|
||||
|
||||
```bash
|
||||
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
|
||||
```
|
||||
|
||||
Deploy to a specific environment
|
||||
|
||||
```bash
|
||||
|
|
|
@ -77,7 +77,9 @@ Thanks goes to these wonderful people 🎉
|
|||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
|
||||
[![All Contributors](https://img.shields.io/badge/all_contributors-37-orange.svg?style=flat-square)](#contributors-)
|
||||
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
|
||||
|
|
|
@ -14,6 +14,7 @@ This page lists frequently-asked questions and solutions to help troubleshoot co
|
|||
|
||||
### Context
|
||||
|
||||
`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).
|
||||
`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).
|
||||
|
||||
### Solution
|
||||
|
@ -24,6 +25,7 @@ While the team is currently working on the fix, we recommend users to use the ot
|
|||
|
||||
### Context
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
### Why do I need to `swa login`?
|
||||
|
@ -45,6 +47,201 @@ In order to avoid this issue, you have a few options:
|
|||
|
||||
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
|
||||
|
||||
- blob.core.windows.net
|
||||
- azurestaticapps.net
|
||||
- swalocaldeploy.azureedge.net
|
||||
|
||||
## `Unable to download StaticSitesClient binary (File Not Found 404 - 403)`
|
||||
|
||||
### Context
|
||||
|
||||
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.
|
||||
|
||||
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`.
|
||||
|
||||
### Solution
|
||||
|
||||
1. Visit https://swalocaldeploy.azureedge.net/downloads/versions.json
|
||||
2. Copy the `stable` JSON content, for eg:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "stable",
|
||||
"buildId": "1.0.020761",
|
||||
"publishDate": "2022-09-07T17:34:35.4261936Z",
|
||||
"files": {
|
||||
"linux-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient",
|
||||
"sha": "871ae9f154ddb8123e24c507e39dfc11c99f34815e59b178051a6e44a870e308"
|
||||
},
|
||||
"win-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe",
|
||||
"sha": "360b76959c68cc0865b1aea144c8eb2aa413f4856e55c781a83bd7e1ad352362"
|
||||
},
|
||||
"osx-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient",
|
||||
"sha": "1a90511003609af378ff3628feaf3115f9d7e335085a925045e9f206359fdb90"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Based on your operating system, download the right binary from the provided URLs:
|
||||
1. Linux: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient
|
||||
2. Windows: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe
|
||||
3. macOS: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient
|
||||
1. Copy this binary to `$HOME/.swa/deploy/VERSION/StaticSiteClient` (add `.exe` for Windows). For eg:
|
||||
`/home/USER/.swa/deploy/1.0.020761/StaticSiteClient`
|
||||
1. Create a file at `$HOME/.swa/deploy/StaticSitesClient.json` with the following content:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": PASTE STABLE JSON CONTENT,
|
||||
"binary": ABSOLUTE PATH TO STATIC SITE CLIENT BINARY,
|
||||
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
|
||||
}
|
||||
```
|
||||
|
||||
For eg:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"version": "stable",
|
||||
"buildId": "1.0.020761",
|
||||
...
|
||||
},
|
||||
"binary":"/home/USER/.swa/deploy/1.0.020761/StaticSitesClient",
|
||||
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
|
||||
}
|
||||
```
|
||||
|
||||
**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.
|
||||
|
||||
How to compute SHA256 checksum:
|
||||
|
||||
1. On Windows using Powershell:
|
||||
|
||||
```
|
||||
PS C:\Users\USER> (Get-fileHash -Algorithm SHA256 .\.swa\deploy\VERSION\StaticSitesClient.exe).Hash.ToLower()
|
||||
```
|
||||
|
||||
2. On Linux:
|
||||
|
||||
```
|
||||
➜ sha256sum ~/.swa/deploy/VERSION/StaticSitesClient | head -c 64
|
||||
```
|
||||
|
||||
3. On macOS:
|
||||
|
||||
```
|
||||
➜ openssl sha256 ~/.swa/deploy/VERSION/StaticSitesClient | awk '{print $2}'
|
||||
```
|
||||
|
||||
## SWA CLI - Domains that need Firewall access
|
||||
|
||||
### Context
|
||||
|
||||
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
|
||||
|
||||
- blob.core.windows.net
|
||||
- azurestaticapps.net
|
||||
- swalocaldeploy.azureedge.net
|
||||
- dataapibuilder.azureedge.net
|
||||
|
||||
## `Unable to download StaticSitesClient binary (File Not Found 404 - 403)`
|
||||
|
||||
### Context
|
||||
|
||||
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.
|
||||
|
||||
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`.
|
||||
|
||||
### Solution
|
||||
|
||||
1. Visit https://swalocaldeploy.azureedge.net/downloads/versions.json
|
||||
2. Copy the `stable` JSON content, for eg:
|
||||
|
||||
```json
|
||||
{
|
||||
"version": "stable",
|
||||
"buildId": "1.0.020761",
|
||||
"publishDate": "2022-09-07T17:34:35.4261936Z",
|
||||
"files": {
|
||||
"linux-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient",
|
||||
"sha": "871ae9f154ddb8123e24c507e39dfc11c99f34815e59b178051a6e44a870e308"
|
||||
},
|
||||
"win-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe",
|
||||
"sha": "360b76959c68cc0865b1aea144c8eb2aa413f4856e55c781a83bd7e1ad352362"
|
||||
},
|
||||
"osx-x64": {
|
||||
"url": "https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient",
|
||||
"sha": "1a90511003609af378ff3628feaf3115f9d7e335085a925045e9f206359fdb90"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
3. Based on your operating system, download the right binary from the provided URLs:
|
||||
1. Linux: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/linux/StaticSitesClient
|
||||
2. Windows: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/windows/StaticSitesClient.exe
|
||||
3. macOS: https://swalocaldeploy.azureedge.net/downloads/1.0.020761/macOS/StaticSitesClient
|
||||
1. Copy this binary to `$HOME/.swa/deploy/VERSION/StaticSiteClient` (add `.exe` for Windows). For eg:
|
||||
`/home/USER/.swa/deploy/1.0.020761/StaticSiteClient`
|
||||
1. Create a file at `$HOME/.swa/deploy/StaticSitesClient.json` with the following content:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": PASTE STABLE JSON CONTENT,
|
||||
"binary": ABSOLUTE PATH TO STATIC SITE CLIENT BINARY,
|
||||
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
|
||||
}
|
||||
```
|
||||
|
||||
For eg:
|
||||
|
||||
```json
|
||||
{
|
||||
"metadata": {
|
||||
"version": "stable",
|
||||
"buildId": "1.0.020761",
|
||||
...
|
||||
},
|
||||
"binary":"/home/USER/.swa/deploy/1.0.020761/StaticSitesClient",
|
||||
"checksum": SH256 CHECKSUM OF THE BINARY SEE BELOW
|
||||
}
|
||||
```
|
||||
|
||||
**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.
|
||||
|
||||
How to compute SHA256 checksum:
|
||||
|
||||
1. On Windows using Powershell:
|
||||
|
||||
```
|
||||
PS C:\Users\USER> (Get-fileHash -Algorithm SHA256 .\.swa\deploy\VERSION\StaticSitesClient.exe).Hash.ToLower()
|
||||
```
|
||||
|
||||
2. On Linux:
|
||||
|
||||
```
|
||||
➜ sha256sum ~/.swa/deploy/VERSION/StaticSitesClient | head -c 64
|
||||
```
|
||||
|
||||
3. On macOS:
|
||||
|
||||
```
|
||||
➜ openssl sha256 ~/.swa/deploy/VERSION/StaticSitesClient | awk '{print $2}'
|
||||
```
|
||||
|
||||
## SWA CLI - Domains that need Firewall access
|
||||
|
||||
### Context
|
||||
|
||||
If you are having trouble accessing SWA CLI, the following domains need to be allowed an access in your firewall:
|
||||
|
||||
- blob.core.windows.net
|
||||
- azurestaticapps.net
|
||||
- swalocaldeploy.azureedge.net
|
||||
|
|
|
@ -249,7 +249,7 @@
|
|||
"description": "The folder containing the source code of the API application",
|
||||
"type": "string"
|
||||
},
|
||||
"dataApiLocation":{
|
||||
"dataApiLocation": {
|
||||
"description": "The folder containing configurations for database connections",
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -268,6 +268,14 @@
|
|||
"dryRun": {
|
||||
"description": "Simulate a deploy process without actually running it",
|
||||
"type": "boolean"
|
||||
},
|
||||
"apiLanguage": {
|
||||
"description": "The runtime language of the API",
|
||||
"type": "string"
|
||||
},
|
||||
"apiVersion": {
|
||||
"description": "The version of the API runtime language",
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
|
|
@ -6,14 +6,17 @@ import path from "path";
|
|||
import {
|
||||
findSWAConfigFile,
|
||||
getCurrentSwaCliConfigFromFile,
|
||||
isUserOrConfigOption,
|
||||
logger,
|
||||
logGitHubIssueMessageAndExit,
|
||||
readWorkflowFile,
|
||||
updateSwaCliConfigFile,
|
||||
} from "../../../core";
|
||||
import { chooseOrCreateProjectDetails, getStaticSiteDeployment } from "../../../core/account";
|
||||
import { DEFAULT_RUNTIME_LANGUAGE } from "../../../core/constants";
|
||||
import { cleanUp, getDeployClientPath } from "../../../core/deploy-client";
|
||||
import { swaCLIEnv } from "../../../core/env";
|
||||
import { getDefaultVersion } from "../../../core/functions-versions";
|
||||
import { login } from "../login";
|
||||
|
||||
const packageInfo = require(path.join(__dirname, "..", "..", "..", "..", "package.json"));
|
||||
|
@ -22,7 +25,20 @@ export async function deploy(options: SWACLIConfig) {
|
|||
const { SWA_CLI_DEPLOYMENT_TOKEN, SWA_CLI_DEBUG } = swaCLIEnv();
|
||||
const isVerboseEnabled = SWA_CLI_DEBUG === "silly";
|
||||
|
||||
let { appLocation, apiLocation, dataApiLocation, outputLocation, dryRun, deploymentToken, printToken, appName, swaConfigLocation, verbose } = options;
|
||||
let {
|
||||
appLocation,
|
||||
apiLocation,
|
||||
dataApiLocation,
|
||||
outputLocation,
|
||||
dryRun,
|
||||
deploymentToken,
|
||||
printToken,
|
||||
appName,
|
||||
swaConfigLocation,
|
||||
verbose,
|
||||
apiLanguage,
|
||||
apiVersion,
|
||||
} = options;
|
||||
|
||||
if (dryRun) {
|
||||
logger.warn("***********************************************************************");
|
||||
|
@ -84,6 +100,18 @@ export async function deploy(options: SWACLIConfig) {
|
|||
}
|
||||
}
|
||||
|
||||
if (!isUserOrConfigOption("apiLanguage")) {
|
||||
logger.log(`Consider providing api-language and version using --api-language and --api-version flags,
|
||||
otherwise default values apiLanguage: ${apiLanguage} and apiVersion: ${apiVersion} will apply`);
|
||||
} else if (!isUserOrConfigOption("apiVersion")) {
|
||||
if (!apiLanguage) {
|
||||
apiLanguage = DEFAULT_RUNTIME_LANGUAGE;
|
||||
}
|
||||
apiVersion = getDefaultVersion(apiLanguage);
|
||||
logger.log(`Api language "${apiLanguage}" is provided but api version is not provided.
|
||||
Assuming default version "${apiVersion}"`);
|
||||
}
|
||||
|
||||
// resolve the deployment token
|
||||
if (deploymentToken) {
|
||||
deploymentToken = deploymentToken;
|
||||
|
@ -174,7 +202,7 @@ export async function deploy(options: SWACLIConfig) {
|
|||
appLocation,
|
||||
outputLocation: resolvedOutputLocation,
|
||||
apiLocation: resolvedApiLocation,
|
||||
dataApiLocation
|
||||
dataApiLocation,
|
||||
};
|
||||
try {
|
||||
userWorkflowConfig = readWorkflowFile({
|
||||
|
@ -219,6 +247,8 @@ export async function deploy(options: SWACLIConfig) {
|
|||
// If config file is not in output location, we need to tell where to find it
|
||||
CONFIG_FILE_LOCATION: resolvedSwaConfigLocation,
|
||||
VERBOSE: isVerboseEnabled ? "true" : "false",
|
||||
FUNCTION_LANGUAGE: apiLanguage,
|
||||
FUNCTION_LANGUAGE_VERSION: apiVersion,
|
||||
};
|
||||
|
||||
// set the DEPLOYMENT_ENVIRONMENT env variable only when the user has provided
|
||||
|
@ -269,7 +299,7 @@ export async function deploy(options: SWACLIConfig) {
|
|||
else if (line.includes("[31m")) {
|
||||
if (line.includes("Cannot deploy to the function app because Function language info isn't provided.")) {
|
||||
line = chalk.red(
|
||||
`Cannot deploy to the function app because Function language info isn't provided. Add a "platform.apiRuntime" property to your staticwebapp.config.json file, or create one in ${options.outputLocation!}. Please consult the documentation for more information about staticwebapp.config.json: https://docs.microsoft.com/azure/static-web-apps/configuration`
|
||||
`Cannot deploy to the function app because Function language info isn't provided, use flags "--api-language" and "--api-version" or add a "platform.apiRuntime" property to your staticwebapp.config.json file, or create one in ${options.outputLocation!}. Please consult the documentation for more information about staticwebapp.config.json: https://learn.microsoft.com/azure/static-web-apps/build-configuration?tabs=github-actions#skip-building-the-api`
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@ export default function registerCommand(program: Command) {
|
|||
.option("-i, --api-location <path>", "the folder containing the source code of the API application", DEFAULT_CONFIG.apiLocation)
|
||||
.option("-da, --data-api-location <path>", "the folder containing the database connections configuration", DEFAULT_CONFIG.dataApiLocation)
|
||||
.option("-O, --output-location <path>", "the folder containing the built source of the front-end application", DEFAULT_CONFIG.outputLocation)
|
||||
.option("-al, --api-language <apiLanguage>", "the runtime language of the function/api", DEFAULT_CONFIG.apiLanguage)
|
||||
.option("-av, --api-version <apiVersion>", "the version of the function runtime language", DEFAULT_CONFIG.apiVersion)
|
||||
.option(
|
||||
"-w, --swa-config-location <swaConfigLocation>",
|
||||
"the directory where the staticwebapp.config.json file is located",
|
||||
|
@ -48,6 +50,9 @@ Examples:
|
|||
Deploy using a deployment token from env
|
||||
SWA_CLI_DEPLOYMENT_TOKEN=123 swa deploy ./dist/ --api-location ./api/
|
||||
|
||||
Provide function language and version
|
||||
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
|
||||
|
||||
Deploy using swa-cli.config.json file
|
||||
swa deploy
|
||||
swa deploy myconfig
|
||||
|
|
|
@ -125,6 +125,8 @@ describe("swa init", () => {
|
|||
\\"appLocation\\": \\"src\\",
|
||||
\\"apiLocation\\": \\"src/node-ts\\",
|
||||
\\"outputLocation\\": \\".\\",
|
||||
\\"apiLanguage\\": \\"node\\",
|
||||
\\"apiVersion\\": \\"16\\",
|
||||
\\"apiBuildCommand\\": \\"npm run build --if-present\\"
|
||||
}
|
||||
}
|
||||
|
@ -146,6 +148,8 @@ describe("swa init", () => {
|
|||
\\"appLocation\\": \\"src/astro preact\\",
|
||||
\\"apiLocation\\": \\"src/node\\",
|
||||
\\"outputLocation\\": \\"_site\\",
|
||||
\\"apiLanguage\\": \\"node\\",
|
||||
\\"apiVersion\\": \\"16\\",
|
||||
\\"appBuildCommand\\": \\"npm run build\\",
|
||||
\\"apiBuildCommand\\": \\"npm run build --if-present\\",
|
||||
\\"run\\": \\"npm run dev\\",
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
writeConfigFile,
|
||||
} from "../../../core/utils";
|
||||
import { detectProjectFolders, generateConfiguration, isDescendantPath } from "../../../core/frameworks";
|
||||
import { getChoicesForApiLanguage } from "../../../core/functions-versions";
|
||||
|
||||
export async function init(options: SWACLIConfig, showHints: boolean = true) {
|
||||
const configFilePath = options.config!;
|
||||
|
@ -137,6 +138,8 @@ function convertToCliConfig(config: FrameworkConfig): SWACLIConfig {
|
|||
appLocation: config.appLocation,
|
||||
apiLocation: config.apiLocation,
|
||||
outputLocation: config.outputLocation,
|
||||
apiLanguage: config.apiLanguage,
|
||||
apiVersion: config.apiVersion,
|
||||
appBuildCommand: config.appBuildCommand,
|
||||
apiBuildCommand: config.apiBuildCommand,
|
||||
run: config.appDevserverCommand,
|
||||
|
@ -150,6 +153,7 @@ async function promptConfigSettings(disablePrompts: boolean, detectedConfig: Fra
|
|||
value = value.trim();
|
||||
return value === "" ? undefined : value;
|
||||
};
|
||||
|
||||
const response = await promptOrUseDefault(disablePrompts, [
|
||||
{
|
||||
type: "text",
|
||||
|
@ -175,6 +179,23 @@ async function promptConfigSettings(disablePrompts: boolean, detectedConfig: Fra
|
|||
initial: detectedConfig.apiLocation,
|
||||
format: trimValue,
|
||||
},
|
||||
{
|
||||
type: (prev) => (prev != null ? "select" : null),
|
||||
name: "apiLanguage",
|
||||
message: "What's your API language? (optional)",
|
||||
choices: [
|
||||
{ title: "Node.js", value: "node" },
|
||||
{ title: "Python", value: "python" },
|
||||
{ title: "Dotnet", value: "dotnet" },
|
||||
{ title: "Dotnet isolated", value: "dotnetisolated" },
|
||||
],
|
||||
},
|
||||
{
|
||||
type: (prev) => (prev != null ? "select" : null),
|
||||
name: "apiVersion",
|
||||
message: "What's your API version? (optional)",
|
||||
choices: (prev) => getChoicesForApiLanguage(prev),
|
||||
},
|
||||
{
|
||||
type: "text",
|
||||
name: "appBuildCommand",
|
||||
|
@ -211,6 +232,7 @@ async function promptConfigSettings(disablePrompts: boolean, detectedConfig: Fra
|
|||
format: trimValue,
|
||||
},
|
||||
]);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -220,6 +242,8 @@ function printFrameworkConfig(config: FrameworkConfig) {
|
|||
logger.log(`- App location: ${chalk.green(config.appLocation)}`);
|
||||
logger.log(`- Output location: ${chalk.green(config.outputLocation)}`);
|
||||
logger.log(`- API location: ${chalk.green(config.apiLocation ?? "")}`);
|
||||
logger.log(`- API language: ${chalk.green(config.apiLanguage ?? "")}`);
|
||||
logger.log(`- API version: ${chalk.green(config.apiVersion ?? "")}`);
|
||||
logger.log(`- App build command: ${chalk.green(config.appBuildCommand ?? "")}`);
|
||||
logger.log(`- API build command: ${chalk.green(config.apiBuildCommand ?? "")}`);
|
||||
logger.log(`- App dev server command: ${chalk.green(config.appDevserverCommand ?? "")}`);
|
||||
|
|
|
@ -35,6 +35,8 @@ const {
|
|||
SWA_CLI_API_DEVSERVER_URL,
|
||||
SWA_CLI_DATA_API_DEVSERVER_URL,
|
||||
SWA_CLI_DATA_API_FOLDER,
|
||||
SWA_CLI_API_LANGUAGE,
|
||||
SWA_CLI_API_VERSION,
|
||||
} = swaCLIEnv();
|
||||
|
||||
export const DEFAULT_CONFIG: SWACLIConfig = {
|
||||
|
@ -58,11 +60,15 @@ export const DEFAULT_CONFIG: SWACLIConfig = {
|
|||
devserverTimeout: parseInt(SWA_CLI_SERVER_TIMEOUT || "60", 10),
|
||||
open: useEnvVarOrUseDefault(SWA_CLI_OPEN_BROWSER, false),
|
||||
githubActionWorkflowLocation: SWA_RUNTIME_WORKFLOW_LOCATION ? SWA_RUNTIME_WORKFLOW_LOCATION : undefined,
|
||||
appDevserverUrl: SWA_CLI_APP_DEVSERVER_URL || undefined,
|
||||
apiDevserverUrl: SWA_CLI_API_DEVSERVER_URL || undefined,
|
||||
|
||||
// swa deploy options
|
||||
env: SWA_CLI_DEPLOY_ENV || "preview",
|
||||
appName: SWA_CLI_APP_NAME || undefined,
|
||||
dryRun: useEnvVarOrUseDefault(SWA_CLI_DEPLOY_DRY_RUN, false),
|
||||
appDevserverUrl: SWA_CLI_APP_DEVSERVER_URL || undefined,
|
||||
apiDevserverUrl: SWA_CLI_API_DEVSERVER_URL || undefined,
|
||||
apiLanguage: SWA_CLI_API_LANGUAGE || "node",
|
||||
apiVersion: SWA_CLI_API_VERSION || "16",
|
||||
dataApiDevserverUrl: SWA_CLI_DATA_API_DEVSERVER_URL || undefined,
|
||||
|
||||
// swa login options
|
||||
|
|
|
@ -3,13 +3,16 @@ import { DEFAULT_CONFIG } from "../config";
|
|||
import { address, isHttpUrl } from "./utils/net";
|
||||
import os from "os";
|
||||
|
||||
// StaticSiteClient related constants
|
||||
export const DEPLOY_BINARY_NAME = "StaticSitesClient";
|
||||
export const DEPLOY_BINARY_STABLE_TAG = "stable";
|
||||
export const DEPLOY_FOLDER = path.join(os.homedir(), ".swa", "deploy");
|
||||
export const STATIC_SITE_CLIENT_RELEASE_METADATA_URL = "https://swalocaldeploy.azureedge.net/downloads/versions.json";
|
||||
|
||||
// Data-api-builder related constants
|
||||
export const DATA_API_BUILDER_BINARY_NAME = "DataApiBuilder";
|
||||
export const DATA_API_BUILDER_COMMAND = "dab";
|
||||
export const STATIC_SITE_CLIENT_RELEASE_METADATA_URL = "https://swalocaldeploy.azureedge.net/downloads/versions.json";
|
||||
export const DATA_API_BUILDER_RELEASE_METADATA_URL = "https://dataapibuilder.azureedge.net/releases/dab-manifest.json";
|
||||
export const DEPLOY_FOLDER = path.join(os.homedir(), ".swa", "deploy");
|
||||
export const DATA_API_BUILDER_FOLDER = path.join(os.homedir(), ".swa", "dataApiBuilder");
|
||||
export const DATA_API_BUILDER_RELEASE_TAG = "released";
|
||||
export const DATA_API_BUILDER_LATEST_TAG = "latest";
|
||||
|
@ -18,6 +21,20 @@ export const DATA_API_BUILDER_DEFAULT_SCHEMA_FILE_NAME = "staticwebapp.database.
|
|||
export const DATA_API_BUILDER_DEFAULT_FOLDER = "swa-db-connections";
|
||||
export const DATA_API_BUILDER_DEFAULT_REST_PATH = "/rest";
|
||||
export const DATA_API_BUILDER_VERSION_ID = "0.5.32";
|
||||
export const DEFAULT_DATA_API_BUILDER_BINARY = {
|
||||
Windows: "Microsoft.DataApiBuilder.exe",
|
||||
Linux: "Microsoft.DataApiBuilder",
|
||||
MacOs: "Microsoft.DataApiBuilder",
|
||||
};
|
||||
export const DATA_API_BUILDER_DATABASE_TYPES = {
|
||||
MsSql: "mssql",
|
||||
CosmosDbNoSql: "cosmosdb_nosql",
|
||||
CosmosDbPostGreSql: "cosmosdb_postgresql",
|
||||
MySql: "mysql",
|
||||
PostGreSql: "postgresql",
|
||||
};
|
||||
|
||||
// General SWA_CLI constants
|
||||
export const SWA_COMMANDS = ["login", "init", "start", "deploy", "build", "db init"] as const;
|
||||
// Type cannot be in swa.d.ts as it's inferred from SWA_COMMANDS
|
||||
export type SWACommand = typeof SWA_COMMANDS[number];
|
||||
|
@ -27,20 +44,6 @@ export const SWA_RUNTIME_CONFIG_MAX_SIZE_IN_KB = 20; // 20kb
|
|||
export const SWA_AUTH_COOKIE = `StaticWebAppsAuthCookie`;
|
||||
export const ALLOWED_HTTP_METHODS_FOR_STATIC_CONTENT = ["GET", "HEAD", "OPTIONS"];
|
||||
|
||||
export const DEFAULT_DATA_API_BUILDER_BINARY = {
|
||||
Windows: "Microsoft.DataApiBuilder.exe",
|
||||
Linux: "Microsoft.DataApiBuilder",
|
||||
MacOs: "Microsoft.DataApiBuilder",
|
||||
};
|
||||
|
||||
export const DATA_API_BUILDER_DATABASE_TYPES = {
|
||||
MsSql: "mssql",
|
||||
CosmosDbNoSql: "cosmosdb_nosql",
|
||||
CosmosDbPostGreSql: "cosmosdb_postgresql",
|
||||
MySql: "mysql",
|
||||
PostGreSql: "postgresql",
|
||||
};
|
||||
|
||||
export const AUTH_STATUS = {
|
||||
NoAuth: 0,
|
||||
HostNameAuthLogin: 1,
|
||||
|
@ -224,6 +227,23 @@ export const SWA_CONFIG_FILENAME_LEGACY = "routes.json";
|
|||
export const CUSTOM_URL_SCHEME = "swa://";
|
||||
export const OVERRIDABLE_ERROR_CODES = [400, 401, 403, 404];
|
||||
|
||||
// Constants related to Api runtime
|
||||
export const DEFAULT_VERSION = {
|
||||
Node: "16",
|
||||
Dotnet: "6.0",
|
||||
DotnetIsolated: "6.0",
|
||||
Python: "3.8",
|
||||
};
|
||||
|
||||
export const SUPPORTED_VERSIONS = {
|
||||
Node: ["12", "14", "16", "18"],
|
||||
Dotnet: ["3.1", "6.0"],
|
||||
DotnetIsolated: ["6.0", "7.0"],
|
||||
Python: ["3.8", "3.9", "3.10"],
|
||||
};
|
||||
|
||||
export const DEFAULT_RUNTIME_LANGUAGE = "node";
|
||||
|
||||
// --
|
||||
// Note: declare these as functions so that their body gets evaluated at runtime!
|
||||
// The reason for this is that these function depend on values set by environment variables which are set
|
||||
|
|
|
@ -30,6 +30,8 @@ describe("framework detection", () => {
|
|||
appBuildCommand: "npm run build",
|
||||
appLocation: "e2e/fixtures/astro-node/astro preact",
|
||||
appDevserverCommand: "npm run dev",
|
||||
apiLanguage: "node",
|
||||
apiVersion: "16",
|
||||
appDevserverUrl: "http://localhost:8080",
|
||||
name: "Astro, with API: Node.js",
|
||||
outputLocation: "_site",
|
||||
|
@ -44,6 +46,8 @@ describe("framework detection", () => {
|
|||
apiLocation: "e2e/fixtures/static-node-ts/node-ts",
|
||||
appLocation: "e2e/fixtures/static-node-ts",
|
||||
name: "Static HTML, with API: Node.js, TypeScript",
|
||||
apiLanguage: "node",
|
||||
apiVersion: "16",
|
||||
outputLocation: ".",
|
||||
});
|
||||
});
|
||||
|
|
|
@ -160,7 +160,6 @@ export async function detectFrameworks(projectFiles: string[], frameworks: Frame
|
|||
detectedFrameworks.push({ ...framework, rootPaths });
|
||||
}
|
||||
}
|
||||
|
||||
detectedFrameworks = await asyncFilter(
|
||||
detectedFrameworks,
|
||||
async (framework) => (await matchPackages(framework)) && (await matchContains(framework, projectFiles))
|
||||
|
|
|
@ -5,6 +5,8 @@ export const apiFrameworks: FrameworkDefinition[] = [
|
|||
files: ["package.json", "host.json"],
|
||||
config: {
|
||||
apiBuildCommand: "npm run build --if-present",
|
||||
apiLanguage: "node",
|
||||
apiVersion: "16",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -24,6 +26,17 @@ export const apiFrameworks: FrameworkDefinition[] = [
|
|||
files: ["*.?(csproj|fsproj)", "host.json"],
|
||||
config: {
|
||||
apiBuildCommand: "dotnet publish -c Release",
|
||||
apiLanguage: "dotnet",
|
||||
apiVersion: "6.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "dotnetisolated",
|
||||
name: ".NET",
|
||||
files: ["*.?(csproj|fsproj)", "host.json"],
|
||||
config: {
|
||||
apiLanguage: "dotnetisolated",
|
||||
apiVersion: "6.0",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -32,6 +45,8 @@ export const apiFrameworks: FrameworkDefinition[] = [
|
|||
files: ["?(requirements.txt|pyproject.toml|runtime.txt|setup.py)", "host.json"],
|
||||
config: {
|
||||
// Nothing to setup, but we need to know the apiLocation (rootPath)
|
||||
apiLanguage: "python",
|
||||
apiVersion: "3.8",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import { DEFAULT_VERSION, SUPPORTED_VERSIONS } from "./constants";
|
||||
import { logger } from "./utils/logger";
|
||||
|
||||
export function getDefaultVersion(apiLanguage: string): string {
|
||||
let apiVersion;
|
||||
// apiLanguage = apiLanguage.toLowerCase();
|
||||
switch (apiLanguage) {
|
||||
case "python":
|
||||
apiVersion = DEFAULT_VERSION.Python;
|
||||
break;
|
||||
case "dotnet":
|
||||
apiVersion = DEFAULT_VERSION.Dotnet;
|
||||
break;
|
||||
case "dotnetisolated":
|
||||
apiVersion = DEFAULT_VERSION.DotnetIsolated;
|
||||
break;
|
||||
case "node":
|
||||
default:
|
||||
apiVersion = DEFAULT_VERSION.Node;
|
||||
break;
|
||||
}
|
||||
return apiVersion;
|
||||
}
|
||||
|
||||
export function getChoicesForApiLanguage(apiLanguage: string) {
|
||||
// Refer to this for functions and versions - https://learn.microsoft.com/azure/static-web-apps/configuration#selecting-the-api-language-runtime-version
|
||||
logger.silly(`ApiLang: ${apiLanguage}`);
|
||||
let choices = [];
|
||||
switch (apiLanguage) {
|
||||
case "python":
|
||||
choices = generateChoicesForApi(SUPPORTED_VERSIONS.Python);
|
||||
break;
|
||||
case "dotnet":
|
||||
choices = generateChoicesForApi(SUPPORTED_VERSIONS.Dotnet);
|
||||
break;
|
||||
case "dotnetisolated":
|
||||
choices = generateChoicesForApi(SUPPORTED_VERSIONS.DotnetIsolated);
|
||||
break;
|
||||
case "node":
|
||||
default:
|
||||
choices = generateChoicesForApi(SUPPORTED_VERSIONS.Node);
|
||||
break;
|
||||
}
|
||||
return choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates and returns array of choices
|
||||
* @param supportedVersions
|
||||
* @returns array of choices
|
||||
*/
|
||||
function generateChoicesForApi(supportedVersions: string[]) {
|
||||
let choices = [];
|
||||
|
||||
for (let index = 0; index < supportedVersions.length; index++) {
|
||||
const version = supportedVersions[index];
|
||||
const choice = {
|
||||
title: version,
|
||||
value: version,
|
||||
};
|
||||
choices.push(choice);
|
||||
}
|
||||
|
||||
return choices;
|
||||
}
|
|
@ -14,7 +14,7 @@ export function runCommand(command: string, cwd?: string) {
|
|||
});
|
||||
}
|
||||
|
||||
export function execFileCommand(command: string, cwd?: string, args?: string[]){
|
||||
export function execFileCommand(command: string, cwd?: string, args?: string[]) {
|
||||
const child = execFileSync(command, args, {
|
||||
stdio: "inherit",
|
||||
cwd: cwd ?? process.cwd(),
|
||||
|
|
|
@ -214,7 +214,7 @@ export function validateUserWorkflowConfig(userWorkflowConfig: Partial<GithubAct
|
|||
|
||||
if (userWorkflowConfig?.dataApiLocation) {
|
||||
dataApiLocation = path.resolve(userWorkflowConfig.dataApiLocation);
|
||||
if(path.isAbsolute(userWorkflowConfig.dataApiLocation)) {
|
||||
if (path.isAbsolute(userWorkflowConfig.dataApiLocation)) {
|
||||
dataApiLocation = userWorkflowConfig.dataApiLocation;
|
||||
}
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ export function validateUserWorkflowConfig(userWorkflowConfig: Partial<GithubAct
|
|||
appLocation,
|
||||
apiLocation,
|
||||
outputLocation,
|
||||
dataApiLocation
|
||||
dataApiLocation,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -119,7 +119,7 @@ export function readWorkflowFile({ userWorkflowConfig }: { userWorkflowConfig?:
|
|||
app_location,
|
||||
output_location,
|
||||
api_location,
|
||||
data_api_location
|
||||
data_api_location,
|
||||
});
|
||||
|
||||
// the following locations (extracted from the config) should be under the user's project folder:
|
||||
|
|
|
@ -22,6 +22,8 @@ declare interface StaticSiteClientEnv {
|
|||
VERBOSE?: string;
|
||||
DEPLOYMENT_ENVIRONMENT?: string;
|
||||
CONFIG_FILE_LOCATION?: string;
|
||||
FUNCTION_LANGUAGE?: string;
|
||||
FUNCTION_LANGUAGE_VERSION?: string;
|
||||
}
|
||||
|
||||
declare interface SWACLIEnv extends StaticSiteClientEnv {
|
||||
|
@ -58,6 +60,8 @@ declare interface SWACLIEnv extends StaticSiteClientEnv {
|
|||
SWA_CLI_DEPLOYMENT_TOKEN?: string;
|
||||
SWA_RUNTIME_CONFIG?: string;
|
||||
SWA_CLI_VERSION?: string;
|
||||
SWA_CLI_API_LANGUAGE?: string;
|
||||
SWA_CLI_API_VERSION?: string;
|
||||
AZURE_REGION_LOCATION?: string;
|
||||
|
||||
// swa build
|
||||
|
@ -186,6 +190,8 @@ declare type SWACLIDeployOptions = SWACLISharedLoginOptions & {
|
|||
dryRun?: boolean;
|
||||
printToken?: boolean;
|
||||
env?: string;
|
||||
apiLanguage?: string;
|
||||
apiVersion?: string;
|
||||
};
|
||||
|
||||
// -- CLI Login options ------------------------------------------------------
|
||||
|
@ -298,6 +304,8 @@ declare type SWACLIConfigFile = {
|
|||
|
||||
declare type FrameworkConfig = GithubActionWorkflow & {
|
||||
name?: string;
|
||||
apiLanguage?: string;
|
||||
apiVersion?: string;
|
||||
apiBuildCommand?: string;
|
||||
appDevserverCommand?: string;
|
||||
appDevserverUrl?: string;
|
||||
|
|
Загрузка…
Ссылка в новой задаче