in src/main/java/com/microsoft/jenkins/appservice/commands/DockerDeployCommand.java [32:87]
public void execute(IDockerDeployCommandData context) {
final DockerBuildInfo dockerBuildInfo = context.getDockerBuildInfo();
final AuthConfig authConfig = dockerBuildInfo.getAuthConfig();
final WebApp webApp = context.getWebApp();
final String slotName = context.getSlotName();
try {
final String image = imageAndTag(dockerBuildInfo);
context.logStatus(String.format("Updating configuration of Azure app service `%s`, with new docker image %s.",
context.getWebApp().name(), image));
if (StringUtils.isNotBlank(context.getSlotName())) {
context.logStatus(String.format("Targeting deployment slot `%s`.", context.getSlotName()));
}
if (StringUtils.isBlank(context.getSlotName())) {
final WebApp.Update update = webApp.update();
if (AuthConfig.DEFAULT_SERVER_ADDRESS.equalsIgnoreCase(authConfig.getRegistryAddress())) {
update.withPrivateDockerHubImage(image)
.withCredentials(authConfig.getUsername(), authConfig.getPassword());
} else {
update.withPrivateRegistryImage(image, authConfig.getRegistryAddress())
.withCredentials(authConfig.getUsername(), authConfig.getPassword());
}
update.withTags(new HashedMap());
webApp.inner().withKind("app");
update.apply();
webApp.stop();
webApp.start();
} else {
final DeploymentSlot slot = webApp.deploymentSlots().getByName(slotName);
checkNotNull(slot, "Deployment slot not found:" + slotName);
final AzureCredentials.ServicePrincipal sp = AzureCredentials.getServicePrincipal(context.getAzureCredentialsId());
final Azure azure = TokenCache.getInstance(sp).getAzureClient();
final SiteConfigResourceInner siteConfigResourceInner = azure.webApps().inner().getConfigurationSlot(
slot.resourceGroupName(), webApp.name(), slotName);
checkNotNull(siteConfigResourceInner, "Configuration not found for slot:" + slotName);
List<NameValuePair> appSettings = new ArrayList<>();
appSettings.add(new NameValuePair().withName(SETTING_DOCKER_IMAGE).withValue(image));
appSettings.add(new NameValuePair().withName(SETTING_REGISTRY_SERVER).withValue(authConfig.getRegistryAddress()));
appSettings.add(new NameValuePair().withName(SETTING_REGISTRY_USERNAME).withValue(authConfig.getUsername()));
appSettings.add(new NameValuePair().withName(SETTING_REGISTRY_PASSWORD).withValue(authConfig.getPassword()));
siteConfigResourceInner.withLinuxFxVersion(String.format("DOCKER|%s", image));
siteConfigResourceInner.withAppSettings(appSettings);
azure.webApps().inner().updateConfigurationSlot(webApp.resourceGroupName(), webApp.name(), slot.name(), siteConfigResourceInner);
}
context.setDeploymentState(DeploymentState.Success);
context.logStatus("Azure app service updated successfully.");
} catch (Exception e) {
context.logError("Fails in updating Azure app service", e);
context.setDeploymentState(DeploymentState.HasError);
}
}