Commit 9945af7a 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 cf236eea
......@@ -43,7 +43,9 @@ RUN git clone -b stable/2101 https://github.com/fdio/vpp.git && \
mv upg-vpp/vpp.spec / && \
./scripts/apply_vpp_patches.sh
RUN make build-release -C vpp/
RUN make build-release -C vpp/ && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl
#---------------------------------------------------------------------
# TARGET IMAGE
......@@ -68,7 +70,8 @@ RUN yum repolist --disablerepo=* && \
rpm -i *.rpm && \
rm *.rpm && \
yum remove -y wget && \
rm -rf /var/lib/apt/lists/*
yum clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf
WORKDIR /openair-upf/bin
COPY --from=vpp-upf-builder \
......@@ -97,7 +100,9 @@ COPY --from=vpp-upf-builder \
# /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/libnat.so.21.01.1 \
/usr/lib64/
RUN ldconfig
RUN ldconfig && \
ldd /openair-upf/bin/vpp && \
ldd /openair-upf/bin/vppctl
RUN groupadd vpp
......
......@@ -47,7 +47,9 @@ RUN git clone -b stable/2101 https://github.com/fdio/vpp.git && \
# To Do - remove unnecessary pulgin build to optimise build time e.g. ipsec, dpdk etc.
# Build vpp with Travelping upf plugin
RUN make build-release -C vpp
RUN make build-release -C vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl
#---------------------------------------------------------------------
# TARGET IMAGE
......@@ -60,7 +62,6 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
net-tools \
tshark \
tzdata\
libhyperscan-dev \
iproute2 \
......@@ -97,7 +98,9 @@ COPY --from=vpp-upf-builder \
# /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/libnat.so.21.01.1 \
/usr/lib/x86_64-linux-gnu/
RUN ldconfig
RUN ldconfig && \
ldd /openair-upf/bin/vpp && \
ldd /openair-upf/bin/vppctl
RUN groupadd vpp
......
......@@ -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,54 @@ 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-upf" '
cmd += ' --change "EXPOSE 8085/udp" '
cmd += ' --change "EXPOSE 2152/udp" '
cmd += ' --change "CMD [\\"/openair-upf/run.sh\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/openair-upf/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()
......@@ -77,7 +77,10 @@ RUN git clone -b stable/2101 https://github.com/fdio/vpp.git && \
./scripts/apply_vpp_patches.sh
RUN make install-dep -C vpp/
RUN make build-release -C vpp/
RUN make build-release -C vpp/ && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl
#---------------------------------------------------------------------
# TARGET IMAGE
#---------------------------------------------------------------------
......@@ -101,7 +104,8 @@ RUN yum repolist --disablerepo=* && \
rpm -i *.rpm && \
rm *.rpm && \
yum remove -y wget && \
rm -rf /var/lib/apt/lists/*
yum clean all -y && \
rm -rf /var/cache/yum /var/cache/dnf
WORKDIR /openair-upf/bin
COPY --from=vpp-upf-builder \
......@@ -130,7 +134,9 @@ COPY --from=vpp-upf-builder \
# /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/libnat.so.21.01.1 \
/usr/lib64/
RUN ldconfig
RUN ldconfig && \
ldd /openair-upf/bin/vpp && \
ldd /openair-upf/bin/vppctl
RUN groupadd vpp
......
......@@ -73,7 +73,10 @@ RUN git clone -b stable/2101 https://github.com/fdio/vpp.git && \
# Build vpp with Travelping upf plugin
RUN make install-dep -C vpp
RUN make build-release -C vpp
RUN make build-release -C vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vpp && \
ldd /vpp-upf/vpp/build-root/install-vpp-native/vpp/bin/vppctl
#---------------------------------------------------------------------
# TARGET IMAGE
#---------------------------------------------------------------------
......@@ -85,7 +88,6 @@ RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && \
DEBIAN_FRONTEND=noninteractive apt-get install --yes \
net-tools \
tshark \
tzdata\
libhyperscan-dev \
iproute2 \
......@@ -122,7 +124,9 @@ COPY --from=vpp-upf-builder \
# /vpp-upf/vpp/build-root/install-vpp-native/vpp/lib/libnat.so.21.01.1 \
/usr/lib/x86_64-linux-gnu/
RUN ldconfig
RUN ldconfig && \
ldd /openair-upf/bin/vpp && \
ldd /openair-upf/bin/vppctl
RUN groupadd vpp
......
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