From 37fb63fbefdf89ea9598988d797651713a0d396e Mon Sep 17 00:00:00 2001 From: Emmanuel Nyachoke Date: Mon, 2 Sep 2024 14:38:27 +0300 Subject: [PATCH] Refactor image names --- maven-parent/pom.xml | 67 ++++++++++++------- .../generate-bundled-docker-compose.groovy | 61 +++++++++++++++-- 2 files changed, 101 insertions(+), 27 deletions(-) diff --git a/maven-parent/pom.xml b/maven-parent/pom.xml index 8d98d5c..299f0e4 100644 --- a/maven-parent/pom.xml +++ b/maven-parent/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 @@ -87,7 +87,7 @@ jar, omod - + Unpack Ozone Scripts generate-resources @@ -107,9 +107,10 @@ org.apache.maven.plugins maven-resources-plugin - + - + Exclude unneeded Ozone files process-resources @@ -139,7 +140,8 @@ true - ${project.build.directory}/${ozone.artifactId}/distro/configs/openmrs/frontend_assembly + + ${project.build.directory}/${ozone.artifactId}/distro/configs/openmrs/frontend_assembly false @@ -304,11 +306,13 @@ - + - + @@ -351,7 +355,8 @@ process-resources - + @@ -393,6 +398,10 @@ 0.45.0 ${project.groupId}-${project.artifactId}-${project.version} + + docker.io + + mekomsolutions @@ -408,7 +417,8 @@ true - ${project.build.directory}/bundled-docker-build-tmp/bundled-docker + + ${project.build.directory}/bundled-docker-build-tmp/bundled-docker bundled-docker @@ -454,7 +464,7 @@ ${project.build.directory}/bundled-docker-build-tmp/bundled-docker true - docker-compose-bundled.yaml + docker-compose-bundled.yml @@ -487,9 +497,10 @@ docker-maven-plugin ${dockerMavenPlugin} + ${docker.push.registry} - openmrs-backend:${docker.tag} + ${docker.push.registry.username}/%a-openmrs-backend ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/openmrs/Dockerfile @@ -498,7 +509,7 @@ - openmrs-frontend:${docker.tag} + ${docker.push.registry.username}/%a-openmrs-frontend ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/frontend/Dockerfile @@ -507,7 +518,7 @@ - proxy:${docker.tag} + ${docker.push.registry.username}/%a-proxy ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/proxy/Dockerfile @@ -516,7 +527,7 @@ - odoo:${docker.tag} + ${docker.push.registry.username}/%a-odoo ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/odoo/Dockerfile @@ -525,7 +536,7 @@ - senaite:${docker.tag} + ${docker.push.registry.username}/%a-senaite ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/senaite/Dockerfile @@ -534,7 +545,7 @@ - erpnext:${docker.tag} + ${docker.push.registry.username}/%a-erpnext ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/erpnext/Dockerfile @@ -543,7 +554,7 @@ - eip-erpnext-openmrs:${docker.tag} + ${docker.push.registry.username}/%a-eip-erpnext-openmrs ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-erpnext-openmrs/Dockerfile @@ -552,7 +563,7 @@ - eip-odoo-openmrs:${docker.tag} + ${docker.push.registry.username}/%a-eip-odoo-openmrs ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-odoo-openmrs/Dockerfile @@ -561,7 +572,7 @@ - eip-openmrs-senaite:${docker.tag} + ${docker.push.registry.username}/%a-eip-openmrs-senaite ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-openmrs-senaite/Dockerfile @@ -570,7 +581,7 @@ - postgresql:${docker.tag} + ${docker.push.registry.username}/%a-postgresql ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/postgresql/Dockerfile @@ -579,7 +590,7 @@ - mysql:${docker.tag} + ${docker.push.registry.username}/%a-mysql ${project.build.directory}/bundled-docker-build-tmp/bundled-docker/mysql/Dockerfile @@ -588,6 +599,9 @@ + + %l + linux/amd64 @@ -603,6 +617,13 @@ package + + Push Bundled Docker images + + push + + deploy + @@ -622,4 +643,4 @@ - + \ No newline at end of file diff --git a/scripts/openmrs/bundled-docker/generate-bundled-docker-compose.groovy b/scripts/openmrs/bundled-docker/generate-bundled-docker-compose.groovy index 4e198fe..2ed715a 100644 --- a/scripts/openmrs/bundled-docker/generate-bundled-docker-compose.groovy +++ b/scripts/openmrs/bundled-docker/generate-bundled-docker-compose.groovy @@ -4,14 +4,67 @@ import java.text.SimpleDateFormat import groovy.text.* import groovy.json.JsonBuilder -myver = "${project.groupId}-${project.artifactId}-${project.version}" +def sanitizeName(name) { + StringBuilder ret = new StringBuilder(); + int underscores = 0; + boolean lastWasADot = false; + for (char c : name.toCharArray()) { + if (c == '_') { + underscores++; + // Only _ in a row are allowed + if (underscores <= 2) { + ret.append(c); + } + continue; + } -def dockerComposeTemplate = Paths.get("${project.build.directory}", "/bundled-docker-build-tmp", "bundled-docker", "docker-compose-bundled.yaml.template").toFile() -def binding = ['dockertag' : myver ] + if (c == '.') { + // Only one dot in a row is allowed + if (!lastWasADot) { + ret.append(c); + } + lastWasADot = true; + continue; + } + + underscores = 0; + lastWasADot = false; + if (Character.isLetter(c) || Character.isDigit(c) || c == '-') { + ret.append(c); + } + } + + // All characters must be lowercase + return ret.toString().toLowerCase(); +} + +String getPropertyValue(String name) { + def value = session.userProperties[name] + if (value != null) return value //property was defined from command line e.g.: -DpropertyName=value + return project.properties[name] +} +groupId = project.groupId +while (groupId.endsWith(".")) { + groupId = groupId.substring(0, groupId.length() - 1); +} +int idx = groupId.lastIndexOf("."); +sanitizedGroupId = sanitizeName(groupId.substring(idx != -1 ? idx + 1 : 0)) +sanitizedArtifactId = sanitizeName(project.artifactId) + + +myver = project.version +mydockerUserName = getPropertyValue('docker.push.registry.username') + +if (project.version.endsWith("-SNAPSHOT")) { + myver = "latest" +} + +def dockerComposeTemplate = Paths.get("${project.build.directory}", "/bundled-docker-build-tmp", "bundled-docker", "docker-compose-bundled.yml.template").toFile() +def binding = ['dockertag' : myver, 'sanitizedGroupId' : sanitizedGroupId, 'sanitizedArtifactId' : sanitizedArtifactId, 'dockerUserName' : mydockerUserName] def engine = new SimpleTemplateEngine() def template = engine.createTemplate(dockerComposeTemplate) def writable = template.make(binding) -def dockerComposePath = Paths.get("${project.build.directory}", "/bundled-docker-build-tmp", "bundled-docker", "docker-compose-bundled.yaml").toAbsolutePath().toString() +def dockerComposePath = Paths.get("${project.build.directory}", "/bundled-docker-build-tmp", "bundled-docker", "docker-compose-bundled.yml").toAbsolutePath().toString() def myFile = new File(dockerComposePath) myFile.write(writable.toString()) \ No newline at end of file