我需要将文件从 Azure Blob 容器文件夹推送到 GitHub。我有一个 .sh 脚本,在我的笔记本电脑上运行良好。现在我如何在 Azure 云中运行相同的脚本?脚本本身需要 inotifywait(window)或 fswatch(mac)。
任何想法?
答案1
您可以创建一个逻辑应用程序来自动化该过程,或者使用 Azure 存储资源管理器下载文件,然后手动推送它们
这是一个用于创建该逻辑应用程序的示例二头肌模板 iac
param storageAccountName string
param storageContainerName string
param blobTriggerName string
param githubRepositoryOwner string
param githubRepositoryName string
param githubToken string
param githubFilePath string
param logicAppName string
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: logicAppName
location: resourceGroup().location
properties: {
definition: {
$schema: "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
actions: {
// Trigger when a blob is added or modified
'When_a_blob_is_added_or_modified_(properties_only)': {
inputs: {
host: {
connection: {
name: `@parameters('$connections')['azureblob']['connectionId']`
}
},
method: 'get',
path: `/datasets/default/triggers/onupdatedfile`,
authentication: '@parameters('$authentication')['connectionId']'
},
metadata: {
blobName: "@triggerOutputs()?['headers']['x-ms-file-path']",
blobUri: "@triggerOutputs()?['headers']['x-ms-file-path']",
lastModified: "@triggerOutputs()?['headers']['Last-Modified']",
size: "@triggerOutputs()?['headers']['x-ms-blob-content-length']"
},
recurrence: {
frequency: 'OnAdd'
},
splitOn: "@triggerOutputs()?['body']"
},
// List blobs
'List_blobs': {
inputs: {
host: {
connection: {
name: `@parameters('$connections')['azureblob']['connectionId']`
}
},
method: 'get',
path: `/datasets/default/diagnostics',
authentication: '@parameters('$authentication')['connectionId']'
}
},
// For each blob, get content and create or update file in GitHub
'For_each': {
actions: {
'Get_blob_content': {
inputs: {
host: {
connection: {
name: `@parameters('$connections')['azureblob']['connectionId']`
}
},
method: 'get',
path: `/datasets/default/files/@{encodeURIComponent(item().name)}`,
authentication: '@parameters('$authentication')['connectionId']'
},
metadata: {
blobName: "@item().name",
blobUri: "@item().name",
contentSize: "@item().size",
contentTypeId: 'binary'
}
},
'Create_or_update_file': {
inputs: {
method: 'post',
uri: "https://api.github.com/repos/@{githubRepositoryOwner}/@{githubRepositoryName}/contents/@{githubFilePath}/@{encodeURIComponent(item().name)}",
headers: {
Authorization: "Bearer @{githubToken}"
},
body: {
message: "Add blob content to GitHub",
content: "@{base64(outputs('Get_blob_content')?['body'])}"
}
},
runAfter: {
'Get_blob_content': [
'Succeeded'
]
}
}
},
foreach: "@outputs('List_blobs')?['body']['value']"
}
},
triggers: {
manual: {
type: 'manual'
}
}
}
}
}
output logicAppResourceId string = logicApp.id