gpt4 book ai didi

azure - 如何将命令传递给 terraform(Azure ACI + osm 切片服务器)

转载 作者:行者123 更新时间:2023-12-03 02:02:38 25 4
gpt4 key购买 nike

我正在尝试在 Azure ACI 上设置 overv/openstreetmap-tile-server 镜像,但我不知道如何传递命令 “run”“import”到容器。

例如,如果我在 terraform 代码下运行:

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}

resource "azurerm_storage_account" "example" {
name = "storage-test"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_share" "example" {
name = "osm-data"
storage_account_name = azurerm_storage_account.example.name
quota = 50
}

resource "azurerm_storage_share" "examplee" {
name = "osm-tiles"
storage_account_name = azurerm_storage_account.example.name
quota = 50
}


resource "azurerm_container_group" "example" {
name = "example-continst"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_address_type = "Public"
dns_name_label = "mapss11"
os_type = "Linux"
restart_policy = "Never"

container {
name = "maps"
image = "overv/openstreetmap-tile-server"
cpu = "2"
memory = "16"

ports {
port = 80
protocol = "TCP"
}

volume {
name = "osm-data"
mount_path = "/data/database/"
read_only = false
share_name = azurerm_storage_share.example.name

storage_account_name = azurerm_storage_account.example.name
storage_account_key = azurerm_storage_account.example.primary_access_key
}

volume {
name = "osm-tiles"
mount_path = "/data/tiles/"
read_only = false
share_name = azurerm_storage_share.examplee.name

storage_account_name = azurerm_storage_account.example.name
storage_account_key = azurerm_storage_account.example.primary_access_key
}
}

tags = {
environment = "testing"
}
}

我可以看到以下信息:

usage: <import|run>
commands:
import: Set up the database and import /data/region.osm.pbf
run: Runs Apache and renderd to serve tiles at /tile/{z}/{x}/{y}.png
environment variables:
THREADS: defines number of threads used for importing / tile rendering
UPDATES: consecutive updates (enabled/disabled)
NAME_LUA: name of .lua script to run as part of the style
NAME_STYLE: name of the .style to use
NAME_MML: name of the .mml file to render to mapnik.xml
NAME_SQL: name of the .sql file to use

enter image description here

如果我将命令部分添加到terraform,例如:

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West Europe"
}

resource "azurerm_storage_account" "example" {
name = "storagetestxx"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "azurerm_storage_share" "example" {
name = "osm-data"
storage_account_name = azurerm_storage_account.example.name
quota = 50
}

resource "azurerm_storage_share" "examplee" {
name = "osm-tiles"
storage_account_name = azurerm_storage_account.example.name
quota = 50
}



resource "azurerm_container_group" "example" {
name = "example-continst"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
ip_address_type = "Public"
dns_name_label = "mapss11"
os_type = "Linux"
restart_policy = "Never"

container {
name = "maps"
image = "overv/openstreetmap-tile-server"
cpu = "2"
memory = "16"

commands = [
"/bin/bash", "-c", "import"
]

ports {
port = 80
protocol = "TCP"
}

volume {
name = "osm-data"
mount_path = "/data/database/"
read_only = false
share_name = azurerm_storage_share.example.name

storage_account_name = azurerm_storage_account.example.name
storage_account_key = azurerm_storage_account.example.primary_access_key
}

volume {
name = "osm-tiles"
mount_path = "/data/tiles/"
read_only = false
share_name = azurerm_storage_share.examplee.name

storage_account_name = azurerm_storage_account.example.name
storage_account_key = azurerm_storage_account.example.primary_access_key
}
}

tags = {
environment = "testing"
}
}

我收到此错误:

/bin/bash: line 1: import: command not found

enter image description here

下面你可以看到纯 docker 的样子:

docker run \
-v osm-data:/data/database/ \
-v osm-tiles:/data/tiles/ \
overv/openstreetmap-tile-server \
import

文档:

@更新:我已将命令更改为+添加了一些环境变量:

   commands = [
"import"
]

environment_variables = {
DOWNLOAD_PBF="https://download.geofabrik.de/europe/luxembourg-latest.osm.pbf"
DOWNLOAD_POLY="https://download.geofabrik.de/europe/luxembourg.poly"
}

现在我得到:

Error: Failed to start container maps, Error response: to create containerd task: failed to create shim task: failed to create container 106a87f1f61033aa11ddeee2c0f6b5797157545516e1f55009c34d72ce9b50cf: guest RPC failure: failed to create container: failed to run runc create/exec call for container 106a87f1f61033aa11ddeee2c0f6b5797157545516e1f55009c34d72ce9b50cf with exit status 1: container_linux.go:380: starting container process caused: exec: "run": executable file not found in $PATH: unknown

最佳答案

你为什么不这样做:

commands = ["import"]

如果您查看 overv/openstreetmap-tile-server 图像的 Dockerfile你会发现它有入口点 /run.shThis script依次有以下代码:

if [ "$1" == "import" ]; then
# ...
fi

所以 import 不是一个 shell 命令,它是一个 /run.sh 命令。

关于azure - 如何将命令传递给 terraform(Azure ACI + osm 切片服务器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75642417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com