Skip to content

Commit

Permalink
Move RPM copying into a separate image
Browse files Browse the repository at this point in the history
This allows the RUN command that need then to mount that image, without
actually including the RPM artifacts in the final image itself.
  • Loading branch information
Fryguy committed Mar 13, 2024
1 parent 4577e12 commit 5d552e8
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gemfile.lock
build.log
images/manageiq-base-worker/container-assets/VMware-*
images/manageiq-base/rpms
images/manageiq-rpms/rpms
manageiq-operator/build/_output/*
manageiq-operator/vendor/*
tools/certs/*.crt
Expand Down
31 changes: 14 additions & 17 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@ RPM_BUILD_OPTIONS=${RPM_BUILD_OPTIONS:-""}
RPM_BUILD_IMAGE=${RPM_BUILD_IMAGE:-"manageiq/rpm_build:$TAG"}
RPM_PREFIX=${RPM_PREFIX:-"manageiq"}

while getopts "t:c:d:r:hblnops" opt; do
while getopts "t:c:d:r:hbnops" opt; do
case $opt in
b) REBUILD_RPM="true" ;;
c) CONTAINER_PREFIX=$OPTARG ;;
d) BASE_DIR=$OPTARG ;;
l) LOCAL_RPM="true" ;;
n) NO_CACHE="true" ;;
o) NO_OPERATOR="true" ;;
p) PUSH="true" ;;
r) REPO=$OPTARG ;;
s) RELEASE_BUILD="true" ;;
t) TAG=$OPTARG ;;
h) echo "Usage: $0 [-hblnops] [-c CONTAINER_PREFIX] [-d BASE_DIR] [-r IMAGE_REPOSITORY] [-t IMAGE_TAG]"; exit 1
h) echo "Usage: $0 [-hbnops] [-c CONTAINER_PREFIX] [-d BASE_DIR] [-r IMAGE_REPOSITORY] [-t IMAGE_TAG]"; exit 1
esac
done

if [ -n "$LOCAL_RPM" ] && [ -n "$REBUILD_RPM" ]; then
echo "Local rpm (-l) and rebuild rpm (-b) options can't be used together"
exit 1
fi

BASE_DIR=${BASE_DIR:-$PWD}
CONTAINER_PREFIX=${CONTAINER_PREFIX:-manageiq}
IMAGE_DIR="$BASE_DIR/images"
Expand All @@ -38,7 +32,7 @@ CONTAINER_COMMAND="$(which podman &>/dev/null && echo "podman" || echo "docker")
set -e

if [ -n "$REBUILD_RPM" ]; then
rpm_dir=$IMAGE_DIR/manageiq-base/rpms
rpm_dir=$IMAGE_DIR/manageiq-rpms/rpms
rm -rf $rpm_dir/*
options="-v $PWD/$rpm_dir:/root/BUILD/rpms"
if [ -n "$RPM_BUILD_OPTIONS" ]; then
Expand All @@ -52,7 +46,10 @@ if [ -n "$REBUILD_RPM" ]; then
fi

pushd $IMAGE_DIR
build_images="manageiq-base manageiq-base-worker manageiq-orchestrator manageiq-webserver-worker manageiq-ui-worker"
# Pull the base image first
$CONTAINER_COMMAND pull registry.access.redhat.com/ubi9/ubi

build_images="manageiq-rpms manageiq-base manageiq-base-worker manageiq-orchestrator manageiq-webserver-worker manageiq-ui-worker"
for image in $build_images; do
cmd="$CONTAINER_COMMAND build --tag $REPO/$image:$TAG"

Expand All @@ -69,17 +66,16 @@ pushd $IMAGE_DIR
cmd+=" --no-cache"
fi

if [ "$image" == "manageiq-base" ]; then
cmd+=" --pull \
--build-arg RPM_PREFIX=$RPM_PREFIX"
if [ "$image" == "manageiq-rpms" ]; then
true # No change
elif [ "$image" == "manageiq-base" ]; then
cmd+=" --build-arg RPM_PREFIX=$RPM_PREFIX"

if [ -n "$RELEASE_BUILD" ]; then
cmd+=" --build-arg RELEASE_BUILD=true"
fi
else
cmd+=" --build-arg FROM_REPO=$REPO \
--build-arg FROM_TAG=$TAG \
--build-arg RPM_PREFIX=$RPM_PREFIX"
cmd+=" --build-arg FROM_REPO=$REPO --build-arg FROM_TAG=$TAG --build-arg RPM_PREFIX=$RPM_PREFIX"
fi

cmd+=" $image"
Expand All @@ -106,11 +102,12 @@ if [ -n "$PUSH" ]; then
for image in $push_images; do
cmd="$CONTAINER_COMMAND push $REPO/$image:$TAG"

# --format docker is needed for podman to ensure the builds are built with docker v2 manifests
if [ "$CONTAINER_COMMAND" == "podman" ]; then
cmd+=" --format docker"
fi

echo "Pushing: $cmd"
echo "Pushing $image: $cmd"
$cmd
done
fi
9 changes: 4 additions & 5 deletions images/manageiq-base/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
FROM registry.access.redhat.com/ubi9/ubi
MAINTAINER ManageIQ https://manageiq.org

ARG LOCAL_RPM
ARG RELEASE_BUILD
ARG RPM_PREFIX=manageiq

Expand Down Expand Up @@ -29,11 +28,11 @@ RUN ARCH=$(uname -m) && \
curl -L -o /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.2/dumb-init_1.2.2_${ARCH} && \
chmod +x /usr/bin/dumb-init

COPY rpms/* /tmp/rpms/
COPY container-assets/create_local_yum_repo.sh /
COPY container-assets/prepare_local_yum_repo.sh /usr/local/bin
COPY container-assets/clean_dnf_rpm /usr/local/bin/

RUN ARCH=$(uname -m) && \
RUN --mount=type=bind,from=docker.io/manageiq/manageiq-rpms,source=/tmp/rpms,target=/tmp/rpms \
ARCH=$(uname -m) && \
dnf config-manager --setopt=tsflags=nodocs --setopt=install_weak_deps=False --save && \
dnf -y --setopt=protected_packages= remove redhat-release && \
dnf -y remove *subscription-manager* && \
Expand All @@ -46,7 +45,7 @@ RUN ARCH=$(uname -m) && \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm \
https://rpm.manageiq.org/release/19-spassky/el9/noarch/manageiq-release-19.0-1.el9.noarch.rpm && \
if [[ "$RELEASE_BUILD" != "true" ]]; then dnf config-manager --enable manageiq-19-spassky-nightly; fi && \
if [[ "$LOCAL_RPM" = "true" ]]; then /create_local_yum_repo.sh; fi && \
if [[ -n "$(ls /tmp/rpms)" ]]; then /usr/local/bin/prepare_local_yum_repo.sh; fi && \
dnf -y module enable ruby:3.1 && \
dnf -y install \
httpd \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#!/bin/bash

yum -y install createrepo_c
rm -rf /tmp/rpms/repodata
createrepo /tmp/rpms
yum -y remove createrepo_c

ls -al /tmp/rpms
set -e

cat > /etc/yum.repos.d/local_rpm.repo << EOF
[local-rpm]
Expand Down
Empty file removed images/manageiq-base/rpms/.gitkeep
Empty file.
21 changes: 21 additions & 0 deletions images/manageiq-rpms/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM registry.access.redhat.com/ubi9/ubi

COPY rpms/* /tmp/rpms/
RUN rm -f /tmp/rpms/.gitkeep

RUN if [[ -n "$(ls /tmp/rpms)" ]]; then \
ARCH=$(uname -m) && \
dnf config-manager --setopt=tsflags=nodocs --setopt=install_weak_deps=False --save && \
dnf -y --setopt=protected_packages= remove redhat-release && \
dnf -y remove *subscription-manager* && \
dnf -y install \
http://mirror.stream.centos.org/9-stream/BaseOS/${ARCH}/os/Packages/centos-stream-release-9.0-24.el9.noarch.rpm \
http://mirror.stream.centos.org/9-stream/BaseOS/${ARCH}/os/Packages/centos-stream-repos-9.0-24.el9.noarch.rpm \
http://mirror.stream.centos.org/9-stream/BaseOS/${ARCH}/os/Packages/centos-gpg-keys-9.0-24.el9.noarch.rpm ; \
fi

RUN if [[ -n "$(ls /tmp/rpms)" ]]; then \
yum -y install createrepo_c && \
rm -rf /tmp/rpms/repodata && \
createrepo /tmp/rpms; \
fi
3 changes: 2 additions & 1 deletion images/manageiq-webserver-worker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ LABEL name="manageiq-webserver-worker" \

COPY container-assets/service-worker-entrypoint /usr/local/bin

RUN dnf -y install \
RUN --mount=type=bind,from=docker.io/manageiq/manageiq-rpms,source=/tmp/rpms,target=/tmp/rpms \
dnf -y install \
${RPM_PREFIX}-ui && \
clean_dnf_rpm && \
# Remove httpd default settings
Expand Down
1 change: 1 addition & 0 deletions manageiq-operator/config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: manageiq-operator
namespace: changeme
rules:
- apiGroups:
- ""
Expand Down

0 comments on commit 5d552e8

Please sign in to comment.