Commit d4dfb2a7 authored by Raphael Defosseux's avatar Raphael Defosseux Committed by KARIM

feat(ci): flatten image to one layer to reduce image to the max

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@openairinterface.org>
parent 0821d193
...@@ -36,7 +36,8 @@ RUN cp -Rf /openair-smf-ext-ref /openair-smf/build/ext ...@@ -36,7 +36,8 @@ RUN cp -Rf /openair-smf-ext-ref /openair-smf/build/ext
# Building SMF # Building SMF
WORKDIR /openair-smf/build/scripts WORKDIR /openair-smf/build/scripts
RUN ./build_smf --clean --Verbose --build-type Release --jobs && \ RUN ldconfig && \
./build_smf --clean --Verbose --build-type Release --jobs && \
ldd /openair-smf/build/smf/build/smf && \ ldd /openair-smf/build/smf/build/smf && \
mv /openair-smf/build/smf/build/smf /openair-smf/build/smf/build/oai_smf mv /openair-smf/build/smf/build/smf /openair-smf/build/smf/build/oai_smf
...@@ -54,10 +55,10 @@ RUN apt-get update && \ ...@@ -54,10 +55,10 @@ RUN apt-get update && \
net-tools \ net-tools \
tzdata \ tzdata \
bc \ bc \
tshark \
perl \ perl \
openssl \ openssl \
libasan4 \ libasan4 \
libgssapi-krb5-2 \
libldap-2.4-2 \ libldap-2.4-2 \
libgoogle-glog0v5 \ libgoogle-glog0v5 \
libdouble-conversion1 \ libdouble-conversion1 \
...@@ -74,6 +75,7 @@ COPY --from=oai-smf-builder \ ...@@ -74,6 +75,7 @@ COPY --from=oai-smf-builder \
WORKDIR /usr/local/lib/ WORKDIR /usr/local/lib/
COPY --from=oai-smf-builder \ COPY --from=oai-smf-builder \
/usr/local/lib/libpistache.so \ /usr/local/lib/libpistache.so \
/usr/local/lib/libnghttp2.so.14 \
/usr/local/lib/libnghttp2_asio.so.1 \ /usr/local/lib/libnghttp2_asio.so.1 \
/usr/lib/libboost_system.so.1.67.0 \ /usr/lib/libboost_system.so.1.67.0 \
/usr/lib/libboost_thread.so.1.67.0 \ /usr/lib/libboost_thread.so.1.67.0 \
......
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
""" """
import argparse import argparse
import re
import subprocess
import sys import sys
def main() -> None: def main() -> None:
args = _parse_args() args = _parse_args()
print (f'Does nothing for the moment on {args.tag}') status = perform_flattening(args.tag)
sys.exit(0) sys.exit(status)
def _parse_args() -> argparse.Namespace: def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Flattening Image') parser = argparse.ArgumentParser(description='Flattening Image')
...@@ -38,5 +40,55 @@ def _parse_args() -> argparse.Namespace: ...@@ -38,5 +40,55 @@ def _parse_args() -> argparse.Namespace:
) )
return parser.parse_args() 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-smf" '
cmd += ' --change "EXPOSE 80/tcp" '
cmd += ' --change "EXPOSE 8080/tcp" '
cmd += ' --change "EXPOSE 8805/udp" '
cmd += ' --change "CMD [\\"/openair-smf/bin/oai_smf\\", \\"-c\\", \\"/openair-smf/etc/smf.conf\\", \\"-o\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-smf/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__': if __name__ == '__main__':
main() main()
...@@ -853,7 +853,7 @@ class HtmlReport(): ...@@ -853,7 +853,7 @@ class HtmlReport():
result = re.search('oai-smf *ci-tmp', line) result = re.search('oai-smf *ci-tmp', line)
else: else:
result = re.search('oai-smf *develop', line) result = re.search('oai-smf *develop', line)
if result is not None: if result is not None and not status:
result = re.search('ago *([0-9A-Z ]+)', line) result = re.search('ago *([0-9A-Z ]+)', line)
if result is not None: if result is not None:
size = result.group(1) size = result.group(1)
......
...@@ -80,7 +80,8 @@ RUN yum update -y && \ ...@@ -80,7 +80,8 @@ RUN yum update -y && \
procps-ng \ procps-ng \
net-tools \ net-tools \
libevent && \ libevent && \
rm -rf /var/lib/apt/lists/* yum clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf
# Copying executable and generated libraries # Copying executable and generated libraries
WORKDIR /openair-smf/bin WORKDIR /openair-smf/bin
......
...@@ -73,10 +73,10 @@ RUN apt-get update && \ ...@@ -73,10 +73,10 @@ RUN apt-get update && \
net-tools \ net-tools \
tzdata \ tzdata \
bc \ bc \
tshark \
perl \ perl \
openssl \ openssl \
libasan4 \ libasan4 \
libgssapi-krb5-2 \
libldap-2.4-2 \ libldap-2.4-2 \
libgoogle-glog0v5 \ libgoogle-glog0v5 \
libdouble-conversion1 \ libdouble-conversion1 \
...@@ -93,6 +93,7 @@ COPY --from=oai-smf-builder \ ...@@ -93,6 +93,7 @@ COPY --from=oai-smf-builder \
WORKDIR /usr/local/lib/ WORKDIR /usr/local/lib/
COPY --from=oai-smf-builder \ COPY --from=oai-smf-builder \
/usr/local/lib/libpistache.so \ /usr/local/lib/libpistache.so \
/usr/local/lib/libnghttp2.so.14 \
/usr/local/lib/libnghttp2_asio.so.1 \ /usr/local/lib/libnghttp2_asio.so.1 \
/usr/lib/libboost_system.so.1.67.0 \ /usr/lib/libboost_system.so.1.67.0 \
/usr/lib/libboost_thread.so.1.67.0 \ /usr/lib/libboost_thread.so.1.67.0 \
......
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