Hi all :grinning:, do you know if there is a way t...
# azure
c
Hi all 😀, do you know if there is a way to achieve exactly this specific case with Pulumi? https://docs.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-quick-task What I want is to mimic the behavior of
az acr build --registry myRegistry --image hello:v1 .
With this specific command the local build context is directly uploaded to the registry and the build will be done by ACR. I see that we have https://www.pulumi.com/registry/packages/azure-native/api-docs/containerregistry/taskrun/ that can be configured with a
DockerBuildRequestArgs
like this
Copy code
var buildContextArchive = new FileArchive(buildContext);
const string buyBuildTaskRunName = "buy-build-task-run";
var buyBuildTaskRun = new TaskRun(buyBuildTaskRunName, new TaskRunArgs
{
    TaskRunName = buyBuildTaskRunName,
    RegistryName = containerRegistry.Name,
    ResourceGroupName = resourceGroup.Name,
    ForceUpdateTag = buyImageNameFull,
    RunRequest = new DockerBuildRequestArgs
    {
        SourceLocation = "here I need the url after the uplaod of the local context",
        DockerFilePath = "Dockerfile.buy",
        ImageNames = 
        {
            buyImageNameFull
        },
        IsPushEnabled = true,
        NoCache = false,
        Type = "DockerBuildRequest",
        Platform = new PlatformPropertiesArgs
        {
            Architecture = "amd64",
            Os = "Linux"
        }
    }
});
but the problem is that
SourceLocation
must be a valid url so someway I need to uplaod the local context somewhere (doesn’t work with local hard drive paths). I do not want to point directly to the github repo url (imagine this inside an azure devops pipeline for example…the source code is local, already pulled by the pipeline)
@tall-librarian-49374 is there a way to create a .tar file with a
FileArchive
? I can then upload it on an azure storage account and reference its url in the azure container registry task. Pretty much the same idea of the azure functions run_from_package https://github.com/pulumi/examples/blob/master/azure-cs-functions/FunctionsStack.cs I can also use
az acr build
directly with a Pulumi.Command but the command has problems when used in an azure devops pipeline and trying to understand what is going wrong it's not easy https://github.com/pulumi/pulumi-command/issues/32 The azure cli (az) it is already installed by default on every azure pipeline hosted agent
t
I always thought tar and zip are somewhat interchangeable. If not, I guess you can create a tar file with a 3rd party utility function and then upload it with
FileAsset
c
Hi @tall-librarian-49374 at the end with a
.tar.gz
it works, trying with a .zip or just passing the content of a folder to the FileArchive it does not. Now I’m facing another error 😂, the build task runs successfully in azure container registry but seems there is something wrong in the
Feature#WaitForCompletion
. I get this error:
Copy code
Future#WaitForCompletion: the number of retries has been exceeded: StatusCode=404 -- Original Error: Code="Creating" Message="The async operation failed." AdditionalInfo=[{"status":"Creating"}]
Seems something like this issue you found some time ago https://github.com/Azure/go-autorest/issues/596 I’m not able to find the specs about ACR task run here https://github.com/Azure/azure-rest-api-specs/blob/main/specification/containerreg[…]soft.ContainerRegistry/stable/2021-09-01/containerregistry.json
Copy code
const string buyBuildTaskName = "buy-build-task";
var buyBuildTask = new ACR.Task(buyBuildTaskName, new TaskArgs
{
    TaskName = buyBuildTaskName,
    RegistryName = containerRegistry.Name,
    ResourceGroupName = resourceGroup.Name,
    Status = ACR.TaskStatus.Enabled,
    IsSystemTask = false,
    AgentConfiguration = new AgentPropertiesArgs
    {
        Cpu = 2
    },
    Identity = new IdentityPropertiesArgs
    {
        Type = ACR.ResourceIdentityType.SystemAssigned
    },
    Platform = new PlatformPropertiesArgs
    {
        Architecture = Architecture.Amd64,
        Os = OS.Linux
    },
    Step = new DockerBuildStepArgs
    {
        ContextPath = BuildContextBlobUrl,
        DockerFilePath = "Dockerfile.buy",
        ImageNames = 
        {
            BuyImageTag
        },
        IsPushEnabled = true,
        NoCache = false,
        Type = "Docker"
    }
});

const string buyBuildTaskRunName = "buy-build-task-run";
var buyBuildTaskRun = new TaskRun(buyBuildTaskRunName, new TaskRunArgs
{
    RegistryName = containerRegistry.Name,
    ResourceGroupName = resourceGroup.Name,
    ForceUpdateTag = "t2", //fake tag just to force the update
    RunRequest = new TaskRunRequestArgs
    {
        TaskId = buyBuildTask.Id,
        Type = "TaskRunRequest"
    }
});
t
The async operation failed
sounds like an Azure error. Any chance you can see its details in activity logs of the resource or resource group?
c
I try to check and I’ll let you know, the second time pulumi up runs everything seems then ok, it’s a first time failure on task run update
@tall-librarian-49374 looking at the the activity log in the azure blade everything seems ok
is there a way to understand what the pulumi provider is waiting for?
t
You could write verbose logs and find all HTTP requests and responses there if you want to understand exactly what is going on
c
like pulumi up --debug --logtostderr -v=9 ?? already tried without getting useful info
t
yes, this makes azure native log all http requests
c
Sorry @tall-librarian-49374 I’m not sure what I have to look at inside the log, it seems that a certain point it receives an Unknown error then the message is just what I already posted here Here attached the log
t
Could you try again with the
--logflow
flag?
c
cb1b is the run id of the task that succeeds but seems there is problem getting the result. The task requires more or less 1 minute to complete, the pulumi up takes more than 4 minutes, it retries to ask for the status until the max num of retries and then fails?
@tall-librarian-49374 I have a call with a customer now, I’ll be back in 1 hour. If we can solve this I’m quite happy, I can close the circle of whaat I want to show.
t
I don’t know how this can be solved other than changing the code TBH… Could you please file an issue for this?
c
ok, I do it just after the work
@tall-librarian-49374 done, https://github.com/pulumi/pulumi-azure-native/issues/1713 thank you 😅
👍 1
so actually I’m another time a little bit stuck 😔, If I find something else useful I’ll let you know
@tall-librarian-49374 maybe you already saw this but looking at this part of the log I can see that the value provided in the
Azure-Asyncoperation
the second time seems not correct --> /operationStatuses/cb1b/operationStatuses/cb1b is present two times --> this I suppose leads to a 404 not found
m
az acr build - I spent some time looking at this and I nearly got it but unfortunately hit a wall when tried to upload the blob part as pulumi blob doesn't let you pass in a SAS to auth to the ACR upload url
c
@tall-librarian-49374 if the one outlined is problem there is something that you can do at the provider level or it is completely in charge of the ARM specification team? @mysterious-mouse-98391 where do you want to upload the blob? I suppose that under the hood Azure Container Registry has it’s own storage to support things like
az acr build
or the new
az container app up
but I did not really understand how to do this using the pulumi azure provider. So I created a separate azure storage with a container and I upload the
.tar.gz
of the docker build context there. You can generate the SAS url of the blob and pass it to the task.
Copy code
static Output<string> SignedBlobReadUrl(Storage.Blob blob, Storage.BlobContainer container, Storage.StorageAccount account, ResourceGroup resourceGroup)
{
    var serviceSasToken = Storage.ListStorageAccountServiceSAS.Invoke(new Storage.ListStorageAccountServiceSASInvokeArgs
    {
        AccountName = account.Name,
        Protocols = Storage.HttpProtocol.Https,
        SharedAccessStartTime = "2022-05-01",
        SharedAccessExpiryTime = "2022-12-31",
        Resource = Storage.SignedResource.C,
        ResourceGroupName = resourceGroup.Name,
        Permissions = Storage.Permissions.R,
        CanonicalizedResource = Output.Format($"/blob/{account.Name}/{container.Name}"),
        ContentType = "application/json",
        CacheControl = "max-age=5",
        ContentDisposition = "inline",
        ContentEncoding = "deflate",
    }).Apply(blobSAS => blobSAS.ServiceSasToken);

    return Output.Format($"https://{account.Name}.<http://blob.core.windows.net/{container.Name}/{blob.Name}?{serviceSasToken}%22);|blob.core.windows.net/{container.Name}/{blob.Name}?{serviceSasToken}");>
}
m
@cold-insurance-72507 so in Pulumi for ACR there is a function that returns the internal ACR blob storage place which is where the az build command puts it to. It outputs a relative path and an upload url , however the az build command can use the SAS provided where as the pulumi blob provider doesn't seem able to. if it did you could replied the az build behaviour by building the ACR , getting the upload url and SAS that comes with it , zipping and uploading locally to the ACR upload url, using the SAS for permissions, and then passing the relative url to the Task Run as the Source with the blob appended. Which is what az build seems to be doing under the hood. https://www.pulumi.com/registry/packages/azure-native/api-docs/containerregistry/listregistrybuildsourceuploadurl/
@cold-insurance-72507 I suppose could try using pulumi to grant a Blob Data RBAC role too and then the SAS might not be required.
c
@mysterious-mouse-98391 yes I saw the
listRegistryBuildSourceUploadUrl
but I didn't investigate it so much. But the problem relative to the task run is still here also in that case...failing the task run then fails also the deploy of the azure container app... in pulumi I mean...
m
@cold-insurance-72507 yeah I'm pretty sure you can't mimic it exactly, you need to be able to pass the SAS to create the blob there and you don't seem able to. Think you'd have to do as you're doing, put it to a blob storage you already have perms to. Though also if you gzip locally and point to complete url locally maybe it will work ? so like source: ./myfolder/dockerfile.tar.gz.