2 minute read (291 words).

Using Github Actions to push to Azure Blob


Azure, Web

Azure Blob is a great place to store static resources for websites with it’s cheap running costs, ease of setup and ability to host them directly from it. The only problem I found was uploading the resources.

Yes, it’s possible to upload them via the GUI, or by running the AzCopy packages. But, I didn’t like these methods.

I store all my assets in various Git repository’s and wanted a seamless way to upload them upon a commit. Github Actions provided that functionality.

Simply add a new secret with the below name and the Azure Storage connection string. This is important as the actions workflow file which controls what happens is public.

AZURE_STORAGE_CONNECTION_STRING

Now lets creating the workflows control file.

vi .github/workflows/main.yml

name: Publish to WB Asset Server

on: push

jobs:
  build_and_publish:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout the repo
      uses: actions/checkout@v2

    - name: Publish app
      uses: Azure/[email protected]
      with:
        azcliversion: latest
        inlineScript: |
          az storage blob delete-batch -s "\$web" --pattern upload_dir\* --connection-string "${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"
az storage blob upload-batch -s $GITHUB_WORKSPACE/ -d "\$web" --destination-path upload_dir --connection-string "${{ secrets.AZURE_STORAGE_CONNECTION_STRING }}"

Two parameters in the az lines will need to me modified for your environments. upload_dir which is the directory in which the repo will be uploaded to.

$web may need to be changed to whatever container name you wish to upload to, however $web is the required name for static website hosting from a storage account.

Note* The Azure Storage connection string can be found under Settings > Access Keys > Show Keys in the Azure Portal under the storage account you intend to use.

Static website hosting in Azure Storage | Microsoft Docs



Share via Twitter LinkedIn Facebook Email