Skip to content

Commit

Permalink
Provide Docker Image for multiple Architectures (#1324)
Browse files Browse the repository at this point in the history
- Update readme files to mention multi-arch images more prominently
- Implement new check in the LowkeyVaultContainer to recommend multi-arch images when it could be beneficial
- Add new tests

Updates #1270
{minor}

Signed-off-by: Esta Nagy <nagyesta@gmail.com>
  • Loading branch information
nagyesta authored Jan 21, 2025
1 parent 72f6e8a commit 6a770d2
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 15 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
[![Java version](https://img.shields.io/badge/Java%20version-17%20app|11%20libs-yellow?logo=java)](https://img.shields.io/badge/Java%20version-17%20app|11%20libs-yellow?logo=java)
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.nagyesta.lowkey-vault/lowkey-vault-app?logo=apache-maven)](https://search.maven.org/search?q=com.github.nagyesta.lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=semver&arch=amd64&logo=docker&label=amd64)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=date&arch=arm64&logo=docker&label=multi-arch)](https://hub.docker.com/r/nagyesta/lowkey-vault)

[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5577/badge)](https://bestpractices.coreinfrastructure.org/projects/5577)
[![code-climate-maintainability](https://img.shields.io/codeclimate/maintainability/nagyesta/lowkey-vault?logo=code%20climate)](https://img.shields.io/codeclimate/maintainability/nagyesta/lowkey-vault?logo=code%20climate)
[![code-climate-tech-debt](https://img.shields.io/codeclimate/tech-debt/nagyesta/lowkey-vault?logo=code%20climate)](https://img.shields.io/codeclimate/tech-debt/nagyesta/lowkey-vault?logo=code%20climate)
Expand Down Expand Up @@ -55,6 +56,10 @@ I have an app using Azure Key Vault and:
> [!NOTE]
> A complex example is available [here](https://github.com/nagyesta/lowkey-vault-example-docker)
> [!TIP]
> Lowkey Vault offers a multi-arch image variant too. You can find the relevant project [here](https://github.com/nagyesta/lowkey-vault-docker-buildx).

1. Pull the most recent version from ```nagyesta/lowkey-vault```
- You can find a list of all the available tags [here](https://hub.docker.com/r/nagyesta/lowkey-vault/tags)
2. ```docker run --rm -p 8443:8443 nagyesta/lowkey-vault:<version>```
Expand Down
3 changes: 2 additions & 1 deletion lowkey-vault-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![GitHub license](https://img.shields.io/github/license/nagyesta/lowkey-vault?color=informational)](https://raw.githubusercontent.com/nagyesta/lowkey-vault/main/LICENSE)
[![Java version](https://img.shields.io/badge/Java%20version-17-yellow?logo=java)](https://img.shields.io/badge/Java%20version-17-yellow?logo=java)
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.nagyesta.lowkey-vault/lowkey-vault-app?logo=apache-maven)](https://search.maven.org/search?q=com.github.nagyesta.lowkey-vault)

[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![codecov](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=app&token=3ZZ9Q4S5WW)](https://app.codecov.io/gh/nagyesta/lowkey-vault?flags%5B0%5D=app)
[![badge-abort-mission-armed-green](https://raw.githubusercontent.com/nagyesta/abort-mission/wiki_assets/.github/assets/badge-abort-mission-armed-green.svg)](https://github.com/nagyesta/abort-mission)
Expand Down
3 changes: 2 additions & 1 deletion lowkey-vault-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![GitHub license](https://img.shields.io/github/license/nagyesta/lowkey-vault?color=informational)](https://raw.githubusercontent.com/nagyesta/lowkey-vault/main/LICENSE)
[![Java version](https://img.shields.io/badge/Java%20version-11-yellow?logo=java)](https://img.shields.io/badge/Java%20version-11-yellow?logo=java)
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.nagyesta.lowkey-vault/lowkey-vault-app?logo=apache-maven)](https://search.maven.org/search?q=com.github.nagyesta.lowkey-vault)

[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![codecov](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=client&token=3ZZ9Q4S5WW)](https://app.codecov.io/gh/nagyesta/lowkey-vault?flags%5B0%5D=client)
[![badge-abort-mission-armed-green](https://raw.githubusercontent.com/nagyesta/abort-mission/wiki_assets/.github/assets/badge-abort-mission-armed-green.svg)](https://github.com/nagyesta/abort-mission)
Expand Down
16 changes: 9 additions & 7 deletions lowkey-vault-docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@
[![GitHub license](https://img.shields.io/github/license/nagyesta/lowkey-vault?color=informational)](https://raw.githubusercontent.com/nagyesta/lowkey-vault/main/LICENSE)
[![Java version](https://img.shields.io/badge/Java%20version-17-yellow?logo=java)](https://img.shields.io/badge/Java%20version-17-yellow?logo=java)
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Docker Pulls](https://img.shields.io/docker/pulls/nagyesta/lowkey-vault?logo=docker)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=semver&arch=amd64&logo=docker&label=amd64)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=date&arch=arm64&logo=docker&label=multi-arch)](https://hub.docker.com/r/nagyesta/lowkey-vault)

[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![Docker Pulls](https://img.shields.io/docker/pulls/nagyesta/lowkey-vault?logo=docker)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![badge-abort-mission-armed-green](https://raw.githubusercontent.com/nagyesta/abort-mission/wiki_assets/.github/assets/badge-abort-mission-armed-green.svg)](https://github.com/nagyesta/abort-mission)

# Lowkey Vault - Docker

This is the root of the Docker image. Visit the [Readme](../README.md) in the repo root for more information about the project in general.

## ARM builds

> [!TIP]
> Lowkey Vault offers a multi-arch image variant too. You can find the relevant project [here](https://github.com/nagyesta/lowkey-vault-docker-buildx).
## Startup parameters

In case you need to change any of the default parameters, you can use the ```LOWKEY_ARGS``` environment variable with
Expand Down Expand Up @@ -69,8 +76,3 @@ configuration can work as well. For example, if there is a ./config/application.
to the folder where the Jar is running, the contents will be picked up automatically. To utilize this, the
recommended option is to attach a *.properties file to /config/application.properties (path inside the
container) using a volume.

## ARM builds

> [!TIP]
> Lowkey Vault offers a multi-arch variant using Buildx. You can find the relevant project [here](https://github.com/nagyesta/lowkey-vault-docker-buildx).
14 changes: 11 additions & 3 deletions lowkey-vault-testcontainers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
[![GitHub license](https://img.shields.io/github/license/nagyesta/lowkey-vault?color=informational)](https://raw.githubusercontent.com/nagyesta/lowkey-vault/main/LICENSE)
[![Java version](https://img.shields.io/badge/Java%20version-11-yellow?logo=java)](https://img.shields.io/badge/Java%20version-11-yellow?logo=java)
[![latest-release](https://img.shields.io/github/v/tag/nagyesta/lowkey-vault?color=blue&logo=git&label=releases&sort=semver)](https://github.com/nagyesta/lowkey-vault/releases)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?label=docker%20hub&logo=docker&sort=semver)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Maven Central](https://img.shields.io/maven-central/v/com.github.nagyesta.lowkey-vault/lowkey-vault-app?logo=apache-maven)](https://search.maven.org/search?q=com.github.nagyesta.lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=semver&arch=amd64&logo=docker&label=amd64)](https://hub.docker.com/r/nagyesta/lowkey-vault)
[![Docker Hub](https://img.shields.io/docker/v/nagyesta/lowkey-vault?sort=date&arch=arm64&logo=docker&label=multi-arch)](https://hub.docker.com/r/nagyesta/lowkey-vault)

[![JavaCI](https://img.shields.io/github/actions/workflow/status/nagyesta/lowkey-vault/gradle.yml?logo=github&branch=main)](https://github.com/nagyesta/lowkey-vault/actions/workflows/gradle.yml)
[![codecov](https://img.shields.io/codecov/c/github/nagyesta/lowkey-vault?label=Coverage&flag=testcontainers&token=3ZZ9Q4S5WW)](https://app.codecov.io/gh/nagyesta/lowkey-vault?flags%5B0%5D=testcontainers)
[![badge-abort-mission-armed-green](https://raw.githubusercontent.com/nagyesta/abort-mission/wiki_assets/.github/assets/badge-abort-mission-armed-green.svg)](https://github.com/nagyesta/abort-mission)
Expand Down Expand Up @@ -66,7 +69,7 @@ import static com.github.nagyesta.lowkeyvault.testcontainers.LowkeyVaultContaine
class Test {
public LowkeyVaultContainer startVault() {
//Please consider using latest image regardless of the value in the example
final DockerImageName imageName = DockerImageName.parse("nagyesta/lowkey-vault:2.6.15");
final DockerImageName imageName = DockerImageName.parse("nagyesta/lowkey-vault:<version>");
final LowkeyVaultContainer lowkeyVaultContainer = lowkeyVault(imageName)
.vaultNames(Set.of("default"))
.build()
Expand All @@ -75,9 +78,14 @@ class Test {
return lowkeyVaultContainer;
}
}

```

##### ARM builds

> [!TIP]
> Lowkey Vault offers a multi-arch image variant too. You can find the relevant project [here](https://github.com/nagyesta/lowkey-vault-docker-buildx).

#### Example importing contents from file

In this example we are importing a file including the placeholder specific configuration and setting additional parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.nagyesta.lowkeyvault.testcontainers;

import org.slf4j.Logger;
import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
Expand Down Expand Up @@ -66,7 +68,10 @@ public LowkeyVaultContainer(final DockerImageName dockerImageName, final Set<Str
LowkeyVaultContainer(final LowkeyVaultContainerBuilder containerBuilder) {
super(containerBuilder.getDockerImageName());

containerBuilder.getDockerImageName().assertCompatibleWith(DEFAULT_IMAGE_NAME);
recommendMultiArchImageIfApplicable(logger(),
containerBuilder.getDockerImageName(),
DockerClientFactory.instance().client().versionCmd().exec().getArch());

if (containerBuilder.getHostPort() != null) {
addFixedExposedPort(containerBuilder.getHostPort(), CONTAINER_PORT);
} else {
Expand Down Expand Up @@ -233,4 +238,28 @@ public String getDefaultKeyStorePassword() {
throw new IllegalStateException("Failed to get default key store password", e);
}
}

/**
* Evaluates whether the currently used image is the recommended one for the host architecture.
* Prints warning log messages if it would be recommended to use multi-arch images instead.
*
* @param logger The logger where we want to print the recommendation
* @param dockerImageName The name of the current docker image
* @param hostArch The host architecture
*/
protected void recommendMultiArchImageIfApplicable(
final Logger logger,
final DockerImageName dockerImageName,
final String hostArch) {
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
final boolean hostArchIsNotAmd64 = !"amd64".equals(hostArch);
final boolean defaultImageUsed = DEFAULT_IMAGE_NAME.getUnversionedPart().equals(dockerImageName.getUnversionedPart());
final String versionPart = dockerImageName.getVersionPart();
final boolean imageIsNotMultiArch = !versionPart.contains("-ubi9-minimal");
if (defaultImageUsed && hostArchIsNotAmd64 && imageIsNotMultiArch) {
logger.warn("An amd64 image is detected with non-amd64 ({}) host.", hostArch);
logger.warn("Please consider using a multi-arch image, like: {}-ubi9-minimal", versionPart);
logger.warn(("See more information: https://github.com/nagyesta/lowkey-vault/tree/main/lowkey-vault-docker#arm-builds"));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.github.nagyesta.lowkeyvault.testcontainers;

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.slf4j.Logger;
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
import org.testcontainers.utility.DockerImageName;

import java.util.stream.Stream;

import static org.mockito.Mockito.*;

class LowkeyVaultContainerTest extends AbstractLowkeyVaultContainerTest {

public static Stream<Arguments> imageRecommendationInputProvider() {
return Stream.<Arguments>builder()
.add(Arguments.of("nagyesta/lowkey-vault:2.7.1", "amd64", false))
.add(Arguments.of("nagyesta/lowkey-vault:2.7.1", "arm64", true))
.add(Arguments.of("nagyesta/lowkey-vault:2.7.1-ubi9-minimal", "amd64", false))
.add(Arguments.of("lowkey-vault:2.7.1", "amd64", false))
.add(Arguments.of("lowkey-vault:2.7.1", "arm64", false))
.build();
}

@ParameterizedTest
@MethodSource("imageRecommendationInputProvider")
void testRecommendMultiArchImageIfApplicableShouldPrintRecommendationWhenHostIsNotMatchingImageArch(
final String imageName, final String hostArch, final boolean logExpected
) {
//given
final DockerImageName dockerImageName = DockerImageName.parse(imageName)
.asCompatibleSubstituteFor(LowkeyVaultContainer.DEFAULT_IMAGE_NAME);
final LowkeyVaultContainer underTest = spy(LowkeyVaultContainerBuilder
.lowkeyVault(LowkeyVaultContainer.DEFAULT_IMAGE_NAME.withTag("2.7.1"))
.build())
.withImagePullPolicy(shouldPull -> false);
final Logger loggerMock = mock(Logger.class);

//when
underTest.recommendMultiArchImageIfApplicable(loggerMock, dockerImageName, hostArch);

//then
if (logExpected) {
verify(loggerMock).warn(
eq("An amd64 image is detected with non-amd64 ({}) host."), eq(hostArch));
verify(loggerMock).warn(
eq("Please consider using a multi-arch image, like: {}-ubi9-minimal"),
eq(StringUtils.substringAfterLast(imageName, ":")));
verify(loggerMock).warn(
eq("See more information: https://github.com/nagyesta/lowkey-vault/tree/main/lowkey-vault-docker#arm-builds"));
}
verifyNoMoreInteractions(loggerMock);
}
}

0 comments on commit 6a770d2

Please # to comment.