Chuyển đến nội dung chính

ARM Template

ARM là gì?

Azure Resource Manager (ARM) là một dịch vụ quản lý tài nguyên của Microsoft Azure. Nó là một framework cho phép bạn triển khai và quản lý tài nguyên trong môi trường Azure. ARM cung cấp một cách thức đơn giản và linh hoạt để triển khai và quản lý các tài nguyên của bạn trong Azure, từ máy ảo và dịch vụ lưu trữ đến các tài nguyên mạng và các thành phần khác.

Declarative Programming là gì?

Declarative programming là mô hình lập trình trong đó lập trình viên chỉ định kết quả mong muốn, thay vì chỉ định các bước cụ thể để đạt được kết quả đó. Mô hình này thường được sử dụng để viết các chương trình có logic đơn giản, hoặc các chương trình cần được tối ưu hóa về hiệu suất.

Ví dụ: Với cách viết code thông thường (Imperative programming)

let array = [1, 2, 3, 4, 5, 6]
var reduced = 0
var filtered = []

for element in array {
  reduced += element
  if element % 2 == 1 {
    filtered.append(element)
  }
}
Viết theo kiểu Declarative Progrmming
let array = [1, 2, 3, 4, 5, 6]
let numbers = [1, 2, 3, 4, 5, 6]
let sum = reduce(numbers, 0, +)
let odds = filter(numbers, { $0 % 2 == 1})

Lưu ý là bạn cần có implement các hàm hoặc sử dụng hàm trong thư viện.

Deploy ARM Template bằng Azure CLI

Tạo file template.json như sau:
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.5.6.12127",
      "templateHash": "17016281914347876853"
    }
  },
  "parameters": {
    "name": {
      "type": "string",
      "defaultValue": "acilinuxpublicipcontainergroup",
      "metadata": {
        "description": "Name for the container group"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "image": {
      "type": "string",
      "defaultValue": "mcr.microsoft.com/azuredocs/aci-helloworld",
      "metadata": {
        "description": "Container image to deploy. Should be of the form repoName/imagename:tag for images stored in public Docker Hub, or a fully qualified URI for other registries. Images from private registries require additional registry credentials."
      }
    },
    "port": {
      "type": "int",
      "defaultValue": 80,
      "metadata": {
        "description": "Port to open on the container and the public IP address."
      }
    },
    "cpuCores": {
      "type": "int",
      "defaultValue": 1,
      "metadata": {
        "description": "The number of CPU cores to allocate to the container."
      }
    },
    "memoryInGb": {
      "type": "int",
      "defaultValue": 2,
      "metadata": {
        "description": "The amount of memory to allocate to the container in gigabytes."
      }
    },
    "restartPolicy": {
      "type": "string",
      "defaultValue": "Always",
      "allowedValues": [
        "Always",
        "Never",
        "OnFailure"
      ],
      "metadata": {
        "description": "The behavior of Azure runtime if container has stopped."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2021-09-01",
      "name": "[parameters('name')]",
      "location": "[parameters('location')]",
      "properties": {
        "containers": [
          {
            "name": "[parameters('name')]",
            "properties": {
              "image": "[parameters('image')]",
              "ports": [
                {
                  "port": "[parameters('port')]",
                  "protocol": "TCP"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": "[parameters('cpuCores')]",
                  "memoryInGB": "[parameters('memoryInGb')]"
                }
              }
            }
          }
        ],
        "osType": "Linux",
        "restartPolicy": "[parameters('restartPolicy')]",
        "ipAddress": {
          "type": "Public",
          "ports": [
            {
              "port": "[parameters('port')]",
              "protocol": "TCP"
            }
          ]
        }
      }
    }
  ],
  "outputs": {
    "containerIPv4Address": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('name'))).ipAddress.ip]"
    }
  }
}

Bạn mở Azure Portal, mở Bash session từ Cloud Shell panel. Sau đó bấm chọn Show advanced settings.

Thêm thông tin storage account và fileshare. Sau đó bấm Create storage

Trong Cloud Shell Panel, bấm Upload rồi chọn file để upload lên.

VD: upload file template.json

Sau đó bạn gõ lệnh

az deployment group create --resource-group <resource-group-name> --template-file <path-to-template-file> --parameters name=<container-name>

Bạn thay thế 

  • resource-group-name: tên resource group mà bạn muốn chứa resource
  • path-to-template: đường dẫn tới file json vừa được upload
  • container-name: tên container mà bạn muốn tạo

VD:

az deployment group create --resource-group rg_eastus_1234 --template-file template.json --parameters name=abc

Kiểm tra kết quả bằng cách vào View all resources


Tham khảo

https://tutorialsdojo.com/azure-101-azure-resource-manager-and-arm-templates/

https://www.netguru.com/blog/imperative-vs-declarative

Labs: https://learn.microsoft.com/en-us/azure/container-instances/container-instances-quickstart-template

Nhận xét

Bài đăng phổ biến từ blog này

[ASP.NET MVC] Authentication và Authorize

Một trong những vấn đề bảo mật cơ bản nhất là đảm bảo những người dùng hợp lệ truy cập vào hệ thống. ASP.NET đưa ra 2 khái niệm: Authentication và Authorize Authentication xác nhận bạn là ai. Ví dụ: Bạn có thể đăng nhập vào hệ thống bằng username và password hoặc bằng ssh. Authorization xác nhận những gì bạn có thể làm. Ví dụ: Bạn được phép truy cập vào website, đăng thông tin lên diễn đàn nhưng bạn không được phép truy cập vào trang mod và admin.

ASP.NET MVC: Cơ bản về Validation

Validation (chứng thực) là một tính năng quan trọng trong ASP.NET MVC và được phát triển trong một thời gian dài. Validation vắng mặt trong phiên bản đầu tiên của asp.net mvc và thật khó để tích hợp 1 framework validation của một bên thứ 3 vì không có khả năng mở rộng. ASP.NET MVC2 đã hỗ trợ framework validation do Microsoft phát triển, tên là Data Annotations. Và trong phiên bản 3, framework validation đã hỗ trợ tốt hơn việc xác thực phía máy khách, và đây là một xu hướng của việc phát triển ứng dụng web ngày nay.

Tổng hợp một số kiến thức lập trình về Amibroker

Giới thiệu về Amibroker Amibroker theo developer Tomasz Janeczko được xây dựng dựa trên ngôn ngữ C. Vì vậy bộ code Amibroker Formula Language sử dụng có syntax khá tương đồng với C, ví dụ như câu lệnh #include để import hay cách gói các object, hàm trong các block {} và kết thúc câu lệnh bằng dấu “;”. AFL trong Amibroker là ngôn ngữ xử lý mảng (an array processing language). Nó hoạt động dựa trên các mảng (các dòng/vector) số liệu, khá giống với cách hoạt động của spreadsheet trên excel.