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

O3-3426: Update build-distro command to use Maven artifacts #277

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -34,6 +34,7 @@
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
* Create docker configuration for distributions.
@@ -120,6 +121,9 @@ public class BuildDistro extends AbstractTask {
@Parameter(defaultValue = "false", property = "reset")
private boolean reset;

@Parameter(property = "appShellVersion")
private String appShellVersion;

@Override
public void executeTask() throws MojoExecutionException, MojoFailureException {
File buildDirectory = getBuildDirectory();
@@ -176,22 +180,9 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
break;
case O3_DISTRIBUTION:
wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper);
Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip");
try {
String gitHubUrl = "https://github.com/openmrs/openmrs-distro-referenceapplication";
CloneCommand cloneCommand = Git.cloneRepository().setURI(gitHubUrl)
.setDirectory(new File(dir));
if (!server.getVersion().equals(versionsHelper.getLatestSnapshotVersion(artifact))) {
cloneCommand.setBranch(server.getVersion());
}
wizard.showMessage("Cloning from " + gitHubUrl);
cloneCommand.call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
wizard.showMessage("The '"+ artifact.getArtifactId() +" " + artifact.getVersion() +
"' distribution created! To start up the server run 'docker-compose up' from" + buildDirectory.getAbsolutePath());
return;
server.setServerDirectory(buildDirectory);
distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip");
distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion));
}

}
@@ -312,8 +303,16 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory),
modulesDir.getAbsolutePath());

File frontendDir = new File(web, "frontend");
frontendDir.mkdir();

File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION);
configDir.mkdir();
setConfigFolder(configDir, distroProperties, distroArtifact);

spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache);


File owasDir = new File(web, "owa");
owasDir.mkdir();
downloadOWAs(targetDirectory, distroProperties, owasDir);
@@ -341,6 +340,49 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
return distroName;
}

private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException {
if (distroProperties.getConfigArtifacts().isEmpty()) {
return;
}


downloadConfigs(distroProperties, configDir);

File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip");

// Handle O2 configuration
if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) {
refappConfigFile = new File(configDir, "referenceapplication-distro.owa");
}

if (!refappConfigFile.exists()) {
wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath());
return;
}

try {
ZipFile zipFile = new ZipFile(refappConfigFile);
zipFile.extractAll(configDir.getPath());
for (File file : Objects.requireNonNull(configDir.listFiles())) {
if (file.getName().equals("openmrs_config")) {
FileUtils.copyDirectory(file, configDir);
}
FileUtils.deleteQuietly(file);
}
FileUtils.deleteQuietly(refappConfigFile);
} catch (ZipException | IOException e) {
throw new RuntimeException(e);
}
}

private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException {
List<Artifact> configs = distroProperties.getConfigArtifacts();
wizard.showMessage("Downloading Configs...\n");
if (!configs.isEmpty()) {
moduleInstaller.installModules(configs, configDir.getAbsolutePath());
}
}

private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir)
throws MojoExecutionException {
List<Artifact> owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory);
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ FROM tomcat:8-jre8
COPY openmrs.war /usr/local/tomcat/webapps/openmrs.war
COPY modules /usr/local/tomcat/.OpenMRS/modules
COPY owa /usr/local/tomcat/.OpenMRS/owa
COPY frontend /usr/local/tomcat/.OpenMRS/frontend
COPY configuration /usr/local/tomcat/.OpenMRS/configuration

COPY setenv.sh /usr/local/tomcat/bin/setenv.sh

Loading