Skip to content

Commit

Permalink
Refactor image names
Browse files Browse the repository at this point in the history
  • Loading branch information
enyachoke committed Sep 2, 2024
1 parent da31c16 commit 37fb63f
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 27 deletions.
67 changes: 44 additions & 23 deletions maven-parent/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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">
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">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand Down Expand Up @@ -87,7 +87,7 @@
<includeTypes>jar, omod</includeTypes>
</configuration>
</execution>

<execution>
<id>Unpack Ozone Scripts</id>
<phase>generate-resources</phase>
Expand All @@ -107,9 +107,10 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<execution>
<!-- Exclude files from Ozone -->
<!-- We exclude nothing here, but distros should override this with any exclusions they need -->
<!-- We exclude nothing here, but distros should override this with any exclusions they
need -->
<id>Exclude unneeded Ozone files</id>
<phase>process-resources</phase>
<goals>
Expand Down Expand Up @@ -139,7 +140,8 @@
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.build.directory}/${ozone.artifactId}/distro/configs/openmrs/frontend_assembly</directory>
<directory>
${project.build.directory}/${ozone.artifactId}/distro/configs/openmrs/frontend_assembly</directory>
<filtering>false</filtering>
</resource>
</resources>
Expand Down Expand Up @@ -304,11 +306,13 @@
</goals>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpathref="maven.plugin.classpath" />
<mkdir dir="${project.build.directory}/openmrs_modules" />
<if>
<resourcecount when="greater" count="0">
<fileset dir="${project.build.directory}/openmrs_modules" includes="*-omod-*.jar" />
<fileset dir="${project.build.directory}/openmrs_modules"
includes="*-omod-*.jar" />
</resourcecount>
<then>
<move todir="${project.build.directory}/openmrs_modules">
Expand Down Expand Up @@ -351,7 +355,8 @@
<phase>process-resources</phase>
<configuration>
<scripts>
<script>file://${project.build.directory}/openmrs/frontend_assembly/build-openmrs-frontend.groovy</script>
<script>
file://${project.build.directory}/openmrs/frontend_assembly/build-openmrs-frontend.groovy</script>
</scripts>
</configuration>
</execution>
Expand Down Expand Up @@ -393,6 +398,10 @@
<dockerMavenPlugin>0.45.0</dockerMavenPlugin>
<!-- Docker image properties-->
<docker.tag>${project.groupId}-${project.artifactId}-${project.version}</docker.tag>
<!-- Docker push registry-->
<docker.push.registry>docker.io</docker.push.registry>
<!-- Docker push registry username-->
<docker.push.registry.username>mekomsolutions</docker.push.registry.username>
</properties>
<build>
<plugins>
Expand All @@ -408,7 +417,8 @@
</goals>
<configuration>
<excludeTransitive>true</excludeTransitive>
<outputDirectory>${project.build.directory}/bundled-docker-build-tmp/bundled-docker</outputDirectory>
<outputDirectory>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker</outputDirectory>
<includeArtifactIds>bundled-docker</includeArtifactIds>
</configuration>
</execution>
Expand Down Expand Up @@ -454,7 +464,7 @@
${project.build.directory}/bundled-docker-build-tmp/bundled-docker</directory>
<filtering>true</filtering>
<includes>
<include>docker-compose-bundled.yaml</include>
<include>docker-compose-bundled.yml</include>
</includes>
</resource>
</resources>
Expand Down Expand Up @@ -487,9 +497,10 @@
<artifactId>docker-maven-plugin</artifactId>
<version>${dockerMavenPlugin}</version>
<configuration>
<pushRegistry>${docker.push.registry}</pushRegistry>
<images>
<image>
<name>openmrs-backend:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-openmrs-backend</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/openmrs/Dockerfile</dockerFile>
Expand All @@ -498,7 +509,7 @@
</build>
</image>
<image>
<name>openmrs-frontend:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-openmrs-frontend</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/frontend/Dockerfile</dockerFile>
Expand All @@ -507,7 +518,7 @@
</build>
</image>
<image>
<name>proxy:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-proxy</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/proxy/Dockerfile</dockerFile>
Expand All @@ -516,7 +527,7 @@
</build>
</image>
<image>
<name>odoo:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-odoo</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/odoo/Dockerfile</dockerFile>
Expand All @@ -525,7 +536,7 @@
</build>
</image>
<image>
<name>senaite:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-senaite</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/senaite/Dockerfile</dockerFile>
Expand All @@ -534,7 +545,7 @@
</build>
</image>
<image>
<name>erpnext:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-erpnext</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/erpnext/Dockerfile</dockerFile>
Expand All @@ -543,7 +554,7 @@
</build>
</image>
<image>
<name>eip-erpnext-openmrs:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-eip-erpnext-openmrs</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-erpnext-openmrs/Dockerfile</dockerFile>
Expand All @@ -552,7 +563,7 @@
</build>
</image>
<image>
<name>eip-odoo-openmrs:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-eip-odoo-openmrs</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-odoo-openmrs/Dockerfile</dockerFile>
Expand All @@ -561,7 +572,7 @@
</build>
</image>
<image>
<name>eip-openmrs-senaite:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-eip-openmrs-senaite</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/eip-openmrs-senaite/Dockerfile</dockerFile>
Expand All @@ -570,7 +581,7 @@
</build>
</image>
<image>
<name>postgresql:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-postgresql</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/postgresql/Dockerfile</dockerFile>
Expand All @@ -579,7 +590,7 @@
</build>
</image>
<image>
<name>mysql:${docker.tag}</name>
<name>${docker.push.registry.username}/%a-mysql</name>
<build>
<dockerFile>
${project.build.directory}/bundled-docker-build-tmp/bundled-docker/mysql/Dockerfile</dockerFile>
Expand All @@ -588,6 +599,9 @@
</build>
</image>
</images>
<tags>
<tag>%l</tag>
</tags>
<buildx>
<platforms>
<platform>linux/amd64</platform>
Expand All @@ -603,6 +617,13 @@
</goals>
<phase>package</phase>
</execution>
<execution>
<id>Push Bundled Docker images</id>
<goals>
<goal>push</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
Expand All @@ -622,4 +643,4 @@
</dependencies>
</profile>
</profiles>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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())

0 comments on commit 37fb63f

Please sign in to comment.