title | description | services | author | ms.service | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|
Tutorial: Deploy GitLab repositories on Azure Static Web Apps |
Use GitLab with Azure Static Web Apps |
static-web-apps |
craigshoemaker |
static-web-apps |
quickstart |
03/30/2021 |
cshoe |
Azure Static Web Apps has flexible deployment options that allow to work with various providers. In this article, you deploy a web application hosted in GitLab to Azure Static Web Apps.
In this tutorial, you learn to:
[!div class="checklist"]
- Import a repository to GitLab
- Create a static web app
- Configure the GitLab repo to deploy to Azure Static Web Apps
- GitLab account
- Azure account
- If you don't have an Azure subscription, create a free trial account.
This article uses a GitHub repository as the source to import code into a GitLab repository.
-
Sign in to your GitLab account and navigate to https://gitlab.com/projects/new#import_project
-
Select the Repo by URL button.
-
In the Git repository URL box, enter the repository URL for your choice of framework.
https://github.com/staticwebdev/vanilla-basic.git
https://github.com/staticwebdev/angular-basic.git
https://github.com/staticwebdev/blazor-basic.git
https://github.com/staticwebdev/react-basic.git
https://github.com/staticwebdev/vue-basic.git
-
In the Project slug box, enter my-first-static-web-app.
-
Select the Create project button and wait a moment while your repository is set up.
Now that the repository is created, you can create a static web app from the Azure portal.
-
Navigate to the Azure portal.
-
Select Create a Resource.
-
Search for Static Web Apps.
-
Select Static Web Apps.
-
Select Create.
-
In the Basics section, begin by configuring your new app.
Setting Value Azure subscription Select your Azure subscription. Resource Group Select the Create new link and enter static-web-apps-gitlab. Name Enter my-first-static-web-app. Plan type Select Free. Region for Azure Functions API and staging environments Select the region closest to you. Source Select Other. -
Select Review + create.
-
Select Create.
-
Select the Go to resource button.
-
Select the Manage deployment token button.
-
Copy the deployment token value and set it aside in an editor for later use.
-
Select the Close button on the Manage deployment token window.
Next you add a workflow task responsible for building and deploying your site as you make changes.
- Navigate to the repository in GitLab.
- Select Settings.
- Select CI/CD.
- Next to the Variables section, select the Expand button.
- Select the Add variable button.
- In the Key box, enter DEPLOYMENT_TOKEN.
- In the Value box, paste in the deployment token value you set aside in a previous step.
- Select the Add variable button.
-
Select the Repository menu option.
-
Select Files.
-
Ensure the main branch is selected in the branch drop down at the top.
-
Press the plus sign drop down and select New file.
-
Create a new file named
.gitlab-ci.yml
at the root of the repository. (Make sure the file extension is.yml
.) -
Enter the following YAML into the file.
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR/src' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR/src' OUTPUT_PATH: '$CI_PROJECT_DIR/dist/angular-basic' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR/Client' OUTPUT_PATH: '$CI_PROJECT_DIR/wwwroot' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR' OUTPUT_PATH: '$CI_PROJECT_DIR/build' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
variables: API_TOKEN: $DEPLOYMENT_TOKEN APP_PATH: '$CI_PROJECT_DIR' OUTPUT_PATH: '$CI_PROJECT_DIR/dist' deploy: stage: deploy image: registry.gitlab.com/static-web-apps/azure-static-web-apps-deploy script: - echo "App deployed successfully."
The following configuration properties are used in the .gitlab-ci.yml file to configure your static web app.
The
$CI_PROJECT_DIR
variable maps to the repository's root folder location during the build process.Property Description Example Required APP_PATH
Location of your application code. Enter $CI_PROJECT_DIR/
if your application source code is at the root of the repository, or$CI_PROJECT_DIR/app
if your application code is in a folder namedapp
.Yes API_PATH
Location of your Azure Functions code. Enter $CI_PROJECT_DIR/api
if your app code is in a folder namedapi
.No OUTPUT_PATH
Location of the build output folder relative to the APP_PATH
.If your application source code is located at $CI_PROJECT_DIR/app
, and the build script outputs files to the$CI_PROJECT_DIR/app/build
folder, then set$CI_PROJECT_DIR/app/build
as theOUTPUT_PATH
value.No API_TOKEN
API token for deployment. API_TOKEN: $DEPLOYMENT_TOKEN
Yes -
Select the Commit changes button.
-
Select the CI/CD then Pipelines menu items to view the progress of your deployment.
Once the deployment is complete, you can view your website.
There are two aspects to deploying a static app. The first step creates the underlying Azure resources that make up your app. The second is a GitLab workflow that builds and publishes your application.
Before you can navigate to your new static site, the deployment build must first finish running.
The Static Web Apps overview window displays a series of links that help you interact with your web app.
- Return to your static web app in the Azure portal.
- Navigate to the Overview window.
- Select the link under the URL label. Your website will load in a new tab.
If you're not going to continue to use this application, you can delete the Azure Static Web Apps instance and all the associated services by removing the resource group.
- Select the static-web-apps-gitlab resource group from the Overview section.
- Select the Delete resource group button at the top of the resource group Overview.
- Enter the resource group name static-web-apps-gitlab in the Are you sure you want to delete "static-web-apps-gitlab"? confirmation dialog.
- Select Delete.
The process to delete the resource group may take a few minutes to complete.
[!div class="nextstepaction"] Add an API