Skip to content

Commit

Permalink
ACR 3.0 SDK (support ACR Build/Task GA Service)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsgouda authored Oct 3, 2018
2 parents f4b52ac + a3779a2 commit 502fab5
Show file tree
Hide file tree
Showing 82 changed files with 4,263 additions and 4,670 deletions.
2 changes: 1 addition & 1 deletion src/SDKs/ContainerRegistry/AzSdk.RP.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--This file and it's contents are updated at build time moving or editing might result in build failure. Take due deligence while editing this file-->
<PropertyGroup>
<AzureApiTag>ContainerRegistry_2018-02-01-preview;ContainerRegistry_2017-10-01;</AzureApiTag>
<AzureApiTag>ContainerRegistry_2017-10-01;ContainerRegistry_2018-09-01;</AzureApiTag>
<PackageTags>$(PackageTags);$(CommonTags);$(AzureApiTag);</PackageTags>
</PropertyGroup>
</Project>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Text;
using Xunit;
using Sku = Microsoft.Azure.Management.ContainerRegistry.Models.Sku;

Expand Down Expand Up @@ -361,5 +361,135 @@ public void ContainerRegistryReplicationTest()
registryClient.Registries.Delete(resourceGroup.Name, registry.Name);
}
}

[Fact]
public void ContainerRegistryTaskTest()
{
var handler = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };

using (MockContext context = MockContext.Start(this.GetType().FullName))
{
var resourceClient = ContainerRegistryTestUtilities.GetResourceManagementClient(context, handler);
var registryClient = ContainerRegistryTestUtilities.GetContainerRegistryManagementClient(context, handler);

// Create resource group
var resourceGroup = ContainerRegistryTestUtilities.CreateResourceGroup(resourceClient);
var nonDefaultLocation = ContainerRegistryTestUtilities.GetNonDefaultRegistryLocation(resourceClient, resourceGroup.Location);

// Create container registry
var registry = ContainerRegistryTestUtilities.CreateManagedContainerRegistry(registryClient, resourceGroup.Name, nonDefaultLocation);

// Crete task
var task = registryClient.Tasks.Create(
resourceGroup.Name,
registry.Name,
TestUtilities.GenerateName("acrtask"),
new Task(
location: registry.Location,
platform: new PlatformProperties { Architecture = Architecture.Amd64, Os = OS.Linux },
step: new DockerBuildStep(
dockerFilePath: "Dockerfile",
baseImageDependencies: null,
contextPath: "https://github.com/azure/acr-builder.git",
imageNames: new List<string> { "image:{{.Run.ID}}", "image:latest" },
isPushEnabled: true,
noCache: true,
arguments: null),
agentConfiguration: new AgentProperties(cpu: 2),
status: "Enabled",
timeout: 600,
trigger: new TriggerProperties(
sourceTriggers: null,
baseImageTrigger: new BaseImageTrigger(BaseImageTriggerType.Runtime, "defaultBaseimageTriggerName", TriggerStatus.Enabled))
));

Assert.NotNull(task);

// List task
var taskList = registryClient.Tasks.List(resourceGroup.Name, registry.Name);
Assert.Single(taskList);

// Update task
task = registryClient.Tasks.Update(resourceGroup.Name, registry.Name, task.Name, new TaskUpdateParameters(
timeout: 900
));

Assert.Equal(900, task.Timeout);

// Schedule a run from task
var run1 = registryClient.Registries.ScheduleRun(resourceGroup.Name, registry.Name,
new TaskRunRequest(
task.Name,
values: new List<SetValue> { new SetValue("key1", "value1"), new SetValue("key2", "value2", isSecret: true) }));

Assert.Equal("ca1", run1.RunId);

// Cancel the run
registryClient.Runs.Cancel(resourceGroup.Name, registry.Name, run1.RunId);

// Schedule a docker build run
var run2 = registryClient.Registries.ScheduleRun(resourceGroup.Name, registry.Name,
new DockerBuildRequest(
dockerFilePath: "Dockerfile",
platform: new PlatformProperties { Architecture = Architecture.Amd64, Os = OS.Linux },
isArchiveEnabled: false,
imageNames: new List<string> { "testimage1:tag1", "testimage2:tag2" },
isPushEnabled: false,
noCache: true,
arguments: new List<Argument> { new Argument("param1", "value1", isSecret: true) },
timeout: 600,
agentConfiguration: new AgentProperties(cpu: 2),
sourceLocation: "https://github.com/azure/acr-builder.git"));

Assert.Equal("ca2", run2.RunId);

// Schedule a file based task run
var run3 = registryClient.Registries.ScheduleRun(resourceGroup.Name, registry.Name,
new FileTaskRunRequest(
taskFilePath: "acb.yaml",
platform: new PlatformProperties { Architecture = Architecture.Amd64, Os = OS.Linux },
isArchiveEnabled: false,
valuesFilePath: null,
values: new List<SetValue> { new SetValue("key1", "value1"), new SetValue("key2", "value2", isSecret: true) },
timeout: 600,
agentConfiguration: new AgentProperties(cpu: 2),
sourceLocation: "https://github.com/azure/acr-builder.git"));

Assert.Equal("ca3", run3.RunId);

// Schedule an encoded task run
string taskString =
@"
steps:
-build: . -t acb:linux-{{.Run.ID}}";
string valuesString =
@"
key1: value1
key2: value2
";
var run4 = registryClient.Registries.ScheduleRun(resourceGroup.Name, registry.Name,
new EncodedTaskRunRequest(
encodedTaskContent: Convert.ToBase64String(Encoding.UTF8.GetBytes(taskString)),
platform: new PlatformProperties { Architecture = Architecture.Amd64, Os = OS.Linux },
isArchiveEnabled: false,
encodedValuesContent: Convert.ToBase64String(Encoding.UTF8.GetBytes(valuesString)),
values: null,
timeout: 600,
agentConfiguration: new AgentProperties(cpu: 2),
sourceLocation: "https://github.com/azure/acr-builder.git"));

Assert.Equal("ca4", run4.RunId);

// List runs
var runList = registryClient.Runs.List(resourceGroup.Name, registry.Name);
Assert.Equal(4, runList.Count());

// Delete the task
registryClient.Tasks.Delete(resourceGroup.Name, registry.Name, task.Name);

// Delete the container registry
registryClient.Registries.Delete(resourceGroup.Name, registry.Name);
}
}
}
}
Loading

0 comments on commit 502fab5

Please sign in to comment.