- Artikel
Die Azure Static Web Apps-Buildkonfiguration wird entweder von GitHub Actions oder von Azure Pipelines unterstützt. Jede Site hat eine YAML-Konfigurationsdatei, die steuert, wie eine Site erstellt und bereitgestellt wird. In diesem Artikel werden Struktur und Optionen der Datei erläutert.
In der folgenden Tabelle sind die verfügbaren Konfigurationseinstellungen aufgeführt.
Eigenschaft | BESCHREIBUNG | Erforderlich |
---|---|---|
app_location | In diesem Ordner befindet sich der Quellcode für Ihre Front-End-Anwendung. Der Wert ist relativ zum Stamm des Repositorys in GitHub und dem aktuellen Arbeitsordner in Azure DevOps. Bei Verwendung mit skip_app_build: true handelt es sich bei diesem Wert um den Buildausgabespeicherort der App. | Ja |
api_location | Dieser Ordner enthält den Quellcode für Ihre API-Anwendung. Der Wert ist relativ zum Stamm des Repositorys in GitHub und dem aktuellen Arbeitsordner in Azure DevOps. Bei Verwendung mit skip_api_build: true handelt es sich bei diesem Wert um den Buildausgabespeicherort der API. | Nein |
output_location | Wenn Ihre Webanwendung einen Build-Schritt ausführt, ist der Ausgabeort der Ordner, in dem die öffentlichen Dateien generiert werden. Bei den meisten Projekten ist der output_location relativ zum app_location . Bei .NET-Projekten ist der Speicherort jedoch relativ zum Ausgabeordner für die Veröffentlichung. | Nein |
app_build_command | Für Node.js-Anwendungen können Sie einen benutzerdefinierten Befehl definieren, um die Anwendung mit statischen Inhalten zu erstellen. Wenn Sie beispielsweise einen Produktionsbuild für eine Angular-Anwendung konfigurieren möchten, erstellen Sie ein npm-Skript mit dem Namen | Nein |
api_build_command | Für Node.js-Anwendungen können Sie einen benutzerdefinierten Befehl definieren, um die Azure Functions API-Anwendung zu erstellen. | Nein |
skip_app_build | Legen Sie den Wert auf true fest, um das Erstellen der Front-End-App zu überspringen. | Nein |
skip_api_build | Legen Sie den Wert auf true fest, um das Erstellen der API-Funktionen zu überspringen. | Nein |
cwd (Nur Azure Pipelines) | Absoluter Pfad zum Arbeitsordner. Wird standardmäßig auf $(System.DefaultWorkingDirectory) festgelegt. | Nein |
build_timeout_in_minutes | Legen Sie diesen Wert fest, um das Buildtimeout anzupassen. Wird standardmäßig auf 15 festgelegt. | Nein |
Mit diesen Einstellungen können Sie GitHub Actions oder Azure Pipelines einrichten, um kontinuierliche Integration/kontinuierliche Bereitstellung (CI/CD) für Ihre statische Webanwendung durchzuführen.
Dateiname und Speicherort
- GitHub-Aktionen
- Azure Pipelines
Die Konfigurationsdatei wird von GitHub generiert und im Ordner .github/workflows gespeichert, der nach folgendem Format benannt ist: azure-static-web-apps-<RANDOM_NAME>.yml
.
Buildkonfiguration
In der folgenden Beispielkonfiguration wird das Repository auf Änderungen überwacht. Wenn Commits in den main
-Zweig gepusht werden, wird die Anwendung im app_location
-Ordner erstellt und die Dateien im output_location
-Ordner werden im öffentlichen Web bereitgestellt. Außerdem ist die Anwendung im Ordner api unter dem Pfad api
der Website verfügbar.
- GitHub-Aktionen
- Azure Pipelines
name: Azure Static Web Apps CI/CDon: push: branches: - main pull_request: types: [opened, synchronize, reopened, closed] branches: - mainjobs: build_and_deploy_job: if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed') runs-on: ubuntu-latest name: Build and Deploy Job steps: - uses: actions/checkout@v2 with: submodules: true - name: Build And Deploy id: builddeploy uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for GitHub integrations (i.e. PR comments) action: "upload" ###### Repository/Build Configurations ###### app_location: "src" # App source code path relative to repository root api_location: "api" # Api source code path relative to repository root - optional output_location: "public" # Built app content directory, relative to app_location - optional ###### End of Repository/Build Configurations ###### close_pull_request_job: if: github.event_name == 'pull_request' && github.event.action == 'closed' runs-on: ubuntu-latest name: Close Pull Request Job steps: - name: Close Pull Request id: closepullrequest uses: Azure/static-web-apps-deploy@v1 with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} action: "close"
Bei dieser Konfiguration gilt Folgendes:
- Der
main
Zweig wird auf Commits überwacht. - Ein GitHub Actions-Workflow wird ausgelöst, wenn eine Pull-Anforderung auf dem
main
Zweig: geöffnet, synchronisiert, erneut geöffnet oder geschlossen wird. - Die
build_and_deploy_job
wird ausgeführt, wenn Sie Commits pushen oder eine Pull Anforderung gegen den in deron
Eigenschaft aufgeführten Zweig öffnen. - Der
app_location
verweist auf den Ordnersrc
, der die Quelldateien für die Webanwendung enthält. Verwenden Sie/
, um diesen Wert auf den Repositorystamm festzulegen. - Der
api_location
verweist auf den Ordnerapi
, der die Azure Functions-Anwendung für die API-Endpunkte der Website enthält. Verwenden Sie/
, um diesen Wert auf den Repositorystamm festzulegen. - Der
output_location
verweist auf den Ordnerpublic
, der die endgültige Version der Quelldateien der App enthält. Er ist relativ zuapp_location
. Bei .NET-Projekten ist der Speicherort relativ zum Ausgabeordner für die Veröffentlichung.
Bitte ändern Sie die Werte für repo_token
, action
und azure_static_web_apps_api_token
nicht, da sie von Azure Static Web Apps für Sie festgelegt werden.
Benutzerdefinierte Buildbefehle
Für Node.js-Anwendungen können Sie genau steuern, welche Befehle während des Build-Prozesses der App oder API ausgeführt werden. Das folgende Beispiel zeigt, wie man Build mit Werten für app_build_command
und api_build_command
definiert.
Hinweis
Derzeit können Sie nur app_build_command
und api_build_command
für Node.js-Builds definieren.Verwenden Sie das Feld engines
in der Datei package.json
, um die Node.js Version anzugeben.
- GitHub-Aktionen
- Azure Pipelines
...with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: 'upload' app_location: '/' api_location: 'api' output_location: 'dist' app_build_command: 'npm run build-ui-prod' api_build_command: 'npm run build-api-prod'
Überspringen des Erstellens einer Front-End-App
Wenn Sie die volle Kontrolle über die Erstellung Ihrer Front-End-Anwendung benötigen, können Sie die automatische Erstellung umgehen und die in einem vorherigen Schritt erstellte Anwendung bereitstellen.
So überspringen Sie die Erstellung der Front-End-Anwendung:
- Setzen Sie
app_location
auf den Speicherort der Dateien, die Sie bereitstellen möchten. - Legen Sie
skip_app_build
auftrue
fest. - Setzen Sie
output_location
auf eine leere Zeichenkette (''
).
Hinweis
Stellen Sie sicher, dass Sie Ihre staticwebapp.config.json
-Datei auch in das output-Verzeichnis (Ausgabe) kopiert haben.
- GitHub-Aktionen
- Azure Pipelines
...with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: 'upload' app_location: 'src/dist' api_location: 'api' output_location: '' skip_app_build: true
Überspringen des Erstellens der API
Wenn Sie das Erstellen der API überspringen möchten, können Sie den automatischen Build umgehen und die in einem vorherigen Schritt integrierte API bereitstellen.
Schritte zum Überspringen des Erstellens der API:
- Legen Sie in der Datei staticwebapp.config.json die Eigenschaft
apiRuntime
auf die richtige Runtime und Version fest. Die Liste der unterstützten Runtimes und Versionen finden Sie unter Konfigurieren von Azure Static Web Apps.{ "platform": { "apiRuntime": "node:16" }}
- Legen Sie
skip_api_build
auftrue
fest. - Legen Sie
api_location
auf den Ordner fest, der die erstellte API-App enthält, die bereitgestellt werden soll. Dieser Pfad ist relativ zum Repositorystamm in GitHub Actions undcwd
in Azure Pipelines.
- GitHub-Aktionen
- Azure Pipelines
...with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: 'upload' app_location: "src" # App source code path relative to repository root api_location: "api" # Api source code path relative to repository root - optional output_location: "public" # Built app content directory, relative to app_location - optional skip_api_build: true
Verlängern des Buildtimeouts
Standardmäßig sind die App- und API-Builds auf 15Minuten beschränkt. Sie können das Buildtimeout verlängern, indem Sie die build_timeout_in_minutes
-Eigenschaft festlegen.
- GitHub-Aktionen
- Azure Pipelines
...with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: 'upload' app_location: 'src' api_location: 'api' output_location: 'public' build_timeout_in_minutes: 30
Umgebungsvariablen
Umgebungsvariablen für Ihren Build können über den Abschnitt env
einer Auftragskonfiguration festgelegt werden.
- GitHub-Aktionen
- Azure Pipelines
...with: azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} repo_token: ${{ secrets.GITHUB_TOKEN }} action: 'upload' app_location: 'src' api_location: 'api' output_location: 'public'env: # Add environment variables here HUGO_VERSION: 0.58.0
Unterstützung für Monorepos
Ein Monorepo ist ein Repository, das Code für mehr als eine Anwendung enthält. Der Workflow verfolgt standardmäßig alle Dateien in einem Repository nach, aber Sie können die Konfiguration so anpassen, dass eine einzelne App als Ziel verwendet wird.
Geben Sie die Pfade in den Abschnitten push
und pull_request
an, um für eine Workflowdatei eine einzelne App als Ziel festzulegen.
- GitHub-Aktionen
- Azure Pipelines
Wenn Sie eine Monorepo einrichten, ist jede statische Anwendungskonfiguration nur auf Dateien für eine einzige Anwendung beschränkt. Die verschiedenen Workflowdateien befinden sich gemeinsam im Ordner .github/workflows des Repositorys.
├── .github│ └── workflows│ ├── azure-static-web-apps-purple-pond.yml│ └── azure-static-web-apps-yellow-shoe.yml│├── app1 👉 controlled by: azure-static-web-apps-purple-pond.yml├── app2 👉 controlled by: azure-static-web-apps-yellow-shoe.yml│├── api1 👉 controlled by: azure-static-web-apps-purple-pond.yml├── api2 👉 controlled by: azure-static-web-apps-yellow-shoe.yml│└── README.md
Im folgenden Beispiel wird veranschaulicht, wie Sie einen paths
-Knoten zu den Abschnitten push
und pull_request
einer Datei namens azure-static-web-apps-purple-pond.yml hinzufügen.
on: push: branches: - main paths: - app1/** - api1/** - .github/workflows/azure-static-web-apps-purple-pond.yml pull_request: types: [opened, synchronize, reopened, closed] branches: - main paths: - app1/** - api1/** - .github/workflows/azure-static-web-apps-purple-pond.yml
In diesem Beispiel lösen nur Änderungen an den folgenden Dateien einen neuen Build aus:
- alle Dateien im Ordner app1
- alle Dateien im Ordner api1
- Änderungen an der Workflowdatei azure-static-web-apps-purple-pond.yml der App
Nächste Schritte
Überprüfen von Pull Requests in Präproduktionsumgebungen
FAQs
How do I create an Azure static web app? ›
- Go to the Azure portal.
- Select Create a Resource.
- Search for Static Web Apps.
- Select Static Web Apps.
- Select Create.
- Inside Visual Studio Code, select the Azure logo in the Activity Bar to open the Azure extensions window. ...
- Select F1 to open the Visual Studio Code command palette.
- Enter Create static web app in the command box.
- Select Azure Static Web Apps: Create static web app... and select Enter.
- Git commit changes.
- Create the Static web app in VS Code.
- Add Function API environment variables.
- Add new static web app's URL to Active Directory app.
- Add React client environment variables to workflow configuration file.
- View the deployment on GitHub.
- Use the remote static web app.
- Clean up resources.
- In the staticwebapp. config. json file, set apiRuntime to the correct runtime and version. ...
- Set skip_api_build to true .
- Set api_location to the folder containing the built API app to deploy. This path is relative to the repository root in GitHub Actions and cwd in Azure Pipelines.
- Install the CLI. Console Copy. npm install @azure/static-web-apps-cli.
- Build your app if required by your application. Run npm run build , or the equivalent command for your project.
- Initialize the repository for the CLI. Console Copy. swa init. ...
- Start the CLI. Console Copy. swa start.
Azure Static Web Apps is a service that automatically builds and deploys full stack web apps to Azure from a code repository. The workflow of Azure Static Web Apps is tailored to a developer's daily workflow. Apps are built and deployed based on code changes.
What languages are supported by Azure Static Web app? ›What programming languages are supported for Azure Functions serverless APIs with Static Web Apps? Static Web Apps supports JavaScript, TypeScript, Python, and C# Azure Functions apps.
How do I protect my Azure static web app? ›Under Settings menu, select Configuration. Select the General settings tab. In the Password protection section, select Protect staging environments only to protect only your app's pre-production environments or select Protect both production and staging environments to protect all environments.
How do I deploy a web app in Azure for free? ›Creating Free Azure Service
Login to Azure Portal. Click on App Services and you will see your App Services panel as shown below (you will see your services listed if you have any; which were created previously). Click on "+Add" and choose Web App from the screen. From the next screen, click on "Create".
- Create a new GitHub repository.
- Clone the repository on your computer.
- Create a static website.
- Push your code to GitHub.
- Open your repository settings.
- Add a new page.
- Update your website.
Is Azure Static Web app serverless? ›
Azure Static Web Apps allows you to develop modern full-stack web apps quickly and easily with a static front-end and dynamic back end powered by serverless APIs.
What is the limit of static web apps? ›Static Web Apps doesn't have a limit on the number of users that can log in to your app. You can assign custom roles to up to 25 users using the built-in invitations system.
What are the advantages of Azure static Web apps? ›- Productivity from local development to GitHub native workflows for CI/CD.
- Managed global availability for static content.
- Dynamic scale for serverless APIs.
- Streamlined management including custom domain configuration and authentication and authorization.
- Seamless developer experience and CI/CD.
Azure Static Web Apps allows you to build modern web applications that automatically publish to the web as your code changes.
What is Azure web app How do you create and deploy? ›To deploy to any Azure App service (Web app for Windows, Linux, container, Function app or web jobs), use the Azure App Service Deploy task. This task is automatically added to the release pipeline when you select one of the prebuilt deployment templates for Azure App Service deployment.
How do I change the environment on a static web app? ›Open your static web app. Select Configuration in the sidebar. Select the environment to which you want to apply the application settings. You can configure application settings per environment.
How do I access files in Azure Static Web app? ›Locate the Storage Account where your static web app was created. In the left menu, select Storage Explorer. Under then Blob Containers section, select $web. You'll see the files and you'll be able to download them.
How do I get a static public IP address in Azure? ›- Login to MS Azure portal.
- Click “Virtual Machines” from the left menu.
- Click “Add”.
- Add the basic information about the virtual machine to be set up.
- In the Networking tab, for Public IP click “Create new”.
- Under assign, select Static.
- Click OK.
The primary difference here is that in a traditional web app, the server is responsible for fetching data and compiling it into HTML that the user can see, while in a static web app the browser is responsible for doing so.
What is the difference between static and web app? ›Static websites are one-way communication channels, meaning that the web server can send information to your browser, but you as a user cannot interact with the content and send data back. Web applications are significantly more complicated than static websites.
What is the difference between web app and API app in Azure? ›
The only difference between the three app types (API, web, mobile) is the name and icon used for them in the Azure portal. So it no longer matters which app service type you choose to deploy to (unless you care what the icon looks like).
Which programming language is best for Azure? ›Whether you choose to host your applications entirely in Azure or extend your on-premises applications with Azure services, Azure helps you create applications that are scalable, reliable, and maintainable. Azure supports the most popular programming languages in use today, including Python, JavaScript, Java, .
Which framework is supported by Azure Web App? ›Built-in languages and frameworks
js, Java (8, 11, and 17), Tomcat, PHP, Python, . NET Core, and Ruby.
Common examples of static websites include resume websites, portfolio websites, brochure websites, one-off landing pages, and other informational or read-only sites. These websites are small (three to four pages or fewer), limited in content, and don't require personalized content or frequent updates.
What is IP restriction in Azure static web app? ›Published date: October 13, 2021
IP-based access restriction allows you to control access to your website based on IP address ranges. Only users who access your website from the defined IP addresses are allowed to view and access your application and its resources.
- Make Use of Security Headers. ...
- Install SSL/TLS Certificate Provided by a Reputable Certificate Authority (CA) ...
- Maintain Current Backups of Your Website. ...
- Avoid Using Vulnerable JavaScript Libraries. ...
- Use Strong Passwords. ...
- Choose Your Hosting Provider Wisely.
- Now, we need to login into https://portal.azure.com/ with our login credentials. ...
- Once, we navigate to the Static Web App Resource, then need to click on the New Button to create New Static Web Apps for our Angular Application.
Azure App Service enables you to build and host web applications in the programming language of your choice without managing infrastructure. Learn how to create a website through the hosted web app platform in Azure App Service.
How do I publish my web API to Azure App Service? ›- In Solution Explorer, right-click the project and select Publish.
- In the Publish dialog, select Azure and select the Next button.
- Select Azure App Service (Windows) and select the Next button.
- Select Create a new Azure App Service. ...
- Select the Create button.
Runtime Stack: defines the technology stack used to develop the app (i.e., '. NET Core 3.0 (Current)'); Operating System: sets the app hosting platform (i.e., Linux).
What is the easiest and fastest way to deploy static Web pages on cloud? ›
Upload and share your site's files. Set up a load balancer and SSL certificate. Connect your load balancer to your bucket. Point your domain to your load balancer using an A record.
How do I create a static website without coding? ›- Hire a developer. Depending on the extent of your website project, the quickest way to design a website without having to code is to outsource it. ...
- Use WordPress and modify a theme. ...
- Use a WYSIWYG editor. ...
- Try Webflow.
AWS Amplify provides fully managed hosting for static websites and web apps. Amplify's hosting solution leverages Amazon CloudFront and Amazon S3 to deliver your site assets via the AWS content delivery network (CDN).
What is the difference between Azure Web App and Lambda? ›AWS Lambda defines a concept of layers: a distribution mechanism for libraries, custom runtimes to support other languages, and other dependencies. Azure Functions enables open binding extensions so that the community can create new types of bindings and bring them into Function Apps.
Is Azure App Service same as Azure Web App? ›Azure Web Apps is a specific type of Azure App Service that is focused on hosting web applications. Azure Web Apps provides a fully managed platform for building and hosting web applications using popular programming languages such as . NET, Java, Node. js, Python, and PHP.
Is Azure Web App expensive? ›The benefits and costs of the Azure App Service plan varies between different tiers of web apps. It is free if you choose the Free and Shared plans app service.
Do static websites need servers? ›Hosting a static website does not require web servers and can use content delivery networks to store content (HTML, CSS and JavaScript files), making it easy to scale with increased user traffic.
What is the largest static websites? ›The World Record of “LARGEST STATIC WEBSITE MADE BY AN INDIVIDUAL” is achieved by a Delhi, India based Amit Sharma on 25th September 2016. He made a largest static website cheapflightsall.com that consists 31 crores 84 lacs 60 thousand and 567 of pages/urls. The size of the website is 5 TB.
Are static websites hackable? ›It doesn't matter if your website has static content — its web server could easily become a victim of a DDoS attack if you don't take the necessary measures. The easiest way to implement DDoS protection on your website is to have a security service provider take care of all cyber threats.
Is Azure static website free? ›Azure Static Web Apps offers cost-effective pricing from hobby to production apps. Get started today with the Free plan which provides free web hosting, SSL certificate, and custom domain to provide branded customizations to your app.
How do I create an Azure webserver? ›
- Create a Resource Group.
- Create a Virtual Network and a subnet.
- Protect a subnet using a Network Security Group.
- Deploy Bastion to connect to a Virtual Machine.
- Create an Ubuntu Server Virtual Machine.
- Install Nextcloud by connecting via SSH using Bastion.
- Publish an IP.
- Create a DNS label.
Login to Azure Portal. Click on App Services and you will see your App Services panel as shown below (you will see your services listed if you have any; which were created previously). Click on "+Add" and choose Web App from the screen. From the next screen, click on "Create".
How do I create and deploy Azure Webapp? ›To deploy to any Azure App service (Web app for Windows, Linux, container, Function app or web jobs), use the Azure App Service Deploy task. This task is automatically added to the release pipeline when you select one of the prebuilt deployment templates for Azure App Service deployment.
What is the cheapest way to host a static website in Azure? ›Blob Storage is the cheapest option to store files in Microsoft Azure. There are two metrics that you pay for with Blob Storage: Storage and Bandwidth. Using the Azure Pricing Calculator you can easily calculate the cost associated with your static sites.
What language is Azure static web app? ›What programming languages are supported for Azure Functions serverless APIs with Static Web Apps? Static Web Apps supports JavaScript, TypeScript, Python, and C# Azure Functions apps.
How do I create a SQL Web App in Azure? ›- In the Publish dialog, scroll down to the Service Dependencies section. ...
- Select Azure SQL Database and click Next.
- In the Configure Azure SQL Database dialog, click +.
- Next to Database server, click New. ...
- Add an administrator username and password. ...
- Click OK.
Azure server management services provide a consistent experience for managing servers at scale. These services cover both Linux and Windows operating systems. They can be used in production, development, and test environments.
How do I create an Azure Web App using terraform? ›- Create a directory in which to test and run the sample Terraform code and make it the current directory. ...
- Create a file named main.tf and insert the above code. ...
- Initialize Terraform. ...
- Create the Terraform plan.
Hosting with Microsoft Azure significantly reduces you and your users' load times. In addition, you save bandwidth and increase responsiveness so users can fully navigate the site without any issues.
Can you develop on Azure for free? ›We'll never charge you unless you decide to move to pay-as-you-go pricing. If you move to pay as you go, you'll only be charged for services that you use above the free monthly amounts. You can check your usage of free services in the Azure portal.
How much of Azure is free? ›
When you start using Azure with a free account, you get $2001 credit to spend in the first 30 days after you sign up. In addition, you get free monthly amounts of two groups of services: popular services, which are free for 12 months, and more than 55 other services that are free always.
What is the difference between Azure Web App and Azure App Service? ›A Web App is a web application that is hosted in an App Service. The App Service is the managed service in Azure that enables you to deploy a web application and make it available to your customers on the Internet in a very short amount of time.
Can I build apps with Azure? ›Enabling productivity and innovation for more than 2 million apps and sites on Azure. Quickly build, deploy, and scale web apps and APIs on your terms. Work with . NET, .
Can I host my website on Azure? ›Azure App Service enables you to build and host web applications in the programming language of your choice without managing infrastructure. Learn how to create a website through the hosted web app platform in Azure App Service.