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

Feature aca maven plugin #2501

Merged
merged 11 commits into from
Nov 6, 2024
Merged

Feature aca maven plugin #2501

merged 11 commits into from
Nov 6, 2024

Conversation

RuoyuWang-MS
Copy link
Member

What does this implement/fix? Explain your changes.

Implement aca maven plugin
Support 3 paths:
deploy image
deploy code
deploy artifact

Have breaking change in the azure-toolkit-containerapp-lib:
Will use generate dockerfile and use ACR to build if dockerfile doesn't exist instead of oryx. The intellij plugin can reuse this logic later.

Does this close any currently open issues?

Any relevant logs, screenshots, error output, etc.?

Any other comments?

Has this been tested?

  • Tested

* init aca maven plugin

* remove useless items

* fix comments
* init aca maven plugin

* remove useless items

* init acr build

* reuse timestamp

* fix comments

* add todo
* init aca maven plugin

* remove useless items

* init acr build

* reuse timestamp

* fix comments

* add todo

* support generate dockerfile

* remove useless comments

* fix comments
* init aca maven plugin

* remove useless items

* init acr build

* reuse timestamp

* fix comments

* add todo

* support generate dockerfile

* remove useless comments

* add unit tests and remove todo

* merge fix comments

* rename folder

* fix

* fix pom

* small fix

* small word fix
@RuoyuWang-MS RuoyuWang-MS changed the title Feature aca maven Feature aca maven plugin Oct 31, 2024
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<configuration>
<goalPrefix>aca</goalPrefix>
Copy link

@allxiao allxiao Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, let's remove this short prefix for now according to: Azure Container Apps branding guidelines

if (MavenConfigUtils.isJarPackaging(project)) {
return true;
} else if (MavenConfigUtils.isPomPackaging(project)) {
log.info(PROJECT_SKIP);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a common practice to extract the log contents to constants, especially when they are not reused. Suggest to use plain text here and for the other 3 log constants.

@@ -8,13 +8,15 @@ user/functionapp.package=generate configuration files and prepare staging direct
user/functionapp.run=run function app locally
user/webapp.deploy_app=deploy to Azure Web App with resource creation or updating
user/webapp.config=generate configuration for web app maven plugin
user/containerapps.deploy_mojo=deploy Container app to Azure from config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When referring to a single Container Apps instance, use lower case singular container app

######################end mojo action operations######################
######################start auto action operations######################
auto/$resource.preload.type=preload {0}s
auto/$resource.refresh_on_subscription_changed.type=refresh {0}s on subscription changed
######################end auto action operations######################
######################start common service operations######################
internal/account.login.type=login with ({0})
internal/containerapps.create_update_app.app=create or update Container app({0}) from config
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

container app for single instance reference

* use mariner image

* ifx

* fix comments

* use java 17 as default

* modify dockerfile comments
}

private void preCheck(ContainerAppsEnvironmentConfig environmentConfig) {
Optional.ofNullable(environmentConfig).map(ContainerAppsEnvironmentConfig::getSubscriptionId).filter(StringUtils::isNotBlank).orElseThrow(() -> new AzureToolkitRuntimeException("'subscriptionId' is required"));
Copy link

@allxiao allxiao Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract the common check to a method, and avoid repeated, too long lines.

<T> String checkNotBlank(T config, Function<T, String> getter, String name) {
    if (config != null) {
        String value = getter.apply(config);
        if (StringUtils.isNotBlank(value)) {
            return value;
        }
    }
    throw new AzureToolkitRuntimeException(String.format("'%s' is required", name));
}

Call with

checkNotBlank(environmentConfig, ContainerAppsEnvironmentConfig::getSubscriptionId, "subscriptionId");

.getOrDraft(config.getResourceGroup(), config.getResourceGroup());

if (resourceGroup.isDraftForCreating() && !resourceGroup.exists()) {
final String region = Optional.ofNullable(config.getRegion()).filter(StringUtils::isNotBlank).orElseThrow(() -> new AzureToolkitRuntimeException("'region' is required"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, to use common check.

* Boolean flag to control whether to wait the deployment status to be ready after deployment
*/
@Parameter(property = "noWait")
private Boolean noWait;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we use the two parameters anywhere else? Shall we remove them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

return null;
}
final String defaultImageName = String.format("%s%s/%s:%s", config.getRegistryConfig().getRegistryName(), ContainerRegistry.ACR_IMAGE_SUFFIX, mojo.getAppName(), timestamp);
final String fullImageName = Optional.ofNullable(containers.get(0).getImage()).orElse(defaultImageName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that we only accept the first container configuration, if so, why not change mojo.getContainers to AppContainerMavenConfig instead of a List?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we will spike if we should support multi container payload later. For the first edition, we can just keep the list for future scalability

return null;
}
final ResourceConfiguration resourceConfiguration = new ResourceConfiguration();
resourceConfiguration.setCpu(containers.get(0).getCpu());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

.map(action -> action.bind("https://aka.ms/azure-container-apps-java"))
.orElse(null);

final Action<String> openPortal = Optional.ofNullable(AzureActionManager.getInstance().getAction(Action.OPEN_URL).withLabel("Open Portal"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before code is to open the portal page of this container app, do we need to change it to open portal instead? Besides, we should read the portal url from AzureEnvironment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the URL. Sorry for the mistake.

@Flanker32
Copy link
Member

@wangmingliang-ms Please help check the logic changes in aca deployments~

.orElse(null);

final Action<String> openPortal = Optional.ofNullable(AzureActionManager.getInstance().getAction(Action.OPEN_URL).withLabel("Open Portal"))
.map(action -> action.bind("https://portal.azure.com"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to change the url?

  1. this action is to open the portal page of this specific resource.
  2. https://portal.azure.com is not the right url of all Azure Environments' portal pages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the URL. Sorry for the mistake.

final Action<String> learnMore = AzureActionManager.getInstance().getAction(Action.OPEN_URL).withLabel("Learn More").bind("https://aka.ms/azuretools-aca-stack");
final Action<String> openPortal = AzureActionManager.getInstance().getAction(Action.OPEN_URL).withLabel("Open Portal").bind(this.getPortalUrl());
final Action<String> learnMore = Optional.ofNullable(AzureActionManager.getInstance().getAction(Action.OPEN_URL).withLabel("Learn More"))
.map(action -> action.bind("https://aka.ms/azure-container-apps-java"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason to change this url?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revert the URL. Sorry for the mistake.

@@ -0,0 +1,5 @@
ARG JAVA_VERSION=17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if user's project is developped upon Java 21?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will use Java 21 and 17 is a default version if no java version detected.
Here we detect the java version and add it into buildImageConfig.sourceBuildEnv (we just reuse this map). code link
And then we put this into ACR build args code link
These build args will override the JAVA_VERSION=17 in the dockerfile.

Copy link
Contributor

@wangmingliang-ms wangmingliang-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -128,7 +128,8 @@ public void testGetContainerAppConfigImage() {
}

@Test
public void testGetContainerAppConfigCode() {
public void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Flanker32
Flanker32 previously approved these changes Nov 6, 2024
Copy link
Member

@Flanker32 Flanker32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@Flanker32 Flanker32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RuoyuWang-MS RuoyuWang-MS merged commit f33a173 into develop Nov 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants