Skip to content

Commit

Permalink
Merge pull request #2 from xdev-software/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
AB-xdev authored Apr 23, 2024
2 parents 9cdaa5e + 0643e52 commit e1194b9
Show file tree
Hide file tree
Showing 17 changed files with 1,180 additions and 30 deletions.
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
# Auto detect text files and perform LF normalization
* text=auto

# Force sh files to have LF
*.sh text eol=lf

# Force MVN Wrapper Linux files LF
mvnw text eol=lf
.mvn/wrapper/maven-wrapper.properties text eol=lf
9 changes: 1 addition & 8 deletions .github/workflows/checkBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
cache: 'maven'

- name: Build with Maven
run: ./mvnw -B clean package
run: ./mvnw -B clean package -P run-integration-tests

- name: Check for uncommited changes
run: |
Expand All @@ -63,13 +63,6 @@ jobs:
exit 1
fi
- name: Upload demo files
uses: actions/upload-artifact@v4
with:
name: demo-files-java-${{ matrix.java }}
path: ${{ env.DEMO_MAVEN_MODULE }}/target/${{ env.DEMO_MAVEN_MODULE }}.jar
if-no-files-found: error

code-style:
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' || !startsWith(github.head_ref, 'renovate/') }}
Expand Down
2 changes: 1 addition & 1 deletion .run/Run Demo.run.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Demo" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="software.xdev.Application" />
<module name="template-placeholder-demo" />
<module name="testcontainers-advanced-imagebuilder-demo" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<extension name="coverage">
<pattern>
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ You should have the following things installed:
* Ensure that the JDK/Java-Version is correct


## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/release.yml?branch=master)](https://github.com/xdev-software/template-placeholder/actions/workflows/release.yml)
## Releasing [![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/testcontainers-advanced-imagebuilder/release.yml?branch=master)](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/release.yml)

Before releasing:
* Consider doing a [test-deployment](https://github.com/xdev-software/template-placeholder/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Consider doing a [test-deployment](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/test-deploy.yml?query=branch%3Adevelop) before actually releasing.
* Check the [changelog](CHANGELOG.md)

If the ``develop`` is ready for release, create a pull request to the ``master``-Branch and merge the changes
Expand Down
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/template-placeholder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/template-placeholder)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/template-placeholder/checkBuild.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_template-placeholder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_template-placeholder)
[![Latest version](https://img.shields.io/maven-central/v/software.xdev/testcontainers-advanced-imagebuilder?logo=apache%20maven)](https://mvnrepository.com/artifact/software.xdev/testcontainers-advanced-imagebuilder)
[![Build](https://img.shields.io/github/actions/workflow/status/xdev-software/testcontainers-advanced-imagebuilder/checkBuild.yml?branch=develop)](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/checkBuild.yml?query=branch%3Adevelop)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=xdev-software_testcontainers-advanced-imagebuilder&metric=alert_status)](https://sonarcloud.io/dashboard?id=xdev-software_testcontainers-advanced-imagebuilder)

# template-placeholder
# Advanced Image-Builder for Testcontainers Java

A re-implementation of [Testcontainers Image-Builder](https://java.testcontainers.org/features/creating_images/) with the following improvements:
* Allows passing a custom logger to the image build - [testcontainers-java#3093](https://github.com/testcontainers/testcontainers-java/issues/3093)
* Allows using ``ARG``s for ``FROM`` - [testcontainers-java#3238](https://github.com/testcontainers/testcontainers-java/issues/3238)
* Brings a custom [build-context](https://docs.docker.com/build/building/context/) processor
* Works more efficient and reliable than the default implementation (however likely still not perfect)
* uses ``.gitignore`` if available
* Allows to adding custom ignores
* This way the build-context can be fine tuned in a way that the build cache works very efficiently (e.g. only re-built when actual code that matters changes)
* Makes logger non generic and therefore controllable
* Cleaned up some code

A common use case - that can also be seen [inside the demo](./testcontainers-advanced-imagebuilder-demo/src/main/java/software/xdev/Application.java) - is for creating an image - used in e.g. Integration tests - for an application that is also inside the same repo.

## Installation
[Installation guide for the latest release](https://github.com/xdev-software/template-placeholder/releases/latest#Installation)
[Installation guide for the latest release](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/releases/latest#Installation)

## Support
If you need support as soon as possible and you can't wait for any pull request, feel free to use [our support](https://xdev.software/en/services/support).
Expand All @@ -15,4 +27,4 @@ If you need support as soon as possible and you can't wait for any pull request,
See the [contributing guide](./CONTRIBUTING.md) for detailed instructions on how to get started with our project.

## Dependencies and Licenses
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/template-placeholder/dependencies)
View the [license of the current project](LICENSE) or the [summary including all dependencies](https://xdev-software.github.io/testcontainers-advanced-imagebuilder/dependencies)
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

## Reporting a Vulnerability

Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/template-placeholder/security/advisories/new).
Please report a security vulnerability [on GitHub Security Advisories](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/security/advisories/new).
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>template-placeholder-root</artifactId>
<artifactId>testcontainers-advanced-imagebuilder-root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

Expand All @@ -15,8 +15,9 @@
</organization>

<modules>
<module>template-placeholder</module>
<module>template-placeholder-demo</module>
<module>testcontainers-advanced-imagebuilder</module>
<module>testcontainers-advanced-imagebuilder-dummy-app</module>
<module>testcontainers-advanced-imagebuilder-demo</module>
</modules>

<licenses>
Expand Down
54 changes: 54 additions & 0 deletions testcontainers-advanced-imagebuilder-demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Stage 1: Build the dummy app
ARG JAVA_VERSION=21
FROM eclipse-temurin:$JAVA_VERSION-jdk-alpine AS build-env

RUN apk add --no-cache git bash

# Create non root user
ARG userName=limitedbuild
ARG groupName=limitedbuild
ARG userId=1000

RUN addgroup --system ${groupName} \
&& adduser --uid ${userId} --system --disabled-password --shell /bin/bash ${userName} \
&& adduser ${userName} ${groupName}

# Create build dir
RUN mkdir /build \
&& chown ${userName}:${groupName} /build
WORKDIR /build

USER ${userName}

# Copying context is prepared by Testcontainers
COPY --chown=${userName}:${groupName} . ./

# RUN chmod +x ./mvnw
ARG mvncmd='clean package -pl "testcontainers-advanced-imagebuilder-dummy-app" -am -T2C -Dmaven.test.skip'

RUN echo "Executing '$mvncmd'"
RUN chmod +x ./mvnw \
&& ./mvnw -B $mvncmd

# Stage 2: Build the executable image
FROM eclipse-temurin:21-jre-alpine

ARG user=dummy-app
ARG group=dummy-app
ARG uid=1000
ARG gid=1000
ARG APP_DIR=/opt/dummy-app

# Create user + group + home
RUN mkdir -p $APP_DIR \
&& chown ${uid}:${gid} $APP_DIR \
&& addgroup -g ${gid} ${group} \
&& adduser -h "$APP_DIR" -u ${uid} -G ${group} -s /bin/bash -D ${user}

EXPOSE 8080

USER ${user}

COPY --from=build-env --chown=${user}:${group} build/testcontainers-advanced-imagebuilder-dummy-app/target/dummy-app.jar ${APP_DIR}/dummy-app.jar

CMD java $JAVA_OPTS -jar /opt/dummy-app/dummy-app.jar
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>template-placeholder-demo</artifactId>
<artifactId>testcontainers-advanced-imagebuilder-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

Expand All @@ -27,9 +27,15 @@
<dependencies>
<dependency>
<groupId>software.xdev</groupId>
<artifactId>template-placeholder</artifactId>
<artifactId>testcontainers-advanced-imagebuilder</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.13</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package software.xdev;

import java.nio.file.Paths;

import org.slf4j.LoggerFactory;

import software.xdev.testcontainers.imagebuilder.AdvancedImageFromDockerFile;


public final class Application
{
@SuppressWarnings("java:S106")
public static void main(final String[] args)
{
final AdvancedImageFromDockerFile builder = new AdvancedImageFromDockerFile("dynamically-built")
.withLoggerForBuild(LoggerFactory.getLogger("container.build"))
.withAdditionalIgnoreLines(
// Ignore files that aren't related to the built code
".git/**",
".config/**",
".github/**",
".idea/**",
".run/**",
".md",
".cmd",
"/renovate.json5",
// We need to keep the pom.xml as maven can't resolve the modules otherwise
"testcontainers-advanced-imagebuilder/src/**",
"testcontainers-advanced-imagebuilder/test/**",
"testcontainers-advanced-imagebuilder-demo/src/**"
)
.withDockerFilePath(Paths.get("../testcontainers-advanced-imagebuilder-demo/Dockerfile"))
.withBaseDir(Paths.get("../"));

final String imageName = builder.get();

System.out.println("Successfully build " + imageName);
}

private Application()
{
}
}
103 changes: 103 additions & 0 deletions testcontainers-advanced-imagebuilder-dummy-app/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>software.xdev</groupId>
<artifactId>testcontainers-advanced-imagebuilder-dummy-app</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
<name>XDEV Software</name>
<url>https://xdev.software</url>
</organization>

<properties>
<javaVersion>17</javaVersion>
<maven.compiler.release>${javaVersion}</maven.compiler.release>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<mainClass>software.xdev.Application</mainClass>
</properties>

<build>
<finalName>dummy-app</finalName>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>${maven.compiler.release}</release>
<compilerArgs>
<arg>-proc:none</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainClass}</mainClass>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>checkstyle</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.3.1</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.15.0</version>
</dependency>
</dependencies>
<configuration>
<configLocation>../.config/checkstyle/checkstyle.xml</configLocation>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package software.xdev;

public final class Application
{
@SuppressWarnings("java:S106")
public static void main(final String[] args)
{
System.out.println("I'm a dummy app. I could also be something more complex like webapp if I want to ;)");
}

private Application()
{
}
}
Loading

0 comments on commit e1194b9

Please sign in to comment.