Commit e7f040ab authored by Raphael Defosseux's avatar Raphael Defosseux

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

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

See merge request oai/cn5g/oai-cn5g-nrf!26
parents de784123 4f26b709
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
# #
# Dockerfile for the Open-Air-Interface NRF service # Dockerfile for the Open-Air-Interface NRF service
# Valid for Ubuntu-18.04 (bionic) # Valid for Ubuntu-18.04 (bionic)
# The port exposed by container are 8080/tcp , 9090/tcp change it according to your setup
# #
#--------------------------------------------------------------------- #---------------------------------------------------------------------
...@@ -37,6 +38,7 @@ RUN cp -Rf /openair-nrf-ext-ref /openair-nrf/build/ext ...@@ -37,6 +38,7 @@ RUN cp -Rf /openair-nrf-ext-ref /openair-nrf/build/ext
# Building NRF # Building NRF
WORKDIR /openair-nrf/build/scripts WORKDIR /openair-nrf/build/scripts
RUN ./build_nrf --clean --Verbose --build-type Release --jobs && \ RUN ./build_nrf --clean --Verbose --build-type Release --jobs && \
ldd /openair-nrf/build/nrf/build/nrf && \
mv /openair-nrf/build/nrf/build/nrf /openair-nrf/build/nrf/build/oai_nrf mv /openair-nrf/build/nrf/build/nrf /openair-nrf/build/nrf/build/oai_nrf
#--------------------------------------------------------------------- #---------------------------------------------------------------------
...@@ -55,12 +57,13 @@ RUN apt-get update && \ ...@@ -55,12 +57,13 @@ RUN apt-get update && \
iputils-ping \ iputils-ping \
bc \ bc \
tzdata \ tzdata \
tshark \
libasan4 \ libasan4 \
libgoogle-glog0v5 \ libgoogle-glog0v5 \
libdouble-conversion1 \ libdouble-conversion1 \
libconfig++9v5 \ libconfig++9v5 \
libldap-2.4-2 \ libldap-2.4-2 \
libkrb5-3 \
libgssapi-krb5-2 \
librtmp1 \ librtmp1 \
libpsl5 \ libpsl5 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
...@@ -73,6 +76,7 @@ COPY --from=oai-nrf-builder \ ...@@ -73,6 +76,7 @@ COPY --from=oai-nrf-builder \
./ ./
COPY --from=oai-nrf-builder \ COPY --from=oai-nrf-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/x86_64-linux-gnu/libcurl-gnutls.so.4 \ /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 \ /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 \
......
...@@ -7,8 +7,7 @@ services: ...@@ -7,8 +7,7 @@ services:
- 80 - 80
- 9090 - 9090
command: > command: >
bash -c "nohup tshark -i eth0 -w /tmp/nrf.pcap 2>&1 > /dev/null & bash -c "/openair-nrf/bin/oai_nrf -c /openair-nrf/etc/nrf.conf -o | tee /tmp/nrf.log 2>&1
/openair-nrf/bin/oai_nrf -c /openair-nrf/etc/nrf.conf -o | tee /tmp/nrf.log 2>&1
" "
cap_add: cap_add:
- NET_ADMIN - NET_ADMIN
......
...@@ -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,54 @@ def _parse_args() -> argparse.Namespace: ...@@ -38,5 +40,54 @@ 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-nrf" '
cmd += ' --change "EXPOSE 80/tcp" '
cmd += ' --change "EXPOSE 9090/tcp" '
cmd += ' --change "CMD [\\"/openair-nrf/bin/oai_nrf\\", \\"-c\\", \\"/openair-nrf/etc/nrf.conf\\", \\"-o\\"]" '
cmd += ' --change "ENTRYPOINT [\\"/bin/bash\\", \\"/openair-nrf/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()
...@@ -618,7 +618,7 @@ class HtmlReport(): ...@@ -618,7 +618,7 @@ class HtmlReport():
status = False status = False
if nfType == 'NRF': if nfType == 'NRF':
section_start_pattern = 'build_nrf --clean --Verbose --build-type Release --jobs' section_start_pattern = 'build_nrf --clean --Verbose --build-type Release --jobs'
section_end_pattern = 'FROM ubuntu:bionic as oai-nrf$' section_end_pattern = 'FROM .* as oai-nrf$'
pass_pattern = 'nrf installed' pass_pattern = 'nrf installed'
section_status = False section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile: with open(cwd + '/archives/' + logFileName, 'r') as logfile:
...@@ -666,7 +666,7 @@ class HtmlReport(): ...@@ -666,7 +666,7 @@ class HtmlReport():
if os.path.isfile(cwd + '/archives/' + logFileName): if os.path.isfile(cwd + '/archives/' + logFileName):
if nfType == 'NRF': if nfType == 'NRF':
section_start_pattern = 'build_nrf --clean --Verbose --build-type Release --jobs' section_start_pattern = 'build_nrf --clean --Verbose --build-type Release --jobs'
section_end_pattern = 'FROM ubuntu:bionic as oai-nrf$' section_end_pattern = 'FROM .* as oai-nrf$'
section_status = False section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile: with open(cwd + '/archives/' + logFileName, 'r') as logfile:
for line in logfile: for line in logfile:
...@@ -727,23 +727,31 @@ class HtmlReport(): ...@@ -727,23 +727,31 @@ class HtmlReport():
for variant in variants: for variant in variants:
logFileName = 'nrf_' + variant + '_image_build.log' logFileName = 'nrf_' + variant + '_image_build.log'
if os.path.isfile(cwd + '/archives/' + logFileName): if os.path.isfile(cwd + '/archives/' + logFileName):
section_start_pattern = 'FROM ubuntu:bionic as oai-nrf$' section_start_pattern = 'FROM .* as oai-nrf$'
section_end_pattern = 'COPY --from=oai-nrf-builder /openair-nrf/scripts/entrypoint.sh entrypoint.sh' section_end_pattern = 'COPY --from=oai-nrf-builder /openair-nrf/etc/nrf.conf '
section_status = False section_status = False
status = False status = False
noPbInLDD = True
with open(cwd + '/archives/' + logFileName, 'r') as logfile: with open(cwd + '/archives/' + logFileName, 'r') as logfile:
for line in logfile: for line in logfile:
result = re.search(section_start_pattern, line) result = re.search(section_start_pattern, line)
if result is not None: if result is not None:
section_status = True section_status = True
result = re.search('not found', line)
if section_status and result is not None:
noPbInLDD = False
result = re.search(section_end_pattern, line) result = re.search(section_end_pattern, line)
if result is not None: if result is not None:
section_status = False section_status = False
status = True status = True
logfile.close() logfile.close()
if status: if status and noPbInLDD:
cell_msg = ' <td bgcolor="LimeGreen"><pre style="border:none; background-color:LimeGreen"><b>' cell_msg = ' <td bgcolor="LimeGreen"><pre style="border:none; background-color:LimeGreen"><b>'
cell_msg += 'OK:\n' cell_msg += 'OK:\n'
elif noPbInLDD:
cell_msg = ' <td bgcolor="Tomato"><pre style="border:none; background-color:Tomato"><b>'
cell_msg += 'KO:\n'
cell_msg += ' Some libraries were not copied from builder image\n'
else: else:
cell_msg = ' <td bgcolor="Tomato"><pre style="border:none; background-color:Tomato"><b>' cell_msg = ' <td bgcolor="Tomato"><pre style="border:none; background-color:Tomato"><b>'
cell_msg += 'KO:\n' cell_msg += 'KO:\n'
...@@ -841,7 +849,7 @@ class HtmlReport(): ...@@ -841,7 +849,7 @@ class HtmlReport():
result = re.search(section_end_pattern, line) result = re.search(section_end_pattern, line)
if result is not None: if result is not None:
section_status = False section_status = False
if section_status: if section_status and not status:
if nfType == 'NRF': if nfType == 'NRF':
if self.git_pull_request: if self.git_pull_request:
result = re.search('oai-nrf *ci-tmp', line) result = re.search('oai-nrf *ci-tmp', line)
......
...@@ -82,7 +82,8 @@ RUN yum update -y && \ ...@@ -82,7 +82,8 @@ RUN yum update -y && \
net-tools \ net-tools \
procps-ng\ procps-ng\
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-nrf/bin WORKDIR /openair-nrf/bin
...@@ -107,7 +108,8 @@ COPY --from=oai-nrf-builder \ ...@@ -107,7 +108,8 @@ COPY --from=oai-nrf-builder \
/usr/lib64/libboost_regex.so.1.66.0 \ /usr/lib64/libboost_regex.so.1.66.0 \
/usr/lib64/ /usr/lib64/
RUN ldconfig RUN ldconfig && \
ldd /openair-nrf/bin/oai_nrf
# Copying template configuration files # Copying template configuration files
# The configuration folder will be flat # The configuration folder will be flat
......
#/*
# * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
# * contributor license agreements. See the NOTICE file distributed with
# * this work for additional information regarding copyright ownership.
# * The OpenAirInterface Software Alliance licenses this file to You under
# * the OAI Public License, Version 1.1 (the "License"); you may not use this file
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.openairinterface.org/?page_id=698
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# */
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# #
# Dockerfile for the Open-Air-Interface NRF service # Dockerfile for the Open-Air-Interface NRF service
...@@ -34,6 +54,7 @@ WORKDIR /openair-nrf ...@@ -34,6 +54,7 @@ WORKDIR /openair-nrf
WORKDIR /openair-nrf/build/scripts WORKDIR /openair-nrf/build/scripts
RUN ./build_nrf --install-deps --force RUN ./build_nrf --install-deps --force
RUN ./build_nrf --clean --Verbose --build-type Release --jobs && \ RUN ./build_nrf --clean --Verbose --build-type Release --jobs && \
ldd /openair-nrf/build/nrf/build/nrf && \
mv /openair-nrf/build/nrf/build/nrf /openair-nrf/build/nrf/build/oai_nrf mv /openair-nrf/build/nrf/build/nrf /openair-nrf/build/nrf/build/oai_nrf
#--------------------------------------------------------------------- #---------------------------------------------------------------------
...@@ -52,12 +73,13 @@ RUN apt-get update && \ ...@@ -52,12 +73,13 @@ RUN apt-get update && \
iputils-ping \ iputils-ping \
bc \ bc \
tzdata \ tzdata \
tshark \
libasan4 \ libasan4 \
libgoogle-glog0v5 \ libgoogle-glog0v5 \
libdouble-conversion1 \ libdouble-conversion1 \
libconfig++9v5 \ libconfig++9v5 \
libldap-2.4-2 \ libldap-2.4-2 \
libkrb5-3 \
libgssapi-krb5-2 \
librtmp1 \ librtmp1 \
libpsl5 \ libpsl5 \
&& rm -rf /var/lib/apt/lists/* && rm -rf /var/lib/apt/lists/*
...@@ -70,6 +92,7 @@ COPY --from=oai-nrf-builder \ ...@@ -70,6 +92,7 @@ COPY --from=oai-nrf-builder \
./ ./
COPY --from=oai-nrf-builder \ COPY --from=oai-nrf-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/x86_64-linux-gnu/libcurl-gnutls.so.4 \ /usr/lib/x86_64-linux-gnu/libcurl-gnutls.so.4 \
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 \ /usr/lib/x86_64-linux-gnu/libboost_system.so.1.65.1 \
......
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