Skip to content

sharmavikashkr/azure-test

Repository files navigation

Description

A simple application developed in Nest framework to demonstrate deployment to Azure in 2 ways:

  1. By using Azure Cli and Azure Resource manager templates.
  2. Though Github Actions workflows.

Installation

$ npm install

Running the app locally

# development
$ npm run start

# watch mode
$ npm run start:dev

Running the app locally in Docker

# build docker image
$ docker build -t hello-world:1.0.0 .
# run
$ docker run -p 80:80 hello-world:1.0.0
# verify
$ verify that the application is accessible at http://localhost/hello

Create a service principal (To be done only once)

This is a common step before deploying though either ways discussed below.

  1. Download Azure Cli and login to Azure using your tenant
$ az login --tenant <tenant_id>
  1. Create a resource group
$ az group create -l centralindia -n TestGroup
  1. Create a group scoped service principal. Save the generated JSON output securely.
$ groupId=$(az group show --name TestGroup --query id --output tsv)
$ MSYS_NO_PATHCONV=1 az ad sp create-for-rbac --name TestApp --role contributor --scope $groupId --sdk-auth

Deploy to Azure using Azure Cli and Azure Resource manager templates

Steps in details here.

  1. Login with service principal
$ az login — service-principal -u <client_id> -p <client_secret> --tenant <tenant_id>
  1. Create a container registry
$ az acr create --resource-group TestGroup --name testgroupregistry --sku Basic
  1. Build and push image to the registry
$ docker build . -t hello-world:1.0.0
$ docker tag hello-world:1.0.0 testgroupregistry.azurecr.io/samples/hello-world:1.0.0
$ az acr login --name testgroupregistry
$ docker push testgroupregistry.azurecr.io/samples/hello-world:1.0.0
  1. Create a container instance There is template file infra/aci.bicep which is a Azure Resource Manager template for creating Azure Container Instance. We will use it to create an ACI and deploy the docker image generated above.
$ az deployment group create --resource-group TestGroup --template-file infra/aci.bicep --parameters name=helloworlddev image=testgroupregistry.azurecr.io/samples/hello-world:1.0.0 registryServer=testgroupregistry.azurecr.io clientId=<client_id> clientSecret=<client_secret> dnsNameLabel=helloworlddevtest port=80

Deploy to Azure using GitHub Actions

Steps in details here.

  1. Store service pricipal credentials in your GitHub repo's secrets:
  AZURE_CREDENTIALS => <the service principal json generated above>
  AZURE_USERNAME => <clientId of the service principal>
  AZURE_PASSWORD => <clientSecret of the service principal>
  1. The .github/workflows/workflow.yml takes care of creating the ACI and deployment on every push.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •