Build the operator container via Dockerfile (#19642)

Closes #16967
This commit is contained in:
Alex Szczuczko 2023-04-21 00:32:29 -06:00 committed by GitHub
parent 68b3c87666
commit edaa84b1e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 100 additions and 4 deletions

View file

@ -145,7 +145,7 @@ jobs:
-Dquarkus.container-image.build=true \ -Dquarkus.container-image.build=true \
-Dquarkus.kubernetes.image-pull-policy=IfNotPresent \ -Dquarkus.kubernetes.image-pull-policy=IfNotPresent \
-Doperator.keycloak.image=keycloak:${{ env.version_remote }} \ -Doperator.keycloak.image=keycloak:${{ env.version_remote }} \
-Dquarkus.jib.jvm-arguments="-Djava.util.logging.manager=org.jboss.logmanager.LogManager","-Doperator.keycloak.image-pull-policy=Never" \ -Dquarkus.kubernetes.env.vars.operator-keycloak-image-pull-policy=Never \
-Dtest.operator.custom.image=custom-keycloak:${{ env.version_remote }} \ -Dtest.operator.custom.image=custom-keycloak:${{ env.version_remote }} \
--no-transfer-progress -Dtest.operator.deployment=remote \ --no-transfer-progress -Dtest.operator.deployment=remote \
-Dtest.operator.kubernetes.ip=$(minikube ip) -Dtest.operator.kubernetes.ip=$(minikube ip)

21
operator/Dockerfile Normal file
View file

@ -0,0 +1,21 @@
FROM registry.access.redhat.com/ubi9 AS ubi-micro-build
ADD target/ubi-null.sh /tmp/
RUN bash /tmp/ubi-null.sh java-17-openjdk-headless glibc-langpack-en
FROM registry.access.redhat.com/ubi9-micro
ENV LANG en_US.UTF-8
COPY --from=ubi-micro-build /tmp/null/rootfs/ /
ADD --chown=1000:0 target/quarkus-app/ /opt/keycloak
RUN chmod -R g+rwX /opt/keycloak && \
echo "keycloak:x:0:root" >> /etc/group && \
echo "keycloak:x:1000:0:keycloak user:/opt/keycloak:/sbin/nologin" >> /etc/passwd
USER 1000
WORKDIR /opt/keycloak
ENTRYPOINT [ "java", "-Djava.util.logging.manager=org.jboss.logmanager.LogManager", "-jar", "quarkus-run.jar" ]

View file

@ -19,6 +19,12 @@ Build the Docker image with:
mvn clean package -Doperator -Dquarkus.container-image.build=true mvn clean package -Doperator -Dquarkus.container-image.build=true
``` ```
This will build a container image from `src/main/docker/Dockerfile.jvm`, using `docker` by default. `podman` is also supported if you do these steps beforehand:
- Follow [this guide](https://quarkus.io/guides/podman#setting-docker_host-on-linux) to enable the podman user socket
- Set the `DOCKER_HOST` environment variable to point at this user socket. For example: `DOCKER_HOST=unix:///run/user/1000/podman/podman.sock`.
- You may also have to set `QUARKUS_DOCKER_EXECUTABLE_NAME=podman`
## Configuration ## Configuration
The Keycloak image can be configured, when starting the operator, using the Java property: The Keycloak image can be configured, when starting the operator, using the Java property:

26
operator/assembly.xml Normal file
View file

@ -0,0 +1,26 @@
<assembly>
<id>operator</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>${project.build.directory}/quarkus-app/</directory>
<outputDirectory></outputDirectory>
<includes>
<include>**/**</include>
</includes>
<excludes>
</excludes>
</fileSet>
</fileSets>
<files>
</files>
</assembly>

View file

@ -35,7 +35,6 @@
<quarkus.operator.sdk.version>4.0.7</quarkus.operator.sdk.version> <quarkus.operator.sdk.version>4.0.7</quarkus.operator.sdk.version>
<quarkus.version>2.13.7.Final</quarkus.version> <quarkus.version>2.13.7.Final</quarkus.version>
<quarkus.container-image.group>keycloak</quarkus.container-image.group> <quarkus.container-image.group>keycloak</quarkus.container-image.group>
<quarkus.jib.base-jvm-image>registry.access.redhat.com/ubi9/openjdk-11-runtime</quarkus.jib.base-jvm-image>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -93,6 +92,10 @@
<groupId>io.quarkus</groupId> <groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId> <artifactId>quarkus-kubernetes-client</artifactId>
</dependency> </dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-container-image-docker</artifactId>
</dependency>
<!-- Keycloak --> <!-- Keycloak -->
<dependency> <dependency>
@ -202,6 +205,24 @@
</resources> </resources>
</configuration> </configuration>
</execution> </execution>
<execution>
<id>copy-ubi-null</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}/../quarkus/container/</directory>
<includes>
<include>**/ubi-null.sh</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions> </executions>
</plugin> </plugin>
@ -258,6 +279,27 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>assemble</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
<workDirectory>${project.build.directory}/assembly/work</workDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins> </plugins>
</build> </build>

View file

@ -1,5 +1,6 @@
quarkus.operator-sdk.crd.apply=true quarkus.operator-sdk.crd.apply=true
quarkus.container-image.builder=jib quarkus.container-image.builder=docker
quarkus.docker.dockerfile-jvm-path=Dockerfile
quarkus.operator-sdk.crd.validate=false quarkus.operator-sdk.crd.validate=false
# Operator config # Operator config

View file

@ -44,7 +44,7 @@ dnf install -y findutils diffutils
# Install core packages to chroot # Install core packages to chroot
rootfs="$(realpath rootfs)" rootfs="$(realpath rootfs)"
mkdir -p "$rootfs" mkdir -p "$rootfs"
<keep xargs dnf install -y --installroot "$rootfs" --releasever 8 --setopt install_weak_deps=false --nodocs <keep xargs dnf install -y --installroot "$rootfs" --releasever 9 --setopt install_weak_deps=false --nodocs
dnf --installroot "$rootfs" clean all dnf --installroot "$rootfs" clean all
rm -rf "$rootfs"/var/cache/* "$rootfs"/var/log/dnf* "$rootfs"/var/log/yum.* rm -rf "$rootfs"/var/cache/* "$rootfs"/var/log/dnf* "$rootfs"/var/log/yum.*
{ set +x; } 2>/dev/null { set +x; } 2>/dev/null