Skip to content

Commit

Permalink
LPS-184062 respect the workspace extension docker pull policy and reg…
Browse files Browse the repository at this point in the history
…istry
  • Loading branch information
gamerson authored and brianchandotcom committed Aug 22, 2023
1 parent 47cdfb3 commit 18d3370
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.liferay.gradle.plugins.workspace.configurator;

import com.bmuschko.gradle.docker.DockerRegistryCredentials;
import com.bmuschko.gradle.docker.DockerRemoteApiPlugin;
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage;
import com.bmuschko.gradle.docker.tasks.image.DockerRemoveImage;
Expand Down Expand Up @@ -241,9 +242,12 @@ else if (clientExtension.type.equals("themeCSS")) {
_nodeBuildConfigurer.apply(
project, assembleClientExtensionTaskProvider);

WorkspaceExtension workspaceExtension = GradleUtil.getExtension(
(ExtensionAware)project.getGradle(), WorkspaceExtension.class);

_addDockerTasks(
project, assembleClientExtensionTaskProvider,
createClientExtensionConfigTaskProvider);
createClientExtensionConfigTaskProvider, workspaceExtension);
}

@Override
Expand Down Expand Up @@ -298,7 +302,8 @@ public FileVisitResult preVisitDirectory(
private void _addDockerTasks(
Project project, TaskProvider<Copy> assembleClientExtensionTaskProvider,
TaskProvider<CreateClientExtensionConfigTask>
createClientExtensionConfigTaskProvider) {
createClientExtensionConfigTaskProvider,
WorkspaceExtension workspaceExtension) {

DockerBuildImage dockerBuildImage = GradleUtil.addTask(
project, RootProjectConfigurator.BUILD_DOCKER_IMAGE_TASK_NAME,
Expand All @@ -317,6 +322,36 @@ private void _addDockerTasks(
assembleClientExtensionTaskProvider.configure(
copy -> inputDirectoryProperty.set(copy.getDestinationDir()));

Property<Boolean> pullProperty = dockerBuildImage.getPull();

pullProperty.set(workspaceExtension.getDockerPullPolicy());

if (Objects.nonNull(
workspaceExtension.getDockerLocalRegistryAddress())) {

DockerRegistryCredentials dockerRegistryCredentials =
dockerBuildImage.getRegistryCredentials();

String dockerUserName = workspaceExtension.getDockerUserName();

if (Objects.nonNull(dockerUserName)) {
Property<String> userNameProperty =
dockerRegistryCredentials.getUsername();

userNameProperty.set(dockerUserName);
}

String dockerUserAccessToken =
workspaceExtension.getDockerUserAccessToken();

if (Objects.nonNull(dockerUserAccessToken)) {
Property<String> passwordProperty =
dockerRegistryCredentials.getPassword();

passwordProperty.set(dockerUserAccessToken);
}
}

DockerRemoveImage dockerRemoveImage = GradleUtil.addTask(
project, RootProjectConfigurator.CLEAN_DOCKER_IMAGE_TASK_NAME,
DockerRemoveImage.class);
Expand Down

0 comments on commit 18d3370

Please sign in to comment.