https://github.com/epomatti/singlecontainer-storage
Azure Single Container WebApp with Storage Blob container.
https://github.com/epomatti/singlecontainer-storage
az-300 azure azure-acr azure-containers azure-webapp nodejs
Last synced: about 2 months ago
JSON representation
Azure Single Container WebApp with Storage Blob container.
- Host: GitHub
- URL: https://github.com/epomatti/singlecontainer-storage
- Owner: epomatti
- License: mit
- Created: 2019-11-27T04:23:00.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2024-12-06T18:01:18.000Z (10 months ago)
- Last Synced: 2025-03-11T02:51:10.493Z (7 months ago)
- Topics: az-300, azure, azure-acr, azure-containers, azure-webapp, nodejs
- Language: JavaScript
- Size: 61.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Single container with Mounted storage
An application to test Azure WebApp with Single Container deployment mounting a Blob Storage container path.
Requirements:
- Docker
- Azure CLI
- Azure Subscription## Run it
#### Node
Create the `.env` file with the path to the local storage path:
```sh
touch .env
echo STORAGE= >> .env
```Get dependencies and start Node:
```sh
npm i
node server.js
```To test it, go to `http://localhost:8080/`. The program will print the content of the file from the `STORAGE` parameter.
#### Docker
Build and push the docker image:
```sh
docker build -t /node-web-app .
docker run -p 8080:8080 -v : -d /node-web-app
```You should be able test it again at this point.
#### Azure
Once you tested your app locally, and against docker runtime, it is ready to run on Azure:
```sh
# set common resource parameters
export group='myResourceGroup'
export location='brazilsouth'
export acr='myContainerRegistry'
export image='yourname/node-web-app'
export tag='yourname.azurecr.io/node-web-app'
export storageAccount='myStoragAccount'
export storageContainer='myfiles'
export localFilePath='/tmp/myfiles/myfile.txt'
export blobName='myfile.txt'
export plan='myPlan'
export webapp='myApp'
export storageMountId='storageMountId'
export storageMountPath='/tmp/myfiles'# create the image registry
az login
az group create -n $group -l $location
az acr create -n $acr -g $group --sku Basic --admin-enabled true
az acr login -n $acr# push the docker image
docker tag $image $tag
docker push $tag# create the storage
az storage account create -n $storageAccount -g $group -l $location --kind StorageV2 --sku Standard_LRS
export key=$(az storage account keys list -n $storageAccount --query "[?keyName == 'key1'].value" -o tsv)
az storage container create -n $storageContainer --account-name $storageAccount --account-key $key# upload a file
az storage blob upload -c $storageContainer -f $localFilePath -n $blobName --account-name $storageAccount --account-key $key# create the Web App
az appservice plan create -n $plan -g $group -l $location --is-linux
az webapp create -g $group -p $plan -n $webapp -i $tag
az webapp config storage-account add -k $key -a $storageAccount -i $storageMountId --sn $storageContainer -t AzureBlob -m $storageMountPath -n $webapp --resource-group $group
```After you finish working, clean your resources:
```sh
az group delete -n $group
```## Reference
[Dockerizing a Node.js web app](1)
[1]: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/