swa deploy
Synopsis
swa deploy [configName|outputLocation] [options]
Description
This command is used to deploy the current project to Azure Static Web Apps. Here are some common use cases:
- Deploy a front-end app without an API
- Deploy a front-end app with an API
- Deploy a Blazor app
Deployment token
The SWA CLI supports deploying using a deployment token. This is usually useful when deploying from a CI/CD environment. You can get a deployment token either from:
The Azure portal: Home → Static Web App → Your Instance → Overview → Manage deployment token
If you are using the Azure CLI, you can get the deployment token of your project using the following command:
az staticwebapp secrets list --name <application-name> --query "properties.apiKey"
- If you are using the Azure Static Web Apps CLI, you can use the following command:
swa deploy --print-token
You can then use that value with the --deployment-token <token>
or you can create an environment variable called SWA_CLI_DEPLOYMENT_TOKEN
and set it to the deployment token.
IMPORTANT
Don't store the deployment token in a public repository. It should be kept secret!
Deploy a front-end app without an API
You can deploy a front-end application (without an API) to Azure Static Web Apps by running the following steps:
- If your front-end application requires a build step, run
swa build
or refer to your application build instructions.
Option 1: From build folder you would like to deploy, run the deploy command:
cd build/
swa deploy
Note: the "build" folder must contain the static content of your app to be deployed!
Option 2: You can also deploy a specific folder:
If your front-end application requires a build step, run
swa build
or refer to your application build instructions.Deploy your app:
swa deploy ./my-dist
Deploy a front-end app with an API
To deploy both the front-end app and an API to Azure Static Web Apps, use the following steps:
If your front-end application requires a build step, run
swa build
or refer to your application build instructions.Use the flags
--api-language
and--api-version
to specify the language and the runtime version of the backend api.
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
Alternatively you can configure the apiRuntime
in the staticwebapp.config.json
file
{
"platform": {
"apiRuntime": "node:16"
}
}
Note
If your project doesn't have any staticwebapp.config.json
file, add one under your outputLocation
folder.
- Deploy your app:
swa deploy ./my-dist --api-location ./api
Deploy a Blazor app
To deploy a Blazor app with (optional) an API to Azure Static Web Apps, use the following steps:
- Build your Blazor app in Release mode:
dotnet publish -c Release -o bin/publish
- From the root of your project, run the deploy command:
swa deploy ./bin/publish/wwwroot --api-location ./Api
Deploy using the swa-cli.config.json
Note
The path for outputLocation
must be relative to the appLocation
.
If you are using a swa-cli.config.json
configuration file in your project and have a single configuration entry, for example:
{
"configurations": {
"my-app": {
"appLocation": "./",
"apiLocation": "api",
"outputLocation": "frontend",
"start": {
"outputLocation": "frontend"
},
"deploy": {
"outputLocation": "frontend"
}
}
}
}
Then you can deploy your application by running the following steps:
If your front-end application requires a build step, run
swa build
or refer to your application build instructions.Deploy your app:
swa deploy
If you have multiple configuration entries, you can provide the entry ID to specify which one to use:
swa deploy my-otherapp
Options
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
)-pt, --print-token
: print the deployment token (default:false
)--env [environment]
: the type of deployment environment where to deploy the project (default: "preview
")-S, --subscription-id <subscriptionId>
: Azure subscription ID used by this project (default:process.env.AZURE_SUBSCRIPTION_ID
)-R, --resource-group <resourceGroup>
: Azure resource group used by this project-T, --tenant-id <tenantId>
: Azure tenant ID (default:process.env.AZURE_TENANT_ID
)-C, --client-id <clientId>
: Azure client ID-CS, --client-secret <clientSecret>
: Azure client secret-n, --app-name <appName>
: Azure Static Web App application name-CC, --clear-credentials
: clear persisted credentials before login (default:false
)-u, --use-keychain
: enable using the operating system native keychain for persistent credentials (default:true
)-nu, --no-use-keychain
: disable using the operating system native keychain-h, --help
: display help for command
Usage
Deploy using a deployment token
swa deploy ./dist/ --api-location ./api/ --deployment-token <token>
Deploy using a deployment token from the environment variables
SWA_CLI_DEPLOYMENT_TOKEN=123 swa deploy ./dist/ --api-location ./api/
Deploy using swa-cli.config.json
file
swa deploy
swa deploy myconfig
Print the deployment token
swa deploy --print-token
Provide function language and version
swa deploy ./my-dist --api-location ./api --api-language "node" --api-version "16"
Deploy to a specific environment
swa deploy --env production