Skip to content

Commit

Permalink
tweak docker changes and update test to working container spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofallops committed Jan 31, 2023
1 parent 88bee96 commit 3d9ed8c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
12 changes: 7 additions & 5 deletions internal/services/appservice/helpers/function_app_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1590,13 +1590,15 @@ func ExpandSiteConfigLinuxFunctionApp(siteConfig []SiteConfigLinuxFunctionApp, e

if linuxAppStack.Docker != nil && len(linuxAppStack.Docker) == 1 {
dockerConfig := linuxAppStack.Docker[0]
dockerUrl := dockerConfig.RegistryURL
httpPrefixes := []string{"https://", "http://"}
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_URL", dockerUrl, false)
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_URL", dockerConfig.RegistryURL, false)
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_USERNAME", dockerConfig.RegistryUsername, false)
appSettings = updateOrAppendAppSettings(appSettings, "DOCKER_REGISTRY_SERVER_PASSWORD", dockerConfig.RegistryPassword, false)
for _, prefix := range httpPrefixes {
dockerUrl = strings.TrimPrefix(dockerUrl, prefix)
var dockerUrl string
for _, prefix := range urlSchemes {
if strings.HasPrefix(dockerConfig.RegistryURL, prefix) {
dockerUrl = strings.TrimPrefix(dockerConfig.RegistryURL, prefix)
continue
}
}
expanded.LinuxFxVersion = utils.String(fmt.Sprintf("DOCKER|%s/%s:%s", dockerUrl, dockerConfig.ImageName, dockerConfig.ImageTag))
}
Expand Down
15 changes: 12 additions & 3 deletions internal/services/appservice/helpers/fx_strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

var urlSchemes = []string{
"https://",
"HTTPS://",
"http://",
"HTTP://",
}

func decodeApplicationStackLinux(fxString string) ApplicationStackLinux {
parts := strings.Split(fxString, "|")
result := ApplicationStackLinux{}
Expand Down Expand Up @@ -189,9 +196,11 @@ func DecodeFunctionAppDockerFxString(input string, partial ApplicationStackDocke
}

dockerUrl := partial.RegistryURL
urlPrefix := []string{"https://", "http://"}
for _, prefix := range urlPrefix {
dockerUrl = strings.TrimPrefix(dockerUrl, prefix)
for _, prefix := range urlSchemes {
if strings.HasPrefix(dockerUrl, prefix) {
dockerUrl = strings.TrimPrefix(dockerUrl, prefix)
continue
}
}
dockerParts := strings.Split(strings.TrimPrefix(parts[1], dockerUrl), ":")
if len(dockerParts) != 2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2334,11 +2334,13 @@ resource "azurerm_linux_function_app" "test" {
storage_account_access_key = azurerm_storage_account.test.primary_access_key
site_config {
always_on = true
application_stack {
docker {
registry_url = "https://mcr.microsoft.com"
image_name = "azure-app-service/samples/aspnethelloworld"
image_tag = "latest"
image_name = "azure-functions/dotnet"
image_tag = "3.0-appservice-quickstart"
}
}
}
Expand Down

0 comments on commit 3d9ed8c

Please sign in to comment.