use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class ContainerRegistryExplorerEditor method pullImage.
private void pullImage() {
Job job = new Job(PULL_IMAGE) {
@Override
protected IStatus run(IProgressMonitor monitor) {
monitor.beginTask(PULL_IMAGE, IProgressMonitor.UNKNOWN);
String deploymentName = UUID.randomUUID().toString();
try {
if (Utils.isEmptyString(currentRepo) || Utils.isEmptyString(currentTag)) {
throw new Exception(REPO_TAG_NOT_AVAILABLE);
}
final String image = String.format("%s:%s", currentRepo, currentTag);
String jobDescription = String.format("Pulling: %s", image);
AzureDeploymentProgressNotification.createAzureDeploymentProgressNotification(deploymentName, jobDescription);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, "", 5, "Getting Registry...");
final Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(subscriptionId, registryId);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, "", 5, "Getting Credential...");
final PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
final String fullImageTagName = String.format("%s/%s", registry.loginServerUrl(), image);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, "", 10, "Pulling image...");
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.pullImage(docker, registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), fullImageTagName);
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, 100, "Finish.");
sendTelemetry(true, subscriptionId, null);
} catch (Exception ex) {
monitor.done();
AzureDeploymentProgressNotification.notifyProgress(this, deploymentName, null, -1, ex.getMessage());
sendTelemetry(false, subscriptionId, ex.getMessage());
return Status.CANCEL_STATUS;
}
monitor.done();
return Status.OK_STATUS;
}
};
job.schedule();
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class ContainerRegistryPropertyViewPresenter method onListTags.
/**
* Called when listing image tags for the given repository.
*/
public void onListTags(String sid, String id, String repo, boolean isNextPage) {
if (isSubscriptionIdAndResourceIdInValid(sid, id)) {
return;
}
resetTagStack();
Observable.fromCallable(() -> {
Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(sid, id);
PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
Map<String, String> query = buildQueryMap(isNextPage, tagStack, nextTag);
Map<String, String> responseMap = ContainerExplorerMvpModel.getInstance().listTags(registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), repo, query);
updatePaginationInfo(isNextPage, Type.TAG, responseMap.get(HEADER_LINK));
Gson gson = new Gson();
Tag tag = gson.fromJson(responseMap.get(BODY), Tag.class);
return tag.getTags();
}).subscribeOn(getSchedulerProvider().io()).subscribe(tags -> DefaultLoader.getIdeHelper().invokeLater(() -> {
if (isViewDetached()) {
return;
}
getMvpView().listTag(tags);
}), e -> errorHandler(CANNOT_GET_TAGS, (Exception) e));
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class ContainerRegistryPropertyViewPresenter method onListRepositories.
/**
* Called when listing repositories of ACR.
*/
public void onListRepositories(String sid, String id, boolean isNextPage) {
if (isSubscriptionIdAndResourceIdInValid(sid, id)) {
return;
}
resetTagStack();
Observable.fromCallable(() -> {
Registry registry = ContainerRegistryMvpModel.getInstance().getContainerRegistry(sid, id);
PrivateRegistryImageSetting setting = ContainerRegistryMvpModel.getInstance().createImageSettingWithRegistry(registry);
Map<String, String> query = buildQueryMap(isNextPage, repoStack, nextRepo);
Map<String, String> responseMap = ContainerExplorerMvpModel.getInstance().listRepositories(registry.loginServerUrl(), setting.getUsername(), setting.getPassword(), query);
updatePaginationInfo(isNextPage, Type.REPO, responseMap.get(HEADER_LINK));
Gson gson = new Gson();
Catalog catalog = gson.fromJson(responseMap.get(BODY), Catalog.class);
return catalog.getRepositories();
}).subscribeOn(getSchedulerProvider().io()).subscribe(repos -> DefaultLoader.getIdeHelper().invokeLater(() -> {
if (isViewDetached()) {
return;
}
getMvpView().listRepo(repos);
}), e -> errorHandler(CANNOT_GET_REPOS, (Exception) e));
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class PushImageDialog method execute.
private void execute() {
Operation operation = TelemetryManager.createOperation(ACR, ACR_PUSHIMAGE);
Observable.fromCallable(() -> {
ConsoleLogger.info("Starting job ... ");
operation.start();
if (basePath == null) {
ConsoleLogger.error("Project base path is null.");
throw new FileNotFoundException("Project base path is null.");
}
// locate artifact to specified location
String targetFilePath = model.getTargetPath();
ConsoleLogger.info(String.format("Locating artifact ... [%s]", targetFilePath));
// validate dockerfile
Path targetDockerfile = Paths.get(model.getDockerFilePath());
ConsoleLogger.info(String.format("Validating dockerfile ... [%s]", targetDockerfile));
if (!targetDockerfile.toFile().exists()) {
throw new FileNotFoundException("Dockerfile not found.");
}
// replace placeholder if exists
String content = new String(Files.readAllBytes(targetDockerfile));
content = content.replaceAll(Constant.DOCKERFILE_ARTIFACT_PLACEHOLDER, Paths.get(basePath).toUri().relativize(Paths.get(targetFilePath).toUri()).getPath());
Files.write(targetDockerfile, content.getBytes());
// build image
PrivateRegistryImageSetting acrInfo = model.getPrivateRegistryImageSetting();
ConsoleLogger.info(String.format("Building image ... [%s]", acrInfo.getImageTagWithServerUrl()));
DockerClient docker = DefaultDockerClient.fromEnv().build();
DockerUtil.ping(docker);
DockerUtil.buildImage(docker, acrInfo.getImageTagWithServerUrl(), targetDockerfile.getParent(), targetDockerfile.getFileName().toString(), new DockerProgressHandler());
// push to ACR
ConsoleLogger.info(String.format("Pushing to ACR ... [%s] ", acrInfo.getServerUrl()));
DockerUtil.pushImage(docker, acrInfo.getServerUrl(), acrInfo.getUsername(), acrInfo.getPassword(), acrInfo.getImageTagWithServerUrl(), new DockerProgressHandler());
return null;
}).subscribeOn(SchedulerProviderFactory.getInstance().getSchedulerProvider().io()).subscribe(props -> {
ConsoleLogger.info("pushed.");
sendTelemetry(true, null);
operation.complete();
}, err -> {
err.printStackTrace();
ConsoleLogger.error(err.getMessage());
EventUtil.logError(operation, ErrorType.systemError, new Exception(err), null, null);
operation.complete();
sendTelemetry(false, err.getMessage());
});
}
use of com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting in project azure-tools-for-java by Microsoft.
the class PushImageDialog method apply.
private void apply() {
model.setDockerFilePath(containerSettingComposite.getDockerfilePath());
// set ACR info
model.setPrivateRegistryImageSetting(new PrivateRegistryImageSetting(containerSettingComposite.getServerUrl().replaceFirst("^https?://", "").replaceFirst("/$", ""), containerSettingComposite.getUserName(), containerSettingComposite.getPassword(), containerSettingComposite.getImageTag(), ""));
// set target
model.setTargetPath(targetPath);
model.setTargetName(Paths.get(targetPath).getFileName().toString());
}
Aggregations