-
Notifications
You must be signed in to change notification settings - Fork 70
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
Cpbr 1867 ubi9 minimal #618
base: master
Are you sure you want to change the base?
Changes from all commits
70e40c0
2541a91
409bb4c
169acae
f3c7fbf
529ac03
b104644
d1014b9
241633b
da30d3f
ea65844
42421f4
5b32376
bbaff1b
664c82c
c509524
ce04ac7
cabebb2
a71423d
2f4faba
b16ec43
8101e30
9fecdd0
c460fde
df94173
c9204a1
7cab88d
3a16eb2
1a10982
e4e9987
db004c4
2bc7e3b
adf216c
c9c12ff
4914e2b
d3d6e45
35b2f3a
7acf42d
21b8049
edcd55c
b20eec5
106d5ea
d36386e
390a255
203090f
3743bc1
3d28ec3
3d1450d
3bea075
dc790b9
1c770cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
ARG UBI_MICRO_VERSION | ||
ARG TEMURIN_JDK_VERSION | ||
ARG DOCKER_UPSTREAM_REGISTRY | ||
ARG DOCKER_UPSTREAM_TAG | ||
ARG GOLANG_VERSION | ||
ARG UBI_MINIMAL_VERSION | ||
|
||
FROM docker.io/golang:${GOLANG_VERSION} AS build-ub-package-dedupe | ||
RUN useradd --no-log-init --create-home --shell /bin/bash appuser | ||
WORKDIR /build/package_dedupe | ||
COPY --chown=appuser:appuser package_dedupe/ ./ | ||
RUN go build -ldflags="-w -s" ./package_dedupe.go | ||
WORKDIR /build/ub | ||
COPY --chown=appuser:appuser ub/ ./ | ||
RUN go build -ldflags="-w -s" ./ub.go | ||
USER appuser | ||
RUN go test ./... | ||
|
||
FROM registry.access.redhat.com/ubi9-minimal:${UBI_MINIMAL_VERSION} AS REFRESH | ||
ARG PROJECT_VERSION | ||
ARG ARTIFACT_ID | ||
|
||
# Remember where we came from | ||
LABEL io.confluent.docker.git.repo="confluentinc/common-docker" | ||
|
||
ARG GIT_COMMIT | ||
LABEL io.confluent.docker.git.id=$GIT_COMMIT | ||
|
||
ARG BUILD_NUMBER=-1 | ||
LABEL io.confluent.docker.build.number=$BUILD_NUMBER | ||
|
||
LABEL maintainer="[email protected]" | ||
LABEL vendor="Confluent" | ||
LABEL version=$GIT_COMMIT | ||
LABEL release=$PROJECT_VERSION | ||
LABEL name=$ARTIFACT_ID | ||
LABEL summary="Common base image for new Confluent lightweight Docker images." | ||
LABEL description="Common base image for Confluent lightweight Docker images." | ||
LABEL io.confluent.docker=true | ||
# This affects how strings in Java class files are interpreted. We want UTF-8 and this is the only locale in the | ||
# base image that supports it | ||
ENV LANG="C.UTF-8" | ||
|
||
RUN printf "[temurin-jre] \n\ | ||
name=temurin-jre \n\ | ||
baseurl=https://packages.adoptium.net/artifactory/rpm/rhel/\$releasever/\$basearch \n\ | ||
enabled=1 \n\ | ||
gpgcheck=1 \n\ | ||
gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public \n\ | ||
" > /etc/yum.repos.d/adoptium.repo | ||
|
||
RUN echo "installing temurin-21-jre:${TEMURIN_JDK_VERSION}" \ | ||
&& microdnf install -y temurin-21-jre${TEMURIN_JDK_VERSION} \ | ||
&& microdnf clean all \ | ||
&& useradd --no-log-init --create-home --shell /bin/bash appuser | ||
|
||
COPY --from=build-ub-package-dedupe /build/package_dedupe /usr/bin/package_dedupe | ||
COPY --from=build-ub-package-dedupe /build/ub /usr/bin/ub | ||
|
||
|
||
COPY target/${ARTIFACT_ID}-${PROJECT_VERSION}-package/share/doc/* /usr/share/doc/${ARTIFACT_ID}/ | ||
COPY target/${ARTIFACT_ID}-${PROJECT_VERSION}-package/share/java/${ARTIFACT_ID}/* /usr/share/java/${ARTIFACT_ID}/ | ||
COPY --chown=appuser:appuser include/etc/confluent/docker /etc/confluent/docker | ||
COPY --chown=appuser:appuser include/etc/cp-base-java /etc/cp-base-java | ||
|
||
|
||
USER appuser | ||
WORKDIR /home/appuser |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../base/include/etc/cp-base-new/log4j.properties |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Copyright 2023 Confluent, Inc. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/sha1" | ||
|
||
"fmt" | ||
|
||
"io" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func dedupe_packages(rootPath string) { | ||
sha2path := make(map[string]string) | ||
err := filepath.Walk(rootPath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if info.IsDir() || info.Mode()&os.ModeSymlink != 0 { | ||
return nil | ||
} | ||
sha, err := shaSum(path) | ||
if err != nil { | ||
return err | ||
} | ||
if orig, exists := sha2path[sha]; exists { | ||
relPath, err := filepath.Rel(filepath.Dir(path), orig) | ||
if err != nil { | ||
return err | ||
} | ||
os.Remove(path) | ||
err = os.Symlink(relPath, path) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("DEDUP: ln -sf %s %s\n", orig, path) | ||
} else { | ||
sha2path[sha] = path | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func shaSum(path string) (string, error) { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
hash := sha1.New() | ||
if _, err := io.Copy(hash, file); err != nil { | ||
return "", err | ||
} | ||
return fmt.Sprintf("%x", hash.Sum(nil)), nil | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Println("Usage: dedupe_packages <directory_name>") | ||
os.Exit(1) | ||
} | ||
basePath := os.Args[1] | ||
dedupe_packages(basePath) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!--~ | ||
~ Copyright 2017 Confluent Inc. | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>io.confluent</groupId> | ||
<artifactId>common-docker</artifactId> | ||
<version>8.0.0-0</version> | ||
</parent> | ||
|
||
<packaging>pom</packaging> | ||
|
||
<artifactId>cp-base-java</artifactId> | ||
|
||
<description>Base for new Confluent lightweight Docker images</description> | ||
<name>${project.artifactId}</name> | ||
|
||
<properties> | ||
<docker.skip-build>false</docker.skip-build> | ||
<docker.skip-test>false</docker.skip-test> | ||
<docker.pull-image>true</docker.pull-image> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.confluent</groupId> | ||
<artifactId>utility-belt</artifactId> | ||
<version>${io.confluent.common-docker.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-resources-plugin</artifactId> | ||
<version>${maven-resources-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>copy-resources</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>copy-resources</goal> | ||
</goals> | ||
<configuration> | ||
<overwrite>true</overwrite> | ||
<outputDirectory>target</outputDirectory> | ||
<resources> | ||
<resource> | ||
<directory>${basedir}/../docker-utils/target</directory> | ||
<includes> | ||
<include>docker-utils-${CONFLUENT_VERSION}-jar-with-dependencies.jar</include> | ||
</includes> | ||
</resource> | ||
</resources> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.spotify</groupId> | ||
<artifactId>dockerfile-maven-plugin</artifactId> | ||
<configuration> | ||
<buildArgs> | ||
<UBI_MINIMAL_VERSION>${ubi9.image.version}</UBI_MINIMAL_VERSION> | ||
<TEMURIN_JDK_VERSION>-${ubi.temurin.jdk.version}</TEMURIN_JDK_VERSION> | ||
<SKIP_SECURITY_UPDATE_CHECK>${docker.skip-security-update-check}</SKIP_SECURITY_UPDATE_CHECK> | ||
<GOLANG_VERSION>${golang.version}</GOLANG_VERSION> | ||
</buildArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>io.fabric8</groupId> | ||
<artifactId>docker-maven-plugin</artifactId> | ||
<version>0.43.4</version> | ||
<configuration> | ||
<images> | ||
<image> | ||
<build> | ||
<args> | ||
<UBI_MINIMAL_VERSION>${ubi9.image.version}</UBI_MINIMAL_VERSION> | ||
<TEMURIN_JDK_VERSION>-${ubi.temurin.jdk.version}</TEMURIN_JDK_VERSION> | ||
<SKIP_SECURITY_UPDATE_CHECK> | ||
${docker.skip-security-update-check} | ||
</SKIP_SECURITY_UPDATE_CHECK> | ||
<GOLANG_VERSION>${golang.version}</GOLANG_VERSION> | ||
</args> | ||
</build> | ||
</image> | ||
</images> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
import unittest | ||
|
||
import confluent.docker_utils as utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep this file in base-lite also to make sure base-lite is getting built properly also. |
||
|
||
|
||
class BaseJavaImageTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.image = "{0}confluentinc/cp-base-java:{1}".format(os.environ["DOCKER_REGISTRY"], os.environ["DOCKER_TAG"]) | ||
|
||
def test_image_build(self): | ||
self.assertTrue(utils.image_exists(self.image)) | ||
|
||
def test_ub_exists(self): | ||
self.assertTrue(utils.path_exists_in_image(self.image, "/usr/bin/ub")) | ||
|
||
def test_ub_runnable(self): | ||
ub_cmd = "bash -c '/usr/bin/ub/ub -h'" | ||
self.assertTrue(b"utility commands" in utils.run_docker_command(image=self.image, command=ub_cmd)) | ||
|
||
def test_kafka_ready_jar(self): | ||
java_cmd = "bash -c 'java -cp \"/usr/share/java/cp-base-java/*\" io.confluent.admin.utils.cli.KafkaReadyCommand -h'" | ||
self.assertTrue(b"Check if Kafka is ready" in utils.run_docker_command(image=self.image, command=java_cmd)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,18 +13,9 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ARG UBI_MINIMAL_VERSION="latest" | ||
ARG GOLANG_VERSION | ||
|
||
FROM golang:${GOLANG_VERSION} AS build-ub | ||
WORKDIR /build | ||
RUN useradd --no-log-init --create-home --shell /bin/bash appuser | ||
COPY --chown=appuser:appuser ub/ ./ | ||
RUN go build -ldflags="-w -s" ./ub.go | ||
USER appuser | ||
RUN go test ./... | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi-minimal:${UBI_MINIMAL_VERSION} | ||
ARG DOCKER_UPSTREAM_REGISTRY | ||
ARG DOCKER_TAG | ||
FROM ${DOCKER_UPSTREAM_REGISTRY}confluentinc/cp-base-java:${DOCKER_TAG} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use new arg/env for the base image name as there are symlinks also added in the Dockerfile |
||
|
||
ARG PROJECT_VERSION | ||
ARG ARTIFACT_ID | ||
|
@@ -56,24 +47,15 @@ ARG TEMURIN_JDK_VERSION="" | |
|
||
ENV UB_CLASSPATH=/usr/share/java/cp-base-lite/* | ||
|
||
RUN printf "[temurin-jdk] \n\ | ||
name=temurin-jdk \n\ | ||
baseurl=https://packages.adoptium.net/artifactory/rpm/rhel/\$releasever/\$basearch \n\ | ||
enabled=1 \n\ | ||
gpgcheck=1 \n\ | ||
gpgkey=https://packages.adoptium.net/artifactory/api/gpg/key/public \n\ | ||
" > /etc/yum.repos.d/adoptium.repo | ||
|
||
RUN microdnf --nodocs install yum \ | ||
&& yum --nodocs update -y \ | ||
&& yum --nodocs install -y --setopt=install_weak_deps=False \ | ||
USER root | ||
|
||
RUN yum --nodocs update -y \ | ||
&& yum --nodocs install -y --setopt=install_weak_deps=False --allowerasing \ | ||
"curl${CURL_VERSION}" \ | ||
"temurin-21-jre${TEMURIN_JDK_VERSION}" \ | ||
&& microdnf clean all \ | ||
&& yum clean all \ | ||
&& rm -rf /tmp/* \ | ||
&& mkdir -p /etc/confluent/docker /usr/logs \ | ||
&& useradd --no-log-init --create-home --shell /bin/bash appuser \ | ||
&& chown appuser:appuser -R /etc/confluent/ /usr/logs | ||
|
||
# This is a step that will cause the build to fail of the package manager detects a package update is availible and isn't installed. | ||
|
@@ -88,12 +70,10 @@ RUN yum --disablerepo="temurin-jdk" check-update || "${SKIP_SECURITY_UPDATE_CHEC | |
COPY --chown=appuser:appuser target/${ARTIFACT_ID}-${PROJECT_VERSION}-package/share/doc/* /usr/share/doc/${ARTIFACT_ID}/ | ||
COPY --chown=appuser:appuser target/${ARTIFACT_ID}-${PROJECT_VERSION}-package/share/java/${ARTIFACT_ID}/* /usr/share/java/${ARTIFACT_ID}/ | ||
|
||
COPY --chown=appuser:appuser include/etc/confluent/docker /etc/confluent/docker | ||
COPY --chown=appuser:appuser include/etc/cp-base-lite /etc/cp-base-lite | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please make this directory a symlink to |
||
COPY --from=build-ub /build/ub /usr/bin | ||
|
||
RUN mkdir /licenses | ||
COPY license.txt /licenses | ||
|
||
USER appuser | ||
WORKDIR /home/appuser | ||
WORKDIR /home/appuser |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please include files under
include
directory