Skip to content

Commit

Permalink
Merge branch 'develop' into update-from-template-merged
Browse files Browse the repository at this point in the history
  • Loading branch information
xdev-gh-bot committed Nov 11, 2024
2 parents 06e8428 + fb3b1cd commit a8a4c58
Show file tree
Hide file tree
Showing 22 changed files with 1,206 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ body:
attributes:
label: "Checklist"
options:
- label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/template-placeholder/releases/latest)"
- label: "I am able to reproduce the bug with the [latest version](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/releases/latest)"
required: true
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues) or [closed](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the bug report will be dismissed otherwise."
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/enhancement.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
attributes:
label: "Checklist"
options:
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues) or [closed](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the feature request will be dismissed otherwise."
required: true
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ body:
attributes:
label: "Checklist"
options:
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/template-placeholder/issues) or [closed](https://github.com/xdev-software/template-placeholder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
- label: "I made sure that there are *no existing issues* - [open](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues) or [closed](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/issues?q=is%3Aissue+is%3Aclosed) - which I could contribute my information to."
required: true
- label: "I have taken the time to fill in all the required details. I understand that the question will be dismissed otherwise."
required: true
Expand Down
9 changes: 1 addition & 8 deletions .github/workflows/check-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,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 @@ -64,13 +64,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

checkstyle:
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# 1.0.1
* Minor improvements in cleanup behavior (backported from upstream)

# 1.0.0
_Initial release_
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,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
26 changes: 20 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/check-build.yml?branch=develop)](https://github.com/xdev-software/template-placeholder/actions/workflows/check-build.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/check-build.yml?branch=develop)](https://github.com/xdev-software/testcontainers-advanced-imagebuilder/actions/workflows/check-build.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 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
* Did some general code cleanup

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,6 @@ 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)

<sub>Disclaimer: This is not an official Testcontainers product and not associated</sub>
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).
9 changes: 5 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<modelVersion>4.0.0</modelVersion>

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

<organization>
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>

<properties>
Expand Down
10 changes: 9 additions & 1 deletion renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"packageRules": [
{
"description": "Ignore project internal dependencies",
"packagePattern": "^software.xdev:template-placeholder",
"packagePattern": "^software.xdev:testcontainers-advanced-imagebuilder",
"datasources": [
"maven"
],
Expand All @@ -19,6 +19,14 @@
"maven"
],
"groupName": "net.sourceforge.pmd"
},
{
"description": "Docker - Java LTS",
"packagePattern": "^eclipse-temurin",
"matchDatasources": [
"docker"
],
"allowedVersions": "/^21\\-alpine$/"
}
]
}
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 @@ -6,12 +6,12 @@

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

<artifactId>template-placeholder-demo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>testcontainers-advanced-imagebuilder-demo</artifactId>
<version>1.0.2-SNAPSHOT</version>
<packaging>jar</packaging>

<organization>
Expand All @@ -32,9 +32,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.16</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()
{
}
}
1 change: 1 addition & 0 deletions testcontainers-advanced-imagebuilder-dummy-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a dummy application that can be started as a container
Loading

0 comments on commit a8a4c58

Please sign in to comment.