Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACR-3.0.0 API upgrade #506

Merged
merged 117 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
05b3138
Merge pull request #21 from AzureCR/master
Jul 25, 2018
a7be0b3
Added Azure Credentials Manager Singleton (#18)
Jul 25, 2018
b2e5740
Sorted Existing Create Registry ready for code review
Jul 25, 2018
ef1ccfa
Added acquiring telemetry data for create registry
rsamai Jul 25, 2018
1fca0da
broke up createnewresourcegroup method and fixed client use
rsamai Jul 26, 2018
60f68d3
Jackson esteban/unified client nit Fix (#24)
Jul 26, 2018
26f00e2
Enabled location selection
rsamai Jul 26, 2018
fe0fe2f
Location request fixes
rsamai Jul 30, 2018
5c8d364
Refactor while loop for new res group
rsamai Jul 30, 2018
a61c728
Added SKU selection
rsamai Jul 30, 2018
9b51397
Quick fix- initializing array syntax
rsamai Jul 30, 2018
048eb67
Added specific error messages and comments
rsamai Aug 1, 2018
bc905d8
Merge pull request #30 from AzureCR/master
rsamai Aug 2, 2018
37d8a27
Merge pull request #22 from AzureCR/Esteban-Julia-Rutu/CreateRegistry
rsamai Aug 2, 2018
b80af87
Julia/delete image (#29)
julialieberman Aug 4, 2018
f4f1924
copied previous push to acr into new pull-from-azure.ts file
rsamai Aug 6, 2018
e2cf013
Merge branch 'dev' into master
jvstokes Aug 7, 2018
64c8282
Merge pull request #42 from AzureCR/master
jvstokes Aug 7, 2018
05df67c
Estebanreyl/dev merge fixes (#43)
Aug 7, 2018
2332645
added acrbuild stuff
jvstokes Aug 7, 2018
7d7a7d5
added acrbuild stuff
jvstokes Aug 7, 2018
17fedec
Update to match utility manager class
jvstokes Aug 7, 2018
126c01e
Rutusamai/list build tasks for each registry (#37)
rsamai Aug 7, 2018
0a8eba4
Added quick pick for selecting resource group and registry
jvstokes Aug 8, 2018
73f6e81
clean
jvstokes Aug 8, 2018
3106ef8
Merge branch 'dev' into Jackson/QuickBuildDev
jvstokes Aug 8, 2018
7c7dcdd
Merge branch 'Jackson/QuickBuildDev' of https://github.com/AzureCR/vs…
jvstokes Aug 8, 2018
53b215a
Added subscription support
jvstokes Aug 8, 2018
108a5bb
utility bug fix
jvstokes Aug 8, 2018
0a3d6e1
Julia/delete repository final (#49)
Aug 9, 2018
19f8b72
Julia/delete registry final (#47)
Aug 9, 2018
2b12ed0
Made loginCredentials method in acrTools more efficient, added Pull I…
rsamai Aug 9, 2018
def6162
added folder select
jvstokes Aug 10, 2018
dc34528
Split the loginCredentials function, added docker login and docker pu…
rsamai Aug 11, 2018
d26247d
Finished pull from azure right click feature
rsamai Aug 13, 2018
a16d877
deleted push to azure
rsamai Aug 13, 2018
2c16571
removed username and password from Azure Registry Node
rsamai Aug 13, 2018
06b0c99
Merge branch 'master2' into dev
Aug 13, 2018
d694255
Merge pull request #52 from AzureCR/master-dev-merge
rsamai Aug 13, 2018
57f3912
Clean up
rsamai Aug 13, 2018
6e18256
copied previous push to acr into new pull-from-azure.ts file
rsamai Aug 6, 2018
47642b1
Made loginCredentials method in acrTools more efficient, added Pull I…
rsamai Aug 9, 2018
dc02f2b
Split the loginCredentials function, added docker login and docker pu…
rsamai Aug 11, 2018
e02d9d5
Finished pull from azure right click feature
rsamai Aug 13, 2018
086a574
deleted push to azure
rsamai Aug 13, 2018
9cadc21
Clean up
rsamai Aug 13, 2018
a0ccbb5
Merge branch 'rutusamai/pullFromACR' of https://github.com/AzureCR/vs…
rsamai Aug 13, 2018
dc77b1a
Working again after rebasing and resolving merge conflicts
rsamai Aug 14, 2018
1f3b25a
Updates and fixes
jvstokes Aug 14, 2018
9736b40
Fixes from PR comments
rsamai Aug 14, 2018
8c36bb9
uncapitalize AzureRegistryNode
rsamai Aug 14, 2018
6c06d76
Refactoring, prod.
jvstokes Aug 14, 2018
90dc12e
Merge pull request #53 from AzureCR/rutusamai/pullFromACR
rsamai Aug 15, 2018
36853de
Merge branch 'dev' into Jackson/QuickBuildDev
jvstokes Aug 16, 2018
3eed8a1
Flexible OSType
jvstokes Aug 16, 2018
77dd36e
Merge branch 'Jackson/QuickBuildDev' of https://github.com/AzureCR/vs…
jvstokes Aug 16, 2018
341f097
Estebanreyl/ready for production (#55)
Aug 16, 2018
ea9e049
Merge branch 'dev' into Jackson/QuickBuildDev
jvstokes Aug 16, 2018
2331636
Merge branch 'dev' into Jackson/QuickBuildDev
jvstokes Aug 16, 2018
1ee4f10
Jackson/quick build dev (#46)
jvstokes Aug 19, 2018
0a4dcb2
added ID
jvstokes Aug 20, 2018
9912c2e
Merge branch 'dev' into master2
Aug 23, 2018
ad17751
Merge pull request #65 from AzureCR/master2
rsamai Aug 23, 2018
d174c6a
Merge pull request #67 from AzureCR/dev
jvstokes Aug 23, 2018
aa0a5ec
Merge branch 'Jackson/QuickBuildDev' of https://github.com/AzureCR/vs…
jvstokes Aug 23, 2018
c280b12
Move build to azure commands
jvstokes Aug 24, 2018
f5f3ef3
cleanup
jvstokes Aug 24, 2018
b255dad
Relative dockerfile support
jvstokes Aug 24, 2018
34a2787
Removed await, updating list in enumeration
jvstokes Aug 24, 2018
b90dee9
Merge branch 'dev' into master3
Aug 29, 2018
eab4fd8
Merge pull request #69 from AzureCR/master3
rsamai Aug 29, 2018
6a954eb
fixed chdir
jvstokes Aug 29, 2018
1465dff
Merge branch 'dev' into Jackson/QuickBuildDev
jvstokes Aug 29, 2018
71f6fa6
flexible ostype
jvstokes Aug 30, 2018
711351e
Merge branch 'Jackson/QuickBuildDev' of https://github.com/AzureCR/vs…
jvstokes Aug 30, 2018
567bf5d
Merge pull request #68 from AzureCR/Jackson/QuickBuildDev
jvstokes Sep 3, 2018
d90ed09
Rutusamai/Show Build Task properties (#70)
rsamai Sep 4, 2018
a6825ae
Merge branch 'dev' of https://github.com/AzureCR/vscode-docker into m…
Sep 7, 2018
9c4d367
merge
Sep 7, 2018
216bb2f
missed small changes
Sep 7, 2018
d74649c
Merge branch 'dev' into master4
Sep 7, 2018
cb70c48
Merge pull request #74 from AzureCR/master4
jvstokes Sep 7, 2018
32332ab
Rutusamai/Run a Build Task (#71)
rsamai Sep 13, 2018
ec20087
Estebanreyl/build logs final (#72)
Sep 14, 2018
64a7a95
Adds streaming and command standarization (ext.ui) (#73)
Sep 14, 2018
039b80c
changes for ACR 3.0.0 (#80)
rosanch Sep 18, 2018
d772951
Run task fixed. Issue ID: 79
rosanch Sep 18, 2018
3b723e3
missing changes added
rosanch Sep 18, 2018
4b1e21b
Merge pull request #81 from rosanch/roy/fix79
rosanch Sep 19, 2018
5a9c892
Fixing ACR run logs for Images
rosanch Sep 19, 2018
5580979
Merge pull request #82 from rosanch/roy/image-runlogs
sajayantony Sep 19, 2018
5e54169
Sajaya/top1 (#83)
sajayantony Sep 19, 2018
e12b963
Refactoring build to run and buildTask to task
rosanch Sep 19, 2018
5d90507
Merge pull request #84 from rosanch/roy/refactoring-3.0.0
rosanch Sep 19, 2018
71bcaf4
Update Credentail Management
Jul 25, 2018
3dc9a9c
Removed filter for top (#88)
sajayantony Sep 22, 2018
123dd9a
fixing Image Log Filter
rosanch Sep 24, 2018
acae68c
last dev branch changes added
rosanch Sep 25, 2018
d2dada7
Merge branch 'acr-3.0.0' of https://github.com/AzureCR/vscode-docker …
rosanch Sep 25, 2018
eed8c9d
Merge branch 'master' into acr-3.0.0
rosanch Oct 4, 2018
552310a
fixing tslint error messages
rosanch Oct 11, 2018
010b5e0
Merged conflicts solved.
rosanch Oct 15, 2018
bec82ee
merge conflincts 2
rosanch Oct 15, 2018
6933622
Merge branch 'acr-3.0.0' of https://github.com/AzureCR/vscode-docker …
rosanch Oct 15, 2018
078e45c
tslint fixes 2
rosanch Oct 16, 2018
37d4c75
updating branch to master: 22e45ec7c7ef6ee568f0e592ca614fdcdd3b2c8b
rosanch Oct 26, 2018
1edab2c
First PR #506 review Update include:
rosanch Nov 3, 2018
e75a205
merge conflicts update to #607
rosanch Nov 3, 2018
75f3c64
Hide Azure Quick Build if Azure Account not available
StephenWeatherford Nov 5, 2018
c7eb304
Second PR #506 review update.
rosanch Nov 6, 2018
ca23731
Merge branch 'acr-3.0.0' of https://github.com/AzureCR/vscode-docker …
rosanch Nov 6, 2018
a8ac042
Merge branch 'master' of https://github.com/Microsoft/vscode-docker i…
rosanch Nov 6, 2018
50bc53b
Improving Logs generation Error handeling
rosanch Nov 7, 2018
6d9d350
Third PR #506 review update.
rosanch Nov 7, 2018
c3dea7d
UploadSourceCode no longer has to change process working directory.
rosanch Nov 9, 2018
5f21cd9
Merge Conflict update to Microsoft/Master 611
rosanch Nov 9, 2018
ea6e794
lint fix
rosanch Nov 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 115 additions & 0 deletions commands/azureCommands/acr-build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { ContainerRegistryManagementClient } from 'azure-arm-containerregistry/lib/containerRegistryManagementClient';
StephenWeatherford marked this conversation as resolved.
Show resolved Hide resolved
rosanch marked this conversation as resolved.
Show resolved Hide resolved
rosanch marked this conversation as resolved.
Show resolved Hide resolved
import { Registry, Run, SourceUploadDefinition } from 'azure-arm-containerregistry/lib/models';
import { DockerBuildRequest } from "azure-arm-containerregistry/lib/models";
import { Subscription } from 'azure-arm-resource/lib/subscription/models';
import { BlobService, createBlobServiceWithSas } from "azure-storage";
import * as fs from 'fs';
import * as os from 'os';
import * as process from 'process';
import * as tar from 'tar';
import * as url from 'url';
import * as vscode from "vscode";
import { IAzureQuickPickItem } from 'vscode-azureextensionui';
import { ext } from '../../extensionVariables';
import { getBlobInfo, getResourceGroupName, IBlobInfo, streamLogs } from "../../utils/Azure/acrTools";
import { AzureUtilityManager } from "../../utils/azureUtilityManager";
import { Item, resolveDockerFileItem } from '../build-image';
import { quickPickACRRegistry, quickPickNewImageName, quickPickSubscription } from '../utils/quick-pick-azure';
rosanch marked this conversation as resolved.
Show resolved Hide resolved

const idPrecision = 6;
const vcsIgnoreList = ['.git', '.gitignore', '.bzr', 'bzrignore', '.hg', '.hgignore', '.svn'];
const status = vscode.window.createOutputChannel('ACR Build status');
rosanch marked this conversation as resolved.
Show resolved Hide resolved

// Prompts user to select a subscription, resource group, then registry from drop down. If there are multiple folders in the workspace, the source folder must also be selected.
// The user is then asked to name & tag the image. A build is queued for the image in the selected registry.
// Selected source code must contain a path to the desired dockerfile.
export async function queueBuild(dockerFileUri?: vscode.Uri): Promise<void> {
rosanch marked this conversation as resolved.
Show resolved Hide resolved
//Acquire information from user
const subscription: Subscription = await quickPickSubscription();

const client: ContainerRegistryManagementClient = await AzureUtilityManager.getInstance().getContainerRegistryManagementClient(subscription);
const registry: Registry = await quickPickACRRegistry(true);

const resourceGroupName: string = getResourceGroupName(registry);
rosanch marked this conversation as resolved.
Show resolved Hide resolved

const osPick = ['Linux', 'Windows'].map(item => <IAzureQuickPickItem<string>>{ label: item, data: item });
const osType: string = (await ext.ui.showQuickPick(osPick, { 'canPickMany': false, 'placeHolder': 'Select image base OS' })).data;

const imageName: string = await quickPickNewImageName();

//Begin readying build
status.show();

let folder: vscode.WorkspaceFolder;
if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length === 1) {
rosanch marked this conversation as resolved.
Show resolved Hide resolved
folder = vscode.workspace.workspaceFolders[0];
} else {
folder = await vscode.window.showWorkspaceFolderPick();
}
const dockerItem: Item = await resolveDockerFileItem(folder, dockerFileUri);
rosanch marked this conversation as resolved.
Show resolved Hide resolved
const sourceLocation: string = folder.uri.path;
const tarFilePath: string = getTempSourceArchivePath();

const uploadedSourceLocation: string = await uploadSourceCode(client, registry.name, resourceGroupName, sourceLocation, tarFilePath, folder);
status.appendLine("Uploaded Source Code to " + tarFilePath);

const runRequest: DockerBuildRequest = {
type: 'DockerBuildRequest',
imageNames: [imageName],
isPushEnabled: true,
sourceLocation: uploadedSourceLocation,
platform: { os: osType },
dockerFilePath: dockerItem.relativeFilePath
};
status.appendLine("Set up Run Request");

const run: Run = await client.registries.scheduleRun(resourceGroupName, registry.name, runRequest);
status.appendLine("Schedule Run " + run.runId);
rosanch marked this conversation as resolved.
Show resolved Hide resolved

await streamLogs(registry, run, status, client);
}

async function uploadSourceCode(client: ContainerRegistryManagementClient, registryName: string, resourceGroupName: string, sourceLocation: string, tarFilePath: string, folder: vscode.WorkspaceFolder): Promise<string> {
status.appendLine(" Sending source code to temp file");
let source: string = sourceLocation.substring(1);
rosanch marked this conversation as resolved.
Show resolved Hide resolved
let current: string = process.cwd();
process.chdir(source);
rosanch marked this conversation as resolved.
Show resolved Hide resolved
fs.readdir(source, (err, items) => {
rosanch marked this conversation as resolved.
Show resolved Hide resolved
items = filter(items);
// tslint:disable-next-line:no-unsafe-any
tar.c({}, items).pipe(fs.createWriteStream(tarFilePath));
process.chdir(current);
});

status.appendLine(" Getting Build Source Upload Url ");
let sourceUploadLocation: SourceUploadDefinition = await client.registries.getBuildSourceUploadUrl(resourceGroupName, registryName);
let upload_url: string = sourceUploadLocation.uploadUrl;
let relative_path: string = sourceUploadLocation.relativePath;

status.appendLine(" Getting blob info from Upload Url ");
// Right now, accountName and endpointSuffix are unused, but will be used for streaming logs later.
let blobInfo: IBlobInfo = getBlobInfo(upload_url);
status.appendLine(" Creating Blob Service ");
let blob: BlobService = createBlobServiceWithSas(blobInfo.host, blobInfo.sasToken);
status.appendLine(" Creating Block Blob ");
blob.createBlockBlobFromLocalFile(blobInfo.containerName, blobInfo.blobName, tarFilePath, (): void => { });
return relative_path;
}

function getTempSourceArchivePath(): string {
/* tslint:disable-next-line:insecure-random */
let id: number = Math.floor(Math.random() * Math.pow(10, idPrecision));
status.appendLine("Setting up temp file with 'sourceArchive" + id + ".tar.gz' ");
let tarFilePath: string = url.resolve(os.tmpdir(), `sourceArchive${id}.tar.gz`);
return tarFilePath;
}

function filter(list: string[]): string[] {
rosanch marked this conversation as resolved.
Show resolved Hide resolved
let result: string[] = [];
for (let file of list) {
if (vcsIgnoreList.indexOf(file) === -1) {
result.push(file);
}
}
return result;
}
70 changes: 70 additions & 0 deletions commands/azureCommands/acr-logs-utils/logFileManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { BlobService, createBlobServiceWithSas } from 'azure-storage';
import * as fs from 'fs';
import * as vscode from 'vscode';
import { getBlobInfo, IBlobInfo } from '../../../utils/Azure/acrTools';

export class LogContentProvider implements vscode.TextDocumentContentProvider {
public static scheme: string = 'purejs';
private onDidChangeEvent: vscode.EventEmitter<vscode.Uri> = new vscode.EventEmitter<vscode.Uri>();

constructor() { }

public provideTextDocumentContent(uri: vscode.Uri): string {
let parse: { log: string } = <{ log: string }>JSON.parse(uri.query);
return decodeBase64(parse.log);
}

get onDidChange(): vscode.Event<vscode.Uri> {
return this.onDidChangeEvent.event;
}

public update(uri: vscode.Uri, message: string): void {
this.onDidChangeEvent.fire(uri);
}

}

export function decodeBase64(str: string): string {
return Buffer.from(str, 'base64').toString('ascii');
}

export function encodeBase64(str: string): string {
return Buffer.from(str, 'ascii').toString('base64');
}

/** Loads log text from remote url using azure blobservices */
export function accessLog(url: string, title: string, download: boolean): void {
let blobInfo: IBlobInfo = getBlobInfo(url);
let blob: BlobService = createBlobServiceWithSas(blobInfo.host, blobInfo.sasToken);
blob.getBlobToText(blobInfo.containerName, blobInfo.blobName, async (error, text, result, response) => {
if (response) {
if (download) {
await downloadLog(text, title);
} else {
openLogInNewWindow(text, title);
}
} else if (error) {
throw error;
rosanch marked this conversation as resolved.
Show resolved Hide resolved
}
});
}

function openLogInNewWindow(content: string, title: string): void {
const scheme = 'purejs';
let query = JSON.stringify({ 'log': encodeBase64(content) });
let uri: vscode.Uri = vscode.Uri.parse(`${scheme}://authority/${title}.log?${query}#idk`);
vscode.workspace.openTextDocument(uri).then((doc) => {
return vscode.window.showTextDocument(doc, vscode.ViewColumn.Active + 1, true);
});
}

export async function downloadLog(content: string, title: string): Promise<void> {
let uri = await vscode.window.showSaveDialog({
filters: { 'Log': ['.log', '.txt'] },
defaultUri: vscode.Uri.file(`${title}.log`)
});
fs.writeFile(uri.fsPath, content,
rosanch marked this conversation as resolved.
Show resolved Hide resolved
(err) => {
if (err) { throw err; }
});
}