Skip to content

Commit fb8ed75

Browse files
authored
Update Dockerfile to build and install expat 2.7.2 from source (#3972)
* libexpat installation on docker image build * carrying over the binary in final stage * removed the dead code * ordered correct * undoed the bin sh * undoed the bin sh * debugs * finds * ls * found * apps * env * bigipconfigdriver * found driver * refactor * refactor again * python ln * main drafted * main drafted fix * Cleanedup * libexpat removed * rpm based * env * repopath * ls * debugs * full debug * full debug * added spec * expat remove * cis binary path * Refactored with removing unnecessary binary copies
1 parent 5abc943 commit fb8ed75

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

build-tools/Dockerfile.ubi

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Stage 1: Build Go binary
12
FROM golang:1.23 as builder
23

34
ARG REPOPATH=$GOPATH/src/github.com/F5Networks/k8s-bigip-ctlr
@@ -8,15 +9,27 @@ ARG BUILD_INFO
89

910
WORKDIR $REPOPATH
1011
ENV GO111MODULE on
12+
1113
COPY . .
1214

1315
RUN $REPOPATH/build-tools/rel-build.sh
1416

17+
# Stage 2: Build expat RPM (not from source!)
18+
FROM registry.redhat.io/ubi9/ubi-minimal AS build-expat-rpm
19+
20+
RUN microdnf install -y rpm-build gcc gcc-c++ make tar bzip2 python3 shadow-utils autoconf libtool && microdnf clean all
21+
WORKDIR /root
22+
RUN mkdir -p /root/rpmbuild/{SOURCES,SPECS,BUILD,BUILDROOT,RPMS,SRPMS}
23+
COPY build-tools/expat.spec /root/rpmbuild/SPECS/expat.spec
24+
RUN curl -L -o /root/rpmbuild/SOURCES/expat-2.7.2.tar.gz https://github.com/libexpat/libexpat/releases/download/R_2_7_2/expat-2.7.2.tar.gz
25+
WORKDIR /root/rpmbuild
26+
RUN rpmbuild -ba SPECS/expat.spec
27+
28+
# Stage 3: Final runtime image
1529
FROM registry.redhat.io/ubi9/ubi-minimal
1630

1731
LABEL name="f5networks/k8s-bigip-ctlr" \
1832
vendor="F5 Networks" \
19-
# version - should be passed in via docker build
2033
url="https://clouddocs.f5.com/containers/latest/" \
2134
summary="F5 BIG-IP Controller for Kubernetes" \
2235
description="Manages F5 BIG-IP from Kubernetes" \
@@ -27,17 +40,22 @@ LABEL name="f5networks/k8s-bigip-ctlr" \
2740
io.openshift.tags="f5,f5networks,bigip,openshift,router"
2841

2942
ENV APPPATH /app
30-
3143
ARG BUILD_VERSION
3244
ARG BUILD_INFO
33-
3445
WORKDIR $APPPATH
3546

47+
# Install expat 2.7.2 RPM first!
48+
COPY --from=build-expat-rpm /root/rpmbuild/RPMS/x86_64/expat-2.7.2-*.rpm /tmp/
49+
RUN microdnf remove expat -y || true && \
50+
rpm -Uvh /tmp/expat-2.7.2-*.rpm && \
51+
microdnf clean all
52+
3653
COPY requirements.txt /tmp/requirements.txt
3754

3855
RUN mkdir -p "$APPPATH/bin" "$APPPATH/vendor/src/f5/schemas/" \
3956
&& touch $APPPATH/vendor/src/f5/VERSION_BUILD.json
4057

58+
# Install runtime dependencies
4159
RUN microdnf update -y && \
4260
microdnf --enablerepo=ubi-9-baseos-rpms install --nodocs python39 python3-pip git shadow-utils -y && \
4361
microdnf --enablerepo=ubi-9-baseos-rpms --enablerepo=ubi-9-appstream-rpms update nss-tools nss-softokn nss-util scl-utils -y && \
@@ -49,10 +67,12 @@ RUN microdnf update -y && \
4967
microdnf remove perl-Error perl-File-Find perl-lib libedit openssh openssh-clients perl-TermReadKey git-core git-core-doc less shadow-utils pip git-core-doc cracklib cracklib-dicts emacs-filesystem git-core-doc git-core groff-base gzip less libcbor libdb libeconf libedit libfdisk util-linux util-linux-core libfido2 libpwquality libsemanage libutempter ncurses openssh openssh-clients openssh-8.7p1 pam perl-Digest perl-Digest-MD5 perl-FileHandle perl-B perl-Data-Dumper perl-libnet perl-base perl-AutoLoader perl-URI perl-Mozilla-CA perl-if perl-IO-Socket-IP perl-Time-Local perl-File-Path perl-Pod-Escapes perl-Text-Tabs+Wrap perl-Net-SSLeay perl-IO-Socket-SSL perl-Class-Struct perl-POSIX perl-Term-ANSIColor perl-IPC-Open3 perl-subs perl-File-Temp perl-Term-Cap perl-HTTP-Tiny perl-Pod-Simple perl-Socket perl-SelectSaver perl-Symbol perl-File-stat perl-podlators perl-Pod-Perldoc perl-Fcntl perl-Text-ParseWords perl-mro perl-IO perl-overloading perl-Pod-Usage perl-Errno perl-File-Basename perl-Getopt-Std perl-MIME-Base64 perl-Scalar-List-Utils perl-constant perl-Storable perl-overload perl-parent perl-vars perl-Getopt-Long perl-Carp perl-Exporter perl-NDBM_File perl-PathTools perl-Encode perl-libs perl-interpreter perl-DynaLoader -y && \
5068
microdnf clean all && echo "{\"version\": \"${BUILD_VERSION}\", \"build\": \"${BUILD_INFO}\"}" > $APPPATH/vendor/src/f5/VERSION_BUILD.json && chown -R ctlr "$APPPATH" && chmod -R 755 "$APPPATH"
5169

52-
# Remove shell access
70+
# Remove shell access for security
5371
RUN rm -f /bin/sh /bin/bash
5472

73+
# Switch to non-root user
5574
USER ctlr
75+
5676
COPY schemas/*.json $APPPATH/vendor/src/f5/schemas/
5777
COPY LICENSE /licenses/
5878

build-tools/expat.spec

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
%global unversion 2_7_2
2+
3+
Summary: An XML parser library
4+
Name: expat
5+
Version: %(echo %{unversion} | sed 's/_/./g')
6+
Release: 1%{?dist}
7+
Source0: https://github.com/libexpat/libexpat/releases/download/R_%{unversion}/expat-%{version}.tar.gz
8+
9+
URL: https://libexpat.github.io/
10+
License: MIT
11+
BuildRequires: autoconf, libtool, gcc-c++
12+
BuildRequires: make
13+
14+
%description
15+
This is expat, the C library for parsing XML, written by James Clark. Expat
16+
is a stream oriented XML parser. This means that you register handlers with
17+
the parser prior to starting the parse. These handlers are called when the
18+
parser discovers the associated structures in the document being parsed. A
19+
start tag is an example of the kind of structures for which you may
20+
register handlers.
21+
22+
%package devel
23+
Summary: Libraries and header files to develop applications using expat
24+
Requires: expat%{?_isa} = %{version}-%{release}
25+
26+
%description devel
27+
The expat-devel package contains the libraries, include files and documentation
28+
to develop XML applications with expat.
29+
30+
%package static
31+
Summary: expat XML parser static library
32+
Requires: expat-devel%{?_isa} = %{version}-%{release}
33+
34+
%description static
35+
The expat-static package contains the static version of the expat library.
36+
Install it if you need to link statically with expat.
37+
38+
%prep
39+
%autosetup
40+
sed -i 's/install-data-hook/do-nothing-please/' lib/Makefile.am
41+
./buildconf.sh
42+
43+
%build
44+
export CFLAGS="$RPM_OPT_FLAGS -fPIC"
45+
export DOCBOOK_TO_MAN="xmlto man --skip-validation"
46+
%configure
47+
%make_build
48+
49+
%install
50+
%make_install
51+
52+
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
53+
54+
%check
55+
make check
56+
57+
%ldconfig_scriptlets
58+
59+
%files
60+
%doc AUTHORS Changes
61+
%license COPYING
62+
%{_bindir}/*
63+
%{_libdir}/libexpat.so.1
64+
%{_libdir}/libexpat.so.1.*
65+
%{_mandir}/*/*
66+
67+
%files devel
68+
%doc doc/reference.html doc/*.css examples/*.c
69+
%{_libdir}/libexpat.so
70+
%{_libdir}/pkgconfig/*.pc
71+
%{_includedir}/*.h
72+
%{_libdir}/cmake/expat-%{version}
73+
74+
%files static
75+
%{_libdir}/libexpat.a
76+
77+
%changelog
78+
* Mon Oct 06 2025 Your Name <your.email@domain.com> - 2.7.2-1
79+
- Initial build for UBI9/RHEL9/CentOS9

0 commit comments

Comments
 (0)