Commit c3c89417 authored by Raphael Defosseux's avatar Raphael Defosseux

DOCKER: improvements:

  -- No more cloning inside builder, just a copy
  -- exposing ports
  -- adding CMD and ENTRYPOINT
Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@openairinterface.org>
parent c7927169
# Any CI/CD artifact
openair-spgwu.tar.bz2
archives
*-cfg.sh
*-env.list
src/oai_rules_result*txt
......@@ -31,6 +31,7 @@ source $THIS_SCRIPT_PATH/build_helper
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_fb_folly_from_source(){
echo_info "Starting to install folly from source"
if [ $1 -eq 0 ]; then
OPTION=""
read -p "Do you want to install FaceBook folly (github)? <y/N> " prompt
......@@ -143,6 +144,7 @@ install_fb_folly_from_source(){
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
popd
fi
echo_success "End of folly installation"
return 0
}
......@@ -69,6 +69,7 @@ install_fmt() {
#arg1 is force (0 or 1) (no interactive script)
#arg2 is debug (0 or 1) (install debug libraries)
install_spdlog_from_git() {
echo_info "Starting to install spdlog from source"
if [ $1 -eq 0 ]; then
read -p "Do you want to install spdlog ? <y/N> " prompt
OPTION=""
......@@ -101,6 +102,7 @@ install_spdlog_from_git() {
sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
popd
fi
echo_success "End of spdlog installation"
return 0
}
......@@ -444,6 +446,7 @@ check_install_spgwu_deps() {
$SUDO $INSTALLER install $OPTION $PACKAGE_LIST
ret=$?;[[ $ret -ne 0 ]] && return $ret
echo_info "Packages and Libraries installation finished!"
# Use fmt lib included in spdlog
#install_fmt $1
......
......@@ -31,37 +31,31 @@
FROM ubuntu:bionic as oai-spgwu-tiny-builder
ARG EURECOM_PROXY
ARG BUILD_FOR_CI
ARG CI_SRC_BRANCH
ARG CI_SRC_COMMIT
ARG CI_DEST_BRANCH
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Europe
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && DEBIAN_FRONTEND=noninteractive apt-get install --yes \
psmisc \
git \
&& rm -rf /var/lib/apt/lists/*
git
# Some GIT configuration command quite useful
RUN /bin/bash -c "if [[ -v EURECOM_PROXY ]]; then git config --global http.proxy $EURECOM_PROXY; fi"
RUN git config --global https.postBuffer 123289600
RUN git config --global http.sslverify false
# In normal case, we build out of the develop branch
RUN /bin/bash -c "if [[ -v CI_SRC_BRANCH ]]; then git clone https://github.com/OPENAIRINTERFACE/openair-spgwu-tiny.git -b $CI_SRC_BRANCH /openair-spgwu-tiny; else git clone https://github.com/OPENAIRINTERFACE/openair-spgwu-tiny.git -b develop /openair-spgwu-tiny; fi"
# For CI, especially for Pull/Merge Requests, we build out of temp merge
# Copy the workspace as is
WORKDIR /openair-spgwu-tiny
RUN /bin/bash -c "if [[ -v BUILD_FOR_CI ]]; then git config --global user.name \"OAI CI\"; fi"
RUN /bin/bash -c "if [[ -v BUILD_FOR_CI ]]; then git config --global user.email ci@openairinterface.org; fi"
RUN /bin/bash -c "if [[ -v BUILD_FOR_CI ]]; then git checkout -f $CI_SRC_COMMIT; fi"
RUN /bin/bash -c "if [[ -v BUILD_FOR_CI ]]; then git merge --ff origin/$CI_DEST_BRANCH -m \"Temporary merge for CI\"; fi"
COPY . /openair-spgwu-tiny
# Installing and Building SPGW-U-TINY
WORKDIR /openair-spgwu-tiny/build/scripts
RUN ./build_spgwu --install-deps --force
RUN ./build_spgwu --clean --build-type Release --jobs
RUN cat /openair-spgwu-tiny/build/log/spgwu.txt
RUN ./build_spgwu --clean --build-type Release --jobs --Verbose
# Getting SHA-ONE for support
WORKDIR /openair-spgwu-tiny
RUN git log -n1 > version.txt
#---------------------------------------------------------------------
# TARGET IMAGE
......@@ -86,6 +80,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get upgrade --yes && DE
# Copying executable and generated libraries
WORKDIR /openair-spgwu-tiny/bin
COPY --from=oai-spgwu-tiny-builder /openair-spgwu-tiny/build/spgw_u/build/spgwu oai_spgwu
COPY --from=oai-spgwu-tiny-builder /openair-spgwu-tiny/scripts/entrypoint.sh .
# Copying template configuration files
# The configuration folder will be flat
......@@ -93,3 +88,10 @@ WORKDIR /openair-spgwu-tiny/etc
COPY --from=oai-spgwu-tiny-builder /openair-spgwu-tiny/etc/spgw_u.conf .
WORKDIR /openair-spgwu-tiny
COPY --from=oai-spgwu-tiny-builder /openair-spgwu-tiny/version.txt .
# expose ports
EXPOSE 2152/udp 8805/udp
CMD ["/openair-spgwu-tiny/bin/oai_spgwu", "-c", "/openair-spgwu-tiny/etc/spgw_u.conf", "-o"]
ENTRYPOINT ["/openair-spgwu-tiny/bin/entrypoint.sh"]
......@@ -122,17 +122,13 @@ pipeline {
stage ('Build SPGW-U Image') {
steps {
script {
if (env.ghprbPullId != null) {
// Building a temporary image
myShCmd('docker image prune --force', new_host_flag, new_host_user, new_host)
myShCmd('docker build --target oai-spgwu-tiny --tag oai-spgwu-tiny:ci-temp --file ci-scripts/Dockerfile.ubuntu18.04 --build-arg EURECOM_PROXY="http://proxy.eurecom.fr:8080" --build-arg BUILD_FOR_CI="True" --build-arg CI_SRC_BRANCH="' + env.ghprbSourceBranch + '" --build-arg CI_SRC_COMMIT="' + env.ghprbActualCommit + '" --build-arg CI_DEST_BRANCH="develop" . > archives/spgwu_docker_image_build.log 2>&1', new_host_flag, new_host_user, new_host)
} else {
if (env.ghprbPullId == null) {
// Currently this pipeline only runs for pushes to `develop` branch
// First clean image registry
myShCmd('docker image rm oai-spgwu-tiny:develop', new_host_flag, new_host_user, new_host)
myShCmd('docker image prune --force', new_host_flag, new_host_user, new_host)
myShCmd('docker build --target oai-spgwu-tiny --tag oai-spgwu-tiny:develop --file ci-scripts/Dockerfile.ubuntu18.04 --build-arg EURECOM_PROXY="http://proxy.eurecom.fr:8080" --build-arg CI_SRC_BRANCH="develop" . > archives/spgwu_docker_image_build.log 2>&1', new_host_flag, new_host_user, new_host)
}
myShCmd('docker image prune --force', new_host_flag, new_host_user, new_host)
myShCmd('docker build --target oai-spgwu-tiny --tag oai-spgwu-tiny:' + spgwu_tag + ' --file ci-scripts/Dockerfile.ubuntu18.04 --build-arg EURECOM_PROXY="http://proxy.eurecom.fr:8080" . > archives/spgwu_docker_image_build.log 2>&1', new_host_flag, new_host_user, new_host)
myShCmd('docker image ls >> archives/spgwu_docker_image_build.log', new_host_flag, new_host_user, new_host)
}
}
......
......@@ -7,7 +7,7 @@
# * except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.openairinterface.org/?page_id=698
# * 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,
......@@ -16,7 +16,7 @@
# * limitations under the License.
# *-------------------------------------------------------------------------------
# * For more information about the OpenAirInterface (OAI) Software Alliance:
# * contact@openairinterface.org
# * contact@openairinterface.org
# */
#---------------------------------------------------------------------
......@@ -31,6 +31,7 @@ class spgwuConfigGen():
self.sxu_name = ''
self.spgwc0_ip_addr = ''
self.fromDockerFile = False
self.envForEntrypoint = False
def GenerateSpgwuConfigurer(self):
spgwuFile = open('./spgwu-cfg.sh', 'w')
......@@ -70,6 +71,17 @@ class spgwuConfigGen():
spgwuFile.write('exit 0\n')
spgwuFile.close()
def GenerateSpgwuEnvList(self):
spgwuFile = open('./spgwu-env.list', 'w')
spgwuFile.write('# Environment Variables used by the OAI-SPGW-U-TINY Entrypoint Script\n')
spgwuFile.write('INSTANCE=1\n')
spgwuFile.write('PID_DIRECTORY=/var/run\n')
spgwuFile.write('SGW_INTERFACE_NAME_FOR_S1U_S12_S4_UP=' + self.s1u_name + '\n')
spgwuFile.write('SGW_INTERFACE_NAME_FOR_SX=' + self.sxu_name + '\n')
spgwuFile.write('SGW_INTERFACE_NAME_FOR_SGI=eth0\n')
spgwuFile.write('SPGWC0_IP_ADDRESS=' + self.spgwc0_ip_addr + '\n')
spgwuFile.close()
#-----------------------------------------------------------
# Usage()
#-----------------------------------------------------------
......@@ -87,6 +99,8 @@ def Usage():
print(' --sxu=[SPGW-U SX Interface Name]')
print(' --s1u=[SPGW-U S1-U Interface Name]')
print(' --from_docker_file')
print('------------------------------------------------------------------------------------------- SPGW-U Not Mandatory -----')
print(' --envForEntrypoint [generates a spgwc-env.list interpreted by the entrypoint]')
argvs = sys.argv
argc = len(argvs)
......@@ -113,6 +127,8 @@ while len(argvs) > 1:
mySpgwuCfg.s1u_name = matchReg.group(1)
elif re.match('^\-\-from_docker_file', myArgv, re.IGNORECASE):
mySpgwuCfg.fromDockerFile = True
elif re.match('^\-\-env_for_entrypoint', myArgv, re.IGNORECASE):
mySpgwuCfg.envForEntrypoint = True
else:
Usage()
sys.exit('Invalid Parameter: ' + myArgv)
......@@ -132,7 +148,10 @@ if mySpgwuCfg.kind == 'SPGW-U':
Usage()
sys.exit('missing SPGW-C #0 IP address on SX interface')
else:
mySpgwuCfg.GenerateSpgwuConfigurer()
if mySpgwuCfg.envForEntrypoint:
mySpgwuCfg.GenerateSpgwuEnvList()
else:
mySpgwuCfg.GenerateSpgwuConfigurer()
sys.exit(0)
else:
Usage()
......
......@@ -428,7 +428,7 @@ class HtmlReport():
if os.path.isfile(cwd + '/archives/' + logFileName):
status = False
section_start_pattern = 'build_spgwu --install-deps --force'
section_end_pattern = 'build_spgwu --clean --build-type Release --jobs'
section_end_pattern = 'build_spgwu --clean --build-type Release --jobs --Verbose'
section_status = False
package_install = False
folly_build_start = False
......@@ -447,22 +447,22 @@ class HtmlReport():
result = re.search('SPGW-U deps installation successful', line)
if result is not None:
status = True
result = re.search('/tmp /openair-spgwu-tiny/build/scripts', line)
result = re.search('Packages and Libraries installation finished', line)
if result is not None:
package_install = True
result = re.search('Cloning into \'folly\'', line)
result = re.search('Starting to install folly from source', line)
if result is not None:
folly_build_start = True
if folly_build_start:
result = re.search('Installing: /usr/local/lib/libfollybenchmark', line)
result = re.search('End of folly installation', line)
if result is not None:
folly_build_start = False
folly_build = True
result = re.search('Install spdlog from ', line)
result = re.search('Starting to install spdlog from source', line)
if result is not None:
spdlog_build_start = True
if spdlog_build_start:
result = re.search('/openair-spgwu-tiny/build/scripts', line)
result = re.search('End of spdlog installation', line)
if result is not None:
spdlog_build_start = False
spdlog_build = True
......@@ -514,8 +514,8 @@ class HtmlReport():
cwd = os.getcwd()
if os.path.isfile(cwd + '/archives/' + logFileName):
status = False
section_start_pattern = 'build_spgwu --clean --build-type Release --jobs'
section_end_pattern = 'cat /openair-spgwu-tiny/build/log/spgwu.txt'
section_start_pattern = 'build_spgwu --clean --build-type Release --jobs --Verbose'
section_end_pattern = 'git log -n1 > version.txt'
section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile:
for line in logfile:
......@@ -557,8 +557,8 @@ class HtmlReport():
nb_warnings = 0
if os.path.isfile(cwd + '/archives/' + logFileName):
section_start_pattern = 'cat /openair-spgwu-tiny/build/log/spgwu.txt'
section_end_pattern = 'FROM ubuntu:bionic as oai-spgwu-tiny$'
section_start_pattern = 'build_spgwu --clean --build-type Release --jobs --Verbose'
section_end_pattern = 'git log -n1 > version.txt'
section_status = False
with open(cwd + '/archives/' + logFileName, 'r') as logfile:
for line in logfile:
......
#!/bin/bash
set -euo pipefail
CONFIG_DIR="/openair-spgwu-tiny/etc"
for c in ${CONFIG_DIR}/*.conf; do
# grep variable names (format: ${VAR}) from template to be rendered
VARS=$(grep -oP '@[a-zA-Z0-9_]+@' ${c} | sort | uniq | xargs)
# create sed expressions for substituting each occurrence of ${VAR}
# with the value of the environment variable "VAR"
EXPRESSIONS=""
for v in ${VARS}; do
NEW_VAR=`echo $v | sed -e "s#@##g"`
if [[ "${!NEW_VAR}x" == "x" ]]; then
echo "Error: Environment variable '${NEW_VAR}' is not set." \
"Config file '$(basename $c)' requires all of $VARS."
exit 1
fi
EXPRESSIONS="${EXPRESSIONS};s|${v}|${!NEW_VAR}|g"
done
EXPRESSIONS="${EXPRESSIONS#';'}"
# render template and inline replace config file
sed -i "${EXPRESSIONS}" ${c}
done
exec "$@"
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