Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Chainguard's Wolfi base image by default #927

Merged
merged 5 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,6 @@ private void setupInstructions(List<Instruction> additionalInstructions) {
break;
default:
from(baseImageProvider);
// mandatory dependency for alpine-glibc docker images
runCommand(getProviders().provider(() -> {
if (baseImageProvider.get().getImage().contains("alpine-glibc")) {
return "apk --no-cache update && apk add libstdc++";
}
return null;
}));
exposePort(getExposedPorts());
getInstructions().addAll(additionalInstructions);
copyFile(new CopyFile(workDir + "/application", "/app/application").withStage("graalvm"));
Expand Down Expand Up @@ -751,11 +744,7 @@ private String resolve() {
if (strategy == DockerBuildStrategy.LAMBDA && baseImage == null) {
baseImage = "amazonlinux:2";
} else if (baseImage == null) {
baseImage = getGraalArch()
.map(a -> a.equals(ARM_ARCH)
? "cgr.dev/chainguard/wolfi-base:latest"
: "frolvlad/alpine-glibc:alpine-" + DefaultVersions.ALPINE)
.getOrElse("frolvlad/alpine-glibc:alpine-" + DefaultVersions.ALPINE);
baseImage = "cgr.dev/chainguard/wolfi-base:latest";
}

return baseImage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ COPY --link config-dirs/generateResourcesConfigFile /home/app/config-dirs/genera
COPY --link config-dirs/io.netty/netty-common/4.0.0.Final /home/app/config-dirs/io.netty/netty-common/4.0.0.Final
COPY --link config-dirs/ch.qos.logback/logback-classic/4.0.0 /home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0
RUN native-image --exclude-config .*/libs/netty-transport-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-buffer-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-handler-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-common-4.0.0.Final.jar ^/META-INF/native-image/.* --exclude-config .*/libs/netty-codec-http2-4.0.0.Final.jar ^/META-INF/native-image/.* -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -o application -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile,/home/app/config-dirs/io.netty/netty-buffer/4.0.0.Final,/home/app/config-dirs/io.netty/netty-common/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http/4.0.0.Final,/home/app/config-dirs/io.netty/netty-transport/4.0.0.Final,/home/app/config-dirs/io.netty/netty-handler/4.0.0.Final,/home/app/config-dirs/io.netty/netty-codec-http2/4.0.0.Final,/home/app/config-dirs/ch.qos.logback/logback-classic/4.0.0 demo.app.Application
FROM frolvlad/alpine-glibc:alpine-${DefaultVersions.ALPINE}
RUN apk --no-cache update && apk add libstdc++
FROM cgr.dev/chainguard/wolfi-base:latest
EXPOSE 8080
COPY --link --from=graalvm /home/app/application /app/application
ENTRYPOINT ["/app/application"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import spock.lang.Requires
class DockerNativeFunctionalTest extends AbstractEagerConfiguringFunctionalTest {

@Lazy
String defaultBaseImage = { -> System.properties['os.arch'] == "aarch64" ? 'cgr.dev/chainguard/wolfi-base:latest' : "frolvlad/alpine-glibc:alpine-${DefaultVersions.ALPINE}" }()
String defaultBaseImage = 'cgr.dev/chainguard/wolfi-base:latest'

@Lazy
String defaultDockerFrom = { -> "FROM $defaultBaseImage" + (System.properties['os.arch'] == "aarch64" ? '' : '\nRUN apk --no-cache update && apk add libstdc++') }()
String defaultDockerFrom = "FROM $defaultBaseImage"

def "test build docker native image for runtime #runtime"() {
given:
Expand Down Expand Up @@ -161,7 +161,7 @@ micronaut:
runtime << ['netty', 'lambda_provided']
}

void 'use alpine-glibc by default and do not build mostly static native images'() {
void 'use wolfi-base by default and do not build mostly static native images'() {
given:
settingsFile << "rootProject.name = 'hello-world'"
buildFile << """
Expand Down Expand Up @@ -202,7 +202,7 @@ micronaut:
dockerFileNative.find { s -> !s.contains('-H:+StaticExecutableWithDynamicLibC') }
}

void 'do not use alpine-glibc for lambda_provided runtime'() {
void 'do not use wolfi-base for lambda_provided runtime'() {
given:
settingsFile << "rootProject.name = 'hello-world'"
buildFile << """
Expand Down Expand Up @@ -239,7 +239,7 @@ micronaut:
dockerfileNativeTask.outcome == TaskOutcome.SUCCESS

and:
dockerFileNative.find { s -> !s.contains('FROM frolvlad/alpine-glibc:alpine-') }
dockerFileNative.find { s -> !s.contains('FROM cgr.dev/chainguard/wolfi-base:latest') }
dockerFileNative.find { s -> !s.contains('-H:+StaticExecutableWithDynamicLibC') }
}

Expand Down
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ shadow = "8.1.1"
groovy = "3.0.19"
spock = "2.1-groovy-3.0"
oraclelinux = "9"
alpine="3.16"
graalvmPlugin = "0.9.28"
micronaut-platform = "4.2.1" # This is the platform version, used in our tests
micronaut-aot = "2.1.1"
Expand Down
1 change: 0 additions & 1 deletion minimal-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var writeVersions = tasks.register("writeDefaultVersions", WriteVersions) {
versions.put('test-resources', libs.versions.micronaut.testresources)
versions.put('openapi', libs.versions.micronaut.openapi)
versions.put('oraclelinux', libs.versions.oraclelinux)
versions.put('alpine', libs.versions.alpine)
packageName = 'io.micronaut.gradle'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ datasources:
# driverClassName: org.postgresql.Driver
# schema-generate: CREATE_DROP
# dialect: POSTGRES
test-resources:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for interfering, just to ask can you try using test-containers 1.19.4 in this PR, maybe these mysql overrides won't be needed?
https://github.com/testcontainers/testcontainers-java/releases/tag/1.19.4 contains fix for MySQL it seems.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I plan to test that version, but not in that PR, reason being that it's driven by test resources, not the Gradle plugin.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, I assume it is test-resources as soon as I see your name:)

containers:
mysql:
image-name: mysql:8.2
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ datasources:
default:
schema-generate: CREATE_DROP
dialect: MYSQL
test-resources:
containers:
mysql:
image-name: mysql:8.2
2 changes: 1 addition & 1 deletion src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ dockerfileNative {
}
----

The compiled native binary will ultimately be copied into an `alpine-glibc` base image for X86_64, and `cgr.dev/chainguard/wolfi-base` for ARM.
The compiled native binary will ultimately be copied into an `cgr.dev/chainguard/wolfi-base:latest` base image.
These base images can be overridden via configuration see <<_base_image_and_pull_limits>> and <<_build_mostly_static_native_executables>>.

[#_base_image_and_pull_limits]
Expand Down
Loading