Code Monkey home page Code Monkey logo

singlecontainer-storage's Introduction

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:

touch .env
echo STORAGE=<STORAGE PATH> >> .env

Get dependencies and start Node:

npm i
node server.js

To test it, go to http://localhost:8080/<file_name>. The program will print the content of the file from the STORAGE parameter.

Docker

Build and push the docker image:

docker build -t <your username>/node-web-app .
docker run -p 8080:8080 -v <local-dir>:<dotenv-storage-path> -d <your username>/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:

# 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:

az group delete -n $group

Reference

Dockerizing a Node.js web app

singlecontainer-storage's People

Contributors

dependabot[bot] avatar epomatti avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.