Deploy to Azure with Blob Storage
Learn how to deploy your customization to Azure with Blob Storage.
Prerequisites
Before you get started, you need to have:
- An Azure account.
- A Merchant Center account and a Project.
- A customization configured in the Merchant Center:
- For Custom Applications, see Managing Custom Applications.
- For Custom Views, see Managing Custom Views.
Configuration
Adding the customization identifier and URL
Depending on the customization type, you'll need to specify either the Custom Application ID or the Custom View ID that was provided to you when you added the customization in the Merchant Center.
You'll also need to specify the production URL from your Azure project. You can keep the standard Azure Blob Storage Static Website URL https://<project>.z13.web.core.windows.net/
or provide your custom domain.
For Custom Applications, make the following changes to the Custom Application config:
- Add the Custom Application ID to
env.production.applicationId
. - Add the production URL from your Azure project to
env.production.url
.
{"env": {"production": {"applicationId": "ckvtahxl90097sys6har1e6n3","url": "https://<project>.z13.web.core.windows.net/"}}}
For Custom Views, make the following changes to the Custom View config:
- Add the Custom View ID to
env.production.customViewId
. - Add the production URL from your Azure project to
env.production.url
.
const config = {env: {production: {customViewId: 'ckvtahxl90097sys6har1e6n3',url: 'https://<project>.z13.web.core.windows.net/',},},// ...};
Using environment variables
To avoid hardcoding values (such as the customization identifier or the Project key), you can use variable placeholders in your Custom Application config or Custom View config.
Example of environment variables with Custom Applications:
{"env": {"production": {"applicationId": "${env:APPLICATION_ID}","url": "https://<project>.z13.web.core.windows.net/"}}}
Example of environment variables with Custom Views:
{"env": {"production": {"customViewId": "${env:CUSTOM_VIEW_ID}","url": "https://<project>.z13.web.core.windows.net/"}}}
Connect Azure Blob Storage with GitHub Actions
One of the ways to deploy to Azure is to use Blob Storage. This service allows hosting a static website, but this needs to be enabled and configured in the storage account.
Follow the steps in the Azure Storage Account creator to create a new storage account.
Configuring static website hosting
Once the storage account is created, go to Static website
section of the storage account and provide the following settings:
- Static website:
enabled
- Index document name:
index.html
- Error document path:
index.html
Generating deployment credentials
Follow the Azure instruction to generate deployment credentials. This step will result with the following JSON object as output in the command-line:
{"clientId": "598...6fe","clientSecret": "OfU...cmr","subscriptionId": "c43...c21","tenantId": "591...e24",...}
Configuring GitHub Action workflow
In your repository configure the GitHub secret named AZURE_CREDENTIALS
and paste the whole JSON object from the previous step as the secret value.
As the next step, add a GitHub Action workflow. For the basic GitHub Action workflow you might want to use the following content in the yaml
file or change it according to your needs:
name: Blob storage website CIon:push:branches: [main]jobs:build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3- name: Install dependenciesrun: yarn install --immutable- name: Buildingrun: yarn build- uses: azure/login@v1with:creds: ${{ secrets.AZURE_CREDENTIALS }}- name: Upload to blob storageuses: azure/CLI@v1with:inlineScript: |az storage blob delete-batch --account-name <STORAGE_ACCOUNT_NAME> --auth-mode key -s '$web' # update with your <STORAGE_ACCOUNT_NAME>az storage blob upload-batch --account-name <STORAGE_ACCOUNT_NAME> --auth-mode key -d '$web' -s public/ # update with your <STORAGE_ACCOUNT_NAME>- name: logoutrun: |az logoutif: always()
If your customization config requires environment variables, make sure to provide them in the GitHub Action workflow file. You can define the environment variables either as plain text or using GitHub encrypted secrets.
See example below for defining environment variables for the GitHub action::
---- name: Buildingenv:APPLICATION_ID: ${{ secrets.APPLICATION_ID }}run: yarn build
Test your deployment
Install your customization in the Merchant Center to access it within your Projects:
- For Custom Applications, see Managing Custom Applications. You can also use deployment previews to test the application before releasing it to the production environment.
- For Custom Views, see Managing Custom Views.