Commit db536b84 authored by Raphael Defosseux's avatar Raphael Defosseux

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

Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent e6e88e21
...@@ -36,7 +36,9 @@ RUN cp -Rf /openair-ausf-ext-ref /openair-ausf/build/ext ...@@ -36,7 +36,9 @@ RUN cp -Rf /openair-ausf-ext-ref /openair-ausf/build/ext
# Building AUSF # Building AUSF
WORKDIR /openair-ausf/build/scripts WORKDIR /openair-ausf/build/scripts
RUN ./build_ausf --clean --Verbose --build-type Release --jobs && \ RUN ldconfig && \
./build_ausf --clean --Verbose --build-type Release --jobs && \
ldd /openair-ausf/build/ausf/build/ausf && \
mv /openair-ausf/build/ausf/build/ausf /openair-ausf/build/ausf/build/oai_ausf mv /openair-ausf/build/ausf/build/ausf /openair-ausf/build/ausf/build/oai_ausf
#--------------------------------------------------------------------- #---------------------------------------------------------------------
...@@ -53,13 +55,13 @@ RUN apt-get update && \ ...@@ -53,13 +55,13 @@ RUN apt-get update && \
net-tools \ net-tools \
tzdata \ tzdata \
bc \ bc \
tshark \
perl \ perl \
libasan4 \ libasan4 \
libnettle6 \ libnettle6 \
libnghttp2-14 \ libnghttp2-14 \
libhogweed4 \ libhogweed4 \
libldap-2.4-2 \ libldap-2.4-2 \
libgssapi-krb5-2 \
librtmp1 \ librtmp1 \
libpsl5 \ libpsl5 \
libconfig++9v5 \ libconfig++9v5 \
...@@ -79,7 +81,8 @@ COPY --from=oai-ausf-builder \ ...@@ -79,7 +81,8 @@ COPY --from=oai-ausf-builder \
/usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \ /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \
/usr/local/lib/ /usr/local/lib/
RUN ldconfig RUN ldconfig && \
ldd /openair-ausf/bin/oai_ausf
WORKDIR /openair-ausf/etc WORKDIR /openair-ausf/etc
COPY --from=oai-ausf-builder /openair-ausf/etc/ausf.conf . COPY --from=oai-ausf-builder /openair-ausf/etc/ausf.conf .
......
...@@ -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,53 @@ def _parse_args() -> argparse.Namespace: ...@@ -38,5 +40,53 @@ 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-ausf" '
cmd += ' --change "EXPOSE 80/tcp" '
cmd += ' --change "CMD [\\"/openair-ausf/bin/oai_ausf\\", \\"-c\\", \\"/openair-ausf/etc/ausf.conf\\", \\"-o\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-ausf/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()
...@@ -808,7 +808,7 @@ class HtmlReport(): ...@@ -808,7 +808,7 @@ class HtmlReport():
result = re.search('oai-ausf *ci-tmp', line) result = re.search('oai-ausf *ci-tmp', line)
else: else:
result = re.search('oai-ausf *develop', line) result = re.search('oai-ausf *develop', line)
if result is not None: if result is not None and not status:
if variant == 'docker': if variant == 'docker':
result = re.search('ago *([0-9A-Z]+)', line) result = re.search('ago *([0-9A-Z]+)', line)
else: else:
......
...@@ -90,7 +90,7 @@ RUN yum update -y && \ ...@@ -90,7 +90,7 @@ RUN yum update -y && \
liblsan \ liblsan \
libevent && \ libevent && \
yum clean all -y && \ yum clean all -y && \
rm -rf /var/cache/yum && \ rm -rf /var/cache/yum /var/cache/dnf && \
echo "/usr/local/lib" > /etc/ld.so.conf.d/local-lib.conf && \ echo "/usr/local/lib" > /etc/ld.so.conf.d/local-lib.conf && \
echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local-lib.conf echo "/usr/local/lib64" >> /etc/ld.so.conf.d/local-lib.conf
......
...@@ -55,6 +55,7 @@ COPY . /openair-ausf ...@@ -55,6 +55,7 @@ COPY . /openair-ausf
WORKDIR /openair-ausf/build/scripts WORKDIR /openair-ausf/build/scripts
RUN ./build_ausf --install-deps --force RUN ./build_ausf --install-deps --force
RUN ./build_ausf --clean --Verbose --build-type Release --jobs && \ RUN ./build_ausf --clean --Verbose --build-type Release --jobs && \
ldd /openair-ausf/build/ausf/build/ausf && \
mv /openair-ausf/build/ausf/build/ausf /openair-ausf/build/ausf/build/oai_ausf mv /openair-ausf/build/ausf/build/ausf /openair-ausf/build/ausf/build/oai_ausf
#--------------------------------------------------------------------- #---------------------------------------------------------------------
...@@ -71,13 +72,13 @@ RUN apt-get update && \ ...@@ -71,13 +72,13 @@ RUN apt-get update && \
net-tools \ net-tools \
tzdata \ tzdata \
bc \ bc \
tshark \
perl \ perl \
libasan4 \ libasan4 \
libnettle6 \ libnettle6 \
libnghttp2-14 \ libnghttp2-14 \
libhogweed4 \ libhogweed4 \
libldap-2.4-2 \ libldap-2.4-2 \
libgssapi-krb5-2 \
librtmp1 \ librtmp1 \
libpsl5 \ libpsl5 \
libconfig++9v5 \ libconfig++9v5 \
...@@ -97,7 +98,8 @@ COPY --from=oai-ausf-builder \ ...@@ -97,7 +98,8 @@ COPY --from=oai-ausf-builder \
/usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \ /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \
/usr/local/lib/ /usr/local/lib/
RUN ldconfig RUN ldconfig && \
ldd /openair-ausf/bin/oai_ausf
WORKDIR /openair-ausf/etc WORKDIR /openair-ausf/etc
COPY --from=oai-ausf-builder /openair-ausf/etc/ausf.conf . COPY --from=oai-ausf-builder /openair-ausf/etc/ausf.conf .
......
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