Skip to content

Commit 870872c

Browse files
committed
O3-3426: Update build-distro command to use Maven artifacts
1 parent 1476d4f commit 870872c

File tree

2 files changed

+60
-16
lines changed

2 files changed

+60
-16
lines changed

maven-plugin/src/main/java/org/openmrs/maven/plugins/BuildDistro.java

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.nio.charset.StandardCharsets;
3535
import java.util.ArrayList;
3636
import java.util.List;
37+
import java.util.Objects;
3738

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

124+
@Parameter(property = "appShellVersion")
125+
private String appShellVersion;
126+
123127
@Override
124128
public void executeTask() throws MojoExecutionException, MojoFailureException {
125129
File buildDirectory = getBuildDirectory();
@@ -176,22 +180,9 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
176180
break;
177181
case O3_DISTRIBUTION:
178182
wizard.promptForO3RefAppVersionIfMissing(server, versionsHelper);
179-
Artifact artifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip");
180-
try {
181-
String gitHubUrl = "https://github.com/openmrs/openmrs-distro-referenceapplication";
182-
CloneCommand cloneCommand = Git.cloneRepository().setURI(gitHubUrl)
183-
.setDirectory(new File(dir));
184-
if (!server.getVersion().equals(versionsHelper.getLatestSnapshotVersion(artifact))) {
185-
cloneCommand.setBranch(server.getVersion());
186-
}
187-
wizard.showMessage("Cloning from " + gitHubUrl);
188-
cloneCommand.call();
189-
} catch (GitAPIException e) {
190-
throw new RuntimeException(e);
191-
}
192-
wizard.showMessage("The '"+ artifact.getArtifactId() +" " + artifact.getVersion() +
193-
"' distribution created! To start up the server run 'docker-compose up' from" + buildDirectory.getAbsolutePath());
194-
return;
183+
server.setServerDirectory(buildDirectory);
184+
distroArtifact = new Artifact(server.getDistroArtifactId(), server.getVersion(), server.getDistroGroupId(), "zip");
185+
distroProperties = new DistroProperties(distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion));
195186
}
196187

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

306+
File frontendDir = new File(web, "frontend");
307+
frontendDir.mkdir();
308+
309+
File configDir = new File(web, SDKConstants.OPENMRS_SERVER_CONFIGURATION);
310+
configDir.mkdir();
311+
setConfigFolder(configDir, distroProperties, distroArtifact);
312+
315313
spaInstaller.installFromDistroProperties(web, distroProperties, ignorePeerDependencies, overrideReuseNodeCache);
316314

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

343+
private void setConfigFolder(File configDir, DistroProperties distroProperties, Artifact distroArtifact) throws MojoExecutionException {
344+
if (distroProperties.getConfigArtifacts().isEmpty()) {
345+
return;
346+
}
347+
348+
349+
downloadConfigs(distroProperties, configDir);
350+
351+
File refappConfigFile = new File(configDir, distroArtifact.getArtifactId() + "-" + distroArtifact.getVersion() + ".zip");
352+
353+
// Handle O2 configuration
354+
if (!refappConfigFile.exists() && Artifact.GROUP_DISTRO.equals(distroArtifact.getGroupId()) && "referenceapplication-distro".equals(distroArtifact.getArtifactId())) {
355+
refappConfigFile = new File(configDir, "referenceapplication-distro.owa");
356+
}
357+
358+
if (!refappConfigFile.exists()) {
359+
wizard.showError("No Configuration file found at " + refappConfigFile.getAbsolutePath());
360+
return;
361+
}
362+
363+
try {
364+
ZipFile zipFile = new ZipFile(refappConfigFile);
365+
zipFile.extractAll(configDir.getPath());
366+
for (File file : Objects.requireNonNull(configDir.listFiles())) {
367+
if (file.getName().equals("openmrs_config")) {
368+
FileUtils.copyDirectory(file, configDir);
369+
}
370+
FileUtils.deleteQuietly(file);
371+
}
372+
FileUtils.deleteQuietly(refappConfigFile);
373+
} catch (ZipException | IOException e) {
374+
throw new RuntimeException(e);
375+
}
376+
}
377+
378+
private void downloadConfigs(DistroProperties distroProperties, File configDir) throws MojoExecutionException {
379+
List<Artifact> configs = distroProperties.getConfigArtifacts();
380+
wizard.showMessage("Downloading Configs...\n");
381+
if (!configs.isEmpty()) {
382+
moduleInstaller.installModules(configs, configDir.getAbsolutePath());
383+
}
384+
}
385+
344386
private void downloadOWAs(File targetDirectory, DistroProperties distroProperties, File owasDir)
345387
throws MojoExecutionException {
346388
List<Artifact> owas = distroProperties.getOwaArtifacts(distroHelper, targetDirectory);

maven-plugin/src/main/resources/build-distro/web/Dockerfile-tomcat8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ FROM tomcat:8-jre8
55
COPY openmrs.war /usr/local/tomcat/webapps/openmrs.war
66
COPY modules /usr/local/tomcat/.OpenMRS/modules
77
COPY owa /usr/local/tomcat/.OpenMRS/owa
8+
COPY frontend /usr/local/tomcat/.OpenMRS/frontend
9+
COPY configuration /usr/local/tomcat/.OpenMRS/configuration
810

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

0 commit comments

Comments
 (0)