Skip to content

Commit

Permalink
O3-3426: Update build-distro command to use Maven artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Jul 29, 2024
1 parent 1476d4f commit 837e613
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}

}
Expand Down Expand Up @@ -312,7 +303,13 @@ private String buildDistro(File targetDirectory, Artifact distroArtifact, Distro
moduleInstaller.installModules(distroProperties.getModuleArtifacts(distroHelper, targetDirectory),
modulesDir.getAbsolutePath());

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

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

File owasDir = new File(web, "owa");
owasDir.mkdir();
Expand Down Expand Up @@ -341,6 +338,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 837e613

Please sign in to comment.