Skip to content

Commit

Permalink
Specify a custom container registry (#970)
Browse files Browse the repository at this point in the history
* Use defined images

* Add container registry property

* Fix mispell of buildArgs

* Try simpifing buildArgs

* Fix build arg

* Print container registry and build args

* Use container registry arg in gosu

* Set container registry without build-args

* Fix adding build arguments

* Add container registry argument to dockerfiles and docker build cmds

* Add container registry property to RedHat tests

* Print container registry

* Use environment variable to set registry

* Debug container registry

* Print container registry on gradle for debug

* Add container registry option to all distros

* Fix container registry for debian Dockerfile

* Fix bug when container registry wasn't set

* Fix missing semicolons

* Fix issue to send container registry when testing

* Print docker.io as default container registry

* Add just CONTAINER_REGISTRY as build argument

* Fix identation issues

* Check if container registry is not null or empty string

* Fix image order
  • Loading branch information
Luigi96 authored Aug 26, 2024
1 parent 7c831ec commit 38b2d02
Show file tree
Hide file tree
Showing 30 changed files with 354 additions and 98 deletions.
4 changes: 4 additions & 0 deletions linux/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,8 @@ def getInputDir() {

def getLocalBuildStatus() {
return hasProperty("INPUT_DIR") ? "true" : "false"
}

def getContainerRegistry() {
return hasProperty("CONTAINER_REGISTRY") ? CONTAINER_REGISTRY.toString() : ""
}
11 changes: 11 additions & 0 deletions linux/ca-certificates/debian/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ task packageCaCertificatesDebian {
def outputDir = new File(project.buildDir.absolutePath, "ospackage")
outputs.dir(outputDir)

// Get container registry property. If not set, return empty string that is equivalent to dockerhub
def containerRegistry = getContainerRegistry()

doLast {
project.copy {
from("src/main/packaging/")
Expand All @@ -84,6 +87,7 @@ task packageCaCertificatesDebian {
workingDir "src/main/packaging"
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-cacerts-debian",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand All @@ -108,8 +112,15 @@ task checkCaCertificatesDebian(type: Test) {
testClassesDirs = sourceSets.packageTest.output.classesDirs
classpath = sourceSets.packageTest.runtimeClasspath

def containerRegistry = getContainerRegistry()

environment "PACKAGE", "adoptium-ca-certificates"

if (containerRegistry != null && containerRegistry != "") {
environment "containerRegistry", "$containerRegistry"
println "Container registry set to $containerRegistry"
}

useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
Expand Down
4 changes: 3 additions & 1 deletion linux/ca-certificates/debian/src/main/packaging/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM debian:bullseye
ARG CONTAINER_REGISTRY=""

FROM ${CONTAINER_REGISTRY}debian:bullseye

# Combine apt-get update with apt-get install to prevent stale package indexes.
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,25 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
* Ubuntu policy: Current LTS versions, and development version.
* (https://wiki.ubuntu.com/Releases)
*/

String containerRegistry = "";

if (System.getenv("containerRegistry") == null) {
System.out.println("Using docker.io as the default container registry");
} else {
containerRegistry = System.getenv("containerRegistry");
System.out.println("Using container registry: " + containerRegistry);
}

return Stream.of(
Arguments.of("debian", "trixie"), // Debian/13 (testing)
Arguments.of("debian", "bookworm"), // Debian/12 (testing)
Arguments.of("debian", "bullseye"), // Debian/11 (stable)
Arguments.of("debian", "buster"), // Debian/10 (oldstable)
Arguments.of("ubuntu", "noble"), // Ubuntu/24.04 (LTS)
Arguments.of("ubuntu", "jammy"), // Ubuntu/22.04 (LTS)
Arguments.of("ubuntu", "focal"), // Ubuntu/20.04 (LTS)
Arguments.of("ubuntu", "bionic") // Ubuntu/18.04 (LTS)
Arguments.of(containerRegistry + "debian", "trixie"), // Debian/13 (testing)
Arguments.of(containerRegistry + "debian", "bookworm"), // Debian/12 (testing)
Arguments.of(containerRegistry + "debian", "bullseye"), // Debian/11 (stable)
Arguments.of(containerRegistry + "debian", "buster"), // Debian/10 (oldstable)
Arguments.of(containerRegistry + "ubuntu", "noble"), // Ubuntu/24.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "jammy"), // Ubuntu/22.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "focal"), // Ubuntu/20.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "bionic") // Ubuntu/18.04 (LTS)
);
}
}
11 changes: 11 additions & 0 deletions linux/jdk/alpine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ task packageJdkAlpine {
def gpgKey = getGPGKey()
def arch = getArch()

// Get container registry property. If not set, return empty string that is equivalent to dockerhub. If not set, return empty string that is equivalent to dockerhub
def containerRegistry = getContainerRegistry()

doLast {
if (!file("src/main/packaging/$product/$productVersion").exists()) {
throw new IllegalArgumentException("Unknown product $product/$productVersion")
Expand All @@ -84,6 +87,7 @@ task packageJdkAlpine {
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-jdk-alpine",
"--secret", "id=gpg,src=${gpgKey}",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand All @@ -92,6 +96,7 @@ task packageJdkAlpine {
workingDir "src/main/packaging"
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-jdk-alpine",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand Down Expand Up @@ -120,13 +125,19 @@ task checkJdkAlpine(type: Test) {
def product = getProduct()
def productVersion = getProductVersion()
def gpgKey = getGPGKey()
def containerRegistry = getContainerRegistry()

environment "PACKAGE", "${product}-${productVersion}-jdk"
if (gpgKey != null) {
environment "JDKGPG", "$gpgKey"
println "We set the gpgkey!"
}

if (containerRegistry != null && containerRegistry != "") {
environment "containerRegistry", "$containerRegistry"
println "Container registry set to $containerRegistry"
}

useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
Expand Down
4 changes: 3 additions & 1 deletion linux/jdk/alpine/src/main/packaging/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM alpine
ARG CONTAINER_REGISTRY=""

FROM ${CONTAINER_REGISTRY}alpine
ENV GOSU_VERSION 1.14

RUN set -eux; \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ public class AlpineFlavours implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
/*
* Alpine policy: current (alive) releases and development version.
* (https://alpinelinux.org/releases/)
* Alpine policy: current (alive) releases and development version.
* (https://alpinelinux.org/releases/)
*/

String containerRegistry = "";

if (System.getenv("containerRegistry") == null) {
System.out.println("Using docker.io as the default container registry");
} else {
containerRegistry = System.getenv("containerRegistry");
System.out.println("Using container registry: " + containerRegistry);
}

return Stream.of(
Arguments.of("alpine", "edge"),
Arguments.of("alpine", "latest"),
Arguments.of("alpine", "3.19"),
Arguments.of("alpine", "3.18"),
Arguments.of("alpine", "3.17")
Arguments.of(containerRegistry + "alpine", "edge"),
Arguments.of(containerRegistry + "alpine", "latest"),
Arguments.of(containerRegistry + "alpine", "3.19"),
Arguments.of(containerRegistry + "alpine", "3.18"),
Arguments.of(containerRegistry + "alpine", "3.17")
);
}
}
13 changes: 13 additions & 0 deletions linux/jdk/debian/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ task packageJdkDebian {
def input_dir = getInputDir()
def buildLocalFlag = getLocalBuildStatus()

// Get container registry property. If not set, return empty string that is equivalent to dockerhub
def containerRegistry = getContainerRegistry()

doLast {
if (!file("src/main/packaging/$product/$productVersion").exists()) {
throw new IllegalArgumentException("Unknown product $product/$productVersion")
Expand Down Expand Up @@ -107,6 +110,7 @@ if ("$arch" == "armhf") {
commandLine "docker", "build", "--no-cache",
"--build-arg", "IMAGE=arm32v7/debian:bullseye",
"-t", "adoptium-packages-linux-jdk-debian",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand All @@ -118,6 +122,7 @@ if ("$arch" == "riscv64") {
commandLine "docker", "build", "--no-cache",
"--build-arg", "IMAGE=riscv64/ubuntu:jammy",
"-t", "adoptium-packages-linux-jdk-debian",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand All @@ -128,6 +133,7 @@ if ("$arch" != "armhf" && "$arch" != "riscv64"){
workingDir "src/main/packaging"
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-jdk-debian",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand Down Expand Up @@ -159,6 +165,8 @@ task checkJdkDebian(type: Test) {

def product = getProduct()
def productVersion = getProductVersion()

def containerRegistry = getContainerRegistry()

// If product is microsoft set it as msopenjdk
if (product == "microsoft") {
Expand All @@ -167,6 +175,11 @@ task checkJdkDebian(type: Test) {
environment "PACKAGE", "$product-$productVersion-jdk"
}

if (containerRegistry != null && containerRegistry != "") {
environment "containerRegistry", "$containerRegistry"
println "Container registry set to $containerRegistry"
}

useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
Expand Down
3 changes: 2 additions & 1 deletion linux/jdk/debian/src/main/packaging/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG CONTAINER_REGISTRY=""
ARG IMAGE=debian:bullseye
FROM $IMAGE
FROM ${CONTAINER_REGISTRY}${IMAGE}

# Combine apt-get update with apt-get install to prevent stale package indexes.
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential \
Expand Down
48 changes: 29 additions & 19 deletions linux/jdk/debian/src/packageTest/java/packaging/DebianFlavours.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,33 @@
* @author luozhenyu
*/
public class DebianFlavours implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
/*
* Debian policy: oldstable, stable and testing version.
* (https://www.debian.org/releases/)
* Ubuntu policy: Current LTS versions, and development version.
* (https://wiki.ubuntu.com/Releases)
*/
return Stream.of(
Arguments.of("debian", "trixie"), // Debian/13 (testing)
Arguments.of("debian", "bookworm"), // Debian/12 (testing)
Arguments.of("debian", "bullseye"), // Debian/11 (stable)
Arguments.of("debian", "buster"), // Debian/10 (oldstable)
Arguments.of("ubuntu", "noble"), // Ubuntu/24.04 (LTS)
Arguments.of("ubuntu", "jammy"), // Ubuntu/22.04 (LTS)
Arguments.of("ubuntu", "focal"), // Ubuntu/20.04 (LTS)
Arguments.of("ubuntu", "bionic") // Ubuntu/18.04 (LTS)
);
}
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
/*
* Debian policy: oldstable, stable and testing version.
* (https://www.debian.org/releases/)
* Ubuntu policy: Current LTS versions, and development version.
* (https://wiki.ubuntu.com/Releases)
*/

String containerRegistry = "";

if (System.getenv("containerRegistry") == null) {
System.out.println("Using docker.io as the default container registry");
} else {
containerRegistry = System.getenv("containerRegistry");
System.out.println("Using container registry: " + containerRegistry);
}

return Stream.of(
Arguments.of(containerRegistry + "debian", "trixie"), // Debian/13 (testing)
Arguments.of(containerRegistry + "debian", "bookworm"), // Debian/12 (testing)
Arguments.of(containerRegistry + "debian", "bullseye"), // Debian/11 (stable)
Arguments.of(containerRegistry + "debian", "buster"), // Debian/10 (oldstable)
Arguments.of(containerRegistry + "ubuntu", "noble"), // Ubuntu/24.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "jammy"), // Ubuntu/22.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "focal"), // Ubuntu/20.04 (LTS)
Arguments.of(containerRegistry + "ubuntu", "bionic") // Ubuntu/18.04 (LTS)
);
}
}
14 changes: 14 additions & 0 deletions linux/jdk/redhat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ task packageJdkRedHat {
def outputDir = new File(project.buildDir.absolutePath, "ospackage")
outputs.dir(outputDir)

// Get container registry property. If not set, return empty string that is equivalent to dockerhub
def containerRegistry = getContainerRegistry()

doLast {
if (!file("src/main/packaging/$product/$productVersion").exists()) {
throw new IllegalArgumentException("Unknown product $product/$productVersion")
Expand Down Expand Up @@ -97,6 +100,7 @@ task packageJdkRedHat {
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-jdk-redhat",
"--secret", "id=gpg,src=${gpgKey}",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand All @@ -105,6 +109,7 @@ task packageJdkRedHat {
workingDir "src/main/packaging"
commandLine "docker", "build", "--no-cache",
"-t", "adoptium-packages-linux-jdk-redhat",
"--build-arg=CONTAINER_REGISTRY=${containerRegistry}",
"-f", "Dockerfile",
getProjectDir().absolutePath + "/src/main/packaging"
}
Expand Down Expand Up @@ -138,6 +143,9 @@ task checkJdkRedHat(type: Test) {
def gpgKey = getGPGKey()
def arch = getArch()

def containerRegistry = getContainerRegistry()
// def containerRegistry = "junipercontainerregistry.azurecr.io/mirror/"

// If product is microsoft set it as msopenjdk
if (product == "microsoft") {
environment "PACKAGE", "msopenjdk-$productVersion"
Expand All @@ -150,6 +158,12 @@ task checkJdkRedHat(type: Test) {
println "We set the gpgkey!"
}
environment "testArch", "$arch"

if (containerRegistry != null && containerRegistry != "") {
environment "containerRegistry", "$containerRegistry"
println "Container registry set to $containerRegistry"
}

useJUnitPlatform()
testLogging {
events "passed", "skipped", "failed"
Expand Down
7 changes: 5 additions & 2 deletions linux/jdk/redhat/src/main/packaging/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM fedora:38
ARG CONTAINER_REGISTRY=""

FROM ${CONTAINER_REGISTRY}tianon/gosu as gosu
FROM ${CONTAINER_REGISTRY}fedora:38

RUN dnf update -y && dnf install -y rpmdevtools \
rpm-sign \
Expand All @@ -9,7 +12,7 @@ RUN dnf update -y && dnf install -y rpmdevtools \
tini \
wget

COPY --from=tianon/gosu /gosu /usr/local/bin/
COPY --from=gosu /gosu /usr/local/bin/

# Create unprivileged user for building, see
# https://github.com/hexops/dockerfile#use-a-static-uid-and-gid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,26 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
* ubi7 does not have DNF pre-installed, ubi-minimal has microdnf
* ubi8 has DNF installed
*/

String containerRegistry = "";

if (System.getenv("containerRegistry") == null) {
System.out.println("Using docker.io as the default container registry");
} else {
containerRegistry = System.getenv("containerRegistry");
System.out.println("Using container registry: " + containerRegistry);
}

return Stream.of(
Arguments.of("rockylinux", "8"),
Arguments.of("fedora", "35"),
Arguments.of("fedora", "36"),
Arguments.of("fedora", "37"),
Arguments.of("fedora", "38"),
Arguments.of("fedora", "39"),
Arguments.of("redhat/ubi8", "latest"),
Arguments.of("redhat/ubi9", "latest"),
Arguments.of("oraclelinux", "8")
Arguments.of(containerRegistry + "rockylinux", "8"),
Arguments.of(containerRegistry + "fedora", "35"),
Arguments.of(containerRegistry + "fedora", "36"),
Arguments.of(containerRegistry + "fedora", "37"),
Arguments.of(containerRegistry + "fedora", "38"),
Arguments.of(containerRegistry + "fedora", "39"),
Arguments.of(containerRegistry + "redhat/ubi8", "latest"),
Arguments.of(containerRegistry + "redhat/ubi9", "latest"),
Arguments.of(containerRegistry + "oraclelinux", "8")
);
}
}
Loading

0 comments on commit 38b2d02

Please sign in to comment.