Commit 01421108 authored by Raphael Defosseux's avatar Raphael Defosseux

Merge branch 'try-flattening-image' into 'develop'

CI: flatten image to one layer to reduce image to the max

See merge request oai/cn5g/oai-cn5g-amf!106
parents d9a0f627 5078a22b
......@@ -37,7 +37,9 @@ RUN cp -Rf /openair-amf-ext-ref /openair-amf/build/ext
# Building AMF
WORKDIR /openair-amf/build/scripts
RUN ./build_amf --clean --Verbose --build-type Release --jobs && \
RUN ldconfig && \
./build_amf --clean --Verbose --build-type Release --jobs && \
ldd /openair-amf/build/amf/build/amf && \
mv /openair-amf/build/amf/build/amf /openair-amf/build/amf/build/oai_amf
#---------------------------------------------------------------------
......@@ -56,8 +58,8 @@ RUN apt-get update && \
bc \
openssl \
perl \
tshark \
libasan4 \
libgssapi-krb5-2 \
libldap-2.4-2 \
libconfig++9v5 \
libsctp1 \
......@@ -81,6 +83,7 @@ COPY --from=oai-amf-builder \
WORKDIR /usr/local/lib
COPY --from=oai-amf-builder \
/usr/local/lib/libnghttp2.so.14 \
/usr/local/lib/libnghttp2_asio.so.1 \
/usr/lib/libboost_system.so.1.67.0 \
/usr/lib/libboost_thread.so.1.67.0 \
......@@ -88,7 +91,8 @@ COPY --from=oai-amf-builder \
/usr/local/lib/libpistache.so \
./
RUN ldconfig
RUN ldconfig && \
ldd /openair-amf/bin/oai_amf
# Copying template configuration files
WORKDIR /openair-amf/etc
......
......@@ -20,12 +20,14 @@
"""
import argparse
import re
import subprocess
import sys
def main() -> None:
args = _parse_args()
print (f'Does nothing for the moment on {args.tag}')
sys.exit(0)
status = perform_flattening(args.tag)
sys.exit(status)
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Flattening Image')
......@@ -38,5 +40,56 @@ def _parse_args() -> argparse.Namespace:
)
return parser.parse_args()
def perform_flattening(tag):
# First detect which docker/podman command to use
cli = ''
image_prefix = ''
cmd = 'which podman || true'
podman_check = subprocess.check_output(cmd, shell=True, universal_newlines=True)
if re.search('podman', podman_check.strip()):
cli = 'sudo podman'
image_prefix = 'localhost/'
if cli == '':
cmd = 'which docker || true'
docker_check = subprocess.check_output(cmd, shell=True, universal_newlines=True)
if re.search('docker', docker_check.strip()):
cli = 'docker'
image_prefix = ''
if cli == '':
print ('No docker / podman installed: quitting')
return -1
print (f'Flattening {tag}')
# Creating a container
cmd = cli + ' run --name test-flatten --entrypoint /bin/true -d ' + tag
print (cmd)
subprocess.check_output(cmd, shell=True, universal_newlines=True)
# Export / Import trick
cmd = cli + ' export test-flatten | ' + cli + ' import '
# Bizarro syntax issue with podman
if cli == 'docker':
cmd += ' --change "ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" '
else:
cmd += ' --change "ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" '
cmd += ' --change "WORKDIR /openair-amf" '
cmd += ' --change "EXPOSE 80/tcp" '
cmd += ' --change "EXPOSE 9090/tcp" '
if cli == 'docker':
cmd += ' --change "EXPOSE 38412/sctp" '
cmd += ' --change "CMD [\\"/openair-amf/bin/oai_amf\\", \\"-c\\", \\"/openair-amf/etc/amf.conf\\", \\"-o\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-amf/bin/entrypoint.sh\\"]" '
cmd += ' - ' + image_prefix + tag
print (cmd)
subprocess.check_output(cmd, shell=True, universal_newlines=True)
# Remove container
cmd = cli + ' rm -f test-flatten'
print (cmd)
subprocess.check_output(cmd, shell=True, universal_newlines=True)
# At this point the original image is a dangling image.
# CI pipeline will clean up (`image prune --force`)
return 0
if __name__ == '__main__':
main()
......@@ -603,7 +603,7 @@ class HtmlReport():
status = False
if nfType == 'AMF':
section_start_pattern = 'build_amf --clean --Verbose --build-type Release --jobs'
section_end_pattern = 'FROM ubuntu:bionic as oai-amf$'
section_end_pattern = 'FROM .* as oai-amf$'
pass_pattern = 'amf installed'
section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile:
......@@ -653,7 +653,7 @@ class HtmlReport():
if os.path.isfile(cwd + '/archives/' + logFileName):
if nfType == 'AMF':
section_start_pattern = 'build_amf --clean --Verbose --build-type Release --jobs'
section_end_pattern = 'FROM ubuntu:bionic as oai-amf$'
section_end_pattern = 'FROM .* as oai-amf$'
section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile:
for line in logfile:
......@@ -723,7 +723,7 @@ class HtmlReport():
for variant in variants:
logFileName = 'amf_' + variant + '_image_build.log'
if os.path.isfile(cwd + '/archives/' + logFileName):
section_start_pattern = 'FROM ubuntu:bionic as oai-amf$'
section_start_pattern = 'FROM .* as oai-amf$'
section_end_pattern = 'WORKDIR /openair-amf/etc'
section_status = False
status = False
......@@ -843,7 +843,7 @@ class HtmlReport():
result = re.search('oai-amf *ci-tmp', line)
else:
result = re.search('oai-amf *develop', line)
if result is not None:
if result is not None and not status:
result = re.search('ago *([0-9A-Z ]+)', line)
if result is not None:
size = result.group(1)
......
......@@ -59,8 +59,8 @@ RUN rm -f /etc/rhsm-host && \
echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local-lib.conf
# Some GIT configuration command quite useful
RUN /bin/bash -c "if [[ -v NEEDED_GIT_PROXY ]]; then git config --global http.proxy $NEEDED_GIT_PROXY; fi" && \
git config --global https.postBuffer 123289600 && \
RUN /bin/bash -c "if [[ -v NEEDED_GIT_PROXY ]]; then git config --global http.proxy $NEEDED_GIT_PROXY; fi"
RUN git config --global https.postBuffer 123289600 && \
git config --global http.sslverify false
# Copying source code
......@@ -73,7 +73,9 @@ RUN ./build_amf --install-deps --force
# Building AMF
WORKDIR /openair-amf/build/scripts
RUN ./build_amf --clean --Verbose --build-type Release --jobs && \
RUN ldconfig && \
./build_amf --clean --Verbose --build-type Release --jobs && \
ldd /openair-amf/build/amf/build/amf && \
mv /openair-amf/build/amf/build/amf /openair-amf/build/amf/build/oai_amf
#---------------------------------------------------------------------
......@@ -90,7 +92,8 @@ RUN yum update -y && \
psmisc \
net-tools \
libevent && \
rm -rf /var/lib/apt/lists/*
yum clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf
# Copying executable and generated libraries
WORKDIR /openair-amf/bin
......@@ -120,7 +123,8 @@ COPY --from=oai-amf-builder \
/usr/lib64/libicuuc.so.60 \
/usr/lib64/
RUN ldconfig
RUN ldconfig && \
ldd /openair-amf/bin/oai_amf
# Copying template configuration files
WORKDIR /openair-amf/etc
......
......@@ -44,8 +44,8 @@ RUN apt-get update && \
&& rm -rf /var/lib/apt/lists/*
# Some GIT configuration commands quite useful
RUN /bin/bash -c "if [[ -v NEEDED_GIT_PROXY ]]; then git config --global http.proxy $NEEDED_GIT_PROXY; fi" && \
git config --global https.postBuffer 123289600 && \
RUN /bin/bash -c "if [[ -v NEEDED_GIT_PROXY ]]; then git config --global http.proxy $NEEDED_GIT_PROXY; fi"
RUN git config --global https.postBuffer 123289600 && \
git config --global http.sslverify false
# Copying source code
......@@ -58,7 +58,9 @@ RUN ./build_amf --install-deps --force
# Building AMF
WORKDIR /openair-amf/build/scripts
RUN ./build_amf --clean --Verbose --build-type Release --jobs && \
RUN ldconfig && \
./build_amf --clean --Verbose --build-type Release --jobs && \
ldd /openair-amf/build/amf/build/amf && \
mv /openair-amf/build/amf/build/amf /openair-amf/build/amf/build/oai_amf
#---------------------------------------------------------------------
......@@ -77,8 +79,8 @@ RUN apt-get update && \
bc \
openssl \
perl \
tshark \
libasan4 \
libgssapi-krb5-2 \
libldap-2.4-2 \
libconfig++9v5 \
libsctp1 \
......@@ -102,6 +104,7 @@ COPY --from=oai-amf-builder \
WORKDIR /usr/local/lib
COPY --from=oai-amf-builder \
/usr/local/lib/libnghttp2.so.14 \
/usr/local/lib/libnghttp2_asio.so.1 \
/usr/lib/libboost_system.so.1.67.0 \
/usr/lib/libboost_thread.so.1.67.0 \
......@@ -109,7 +112,8 @@ COPY --from=oai-amf-builder \
/usr/local/lib/libpistache.so \
./
RUN ldconfig
RUN ldconfig && \
ldd /openair-amf/bin/oai_amf
# Copying template configuration files
WORKDIR /openair-amf/etc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment