Search in sources :

Example 11 with PrivateRegistryImageSetting

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();
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) Registry(com.microsoft.azure.management.containerregistry.Registry) Job(org.eclipse.core.runtime.jobs.Job) PartInitException(org.eclipse.ui.PartInitException)

Example 12 with PrivateRegistryImageSetting

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));
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) Gson(com.google.gson.Gson) Registry(com.microsoft.azure.management.containerregistry.Registry) Tag(com.microsoft.azuretools.core.mvp.model.container.pojo.Tag)

Example 13 with PrivateRegistryImageSetting

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));
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) Gson(com.google.gson.Gson) Registry(com.microsoft.azure.management.containerregistry.Registry) Catalog(com.microsoft.azuretools.core.mvp.model.container.pojo.Catalog)

Example 14 with PrivateRegistryImageSetting

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());
    });
}
Also used : Path(java.nio.file.Path) PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting) DockerProgressHandler(com.microsoft.azuretools.container.DockerProgressHandler) DockerClient(com.spotify.docker.client.DockerClient) DefaultDockerClient(com.spotify.docker.client.DefaultDockerClient) FileNotFoundException(java.io.FileNotFoundException) Operation(com.microsoft.azuretools.telemetrywrapper.Operation) InvalidFormDataException(com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException) FileNotFoundException(java.io.FileNotFoundException)

Example 15 with PrivateRegistryImageSetting

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());
}
Also used : PrivateRegistryImageSetting(com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)

Aggregations

PrivateRegistryImageSetting (com.microsoft.azuretools.core.mvp.model.webapp.PrivateRegistryImageSetting)21 DefaultDockerClient (com.spotify.docker.client.DefaultDockerClient)6 DockerClient (com.spotify.docker.client.DockerClient)6 Registry (com.microsoft.azure.management.containerregistry.Registry)5 ISecureStore (com.microsoft.azure.toolkit.ide.common.store.ISecureStore)4 IWebApp (com.microsoft.azure.toolkit.lib.appservice.service.IWebApp)4 InvalidFormDataException (com.microsoft.azuretools.azurecommons.exceptions.InvalidFormDataException)4 FileNotFoundException (java.io.FileNotFoundException)4 Path (java.nio.file.Path)4 PricingTier (com.microsoft.azure.toolkit.lib.appservice.model.PricingTier)3 Gson (com.google.gson.Gson)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2 AccessKeyType (com.microsoft.azure.management.containerregistry.AccessKeyType)2 RegistryCredentials (com.microsoft.azure.management.containerregistry.RegistryCredentials)2 DockerProgressHandler (com.microsoft.azure.toolkit.intellij.webapp.docker.utils.DockerProgressHandler)2 IAppServicePlan (com.microsoft.azure.toolkit.lib.appservice.service.IAppServicePlan)2 Region (com.microsoft.azure.toolkit.lib.common.model.Region)2 ResourceGroup (com.microsoft.azure.toolkit.lib.common.model.ResourceGroup)2 Subscription (com.microsoft.azure.toolkit.lib.common.model.Subscription)2 DockerProgressHandler (com.microsoft.azuretools.container.DockerProgressHandler)2