Skip to content

Commit ca545de

Browse files
authored
fix(ci): Latest fixes from Eurecom Infrastructure changes (magma#12570)
* fix(ci): handle the case when HTML file not present * fix(ci): no more need for a git proxy in the Eurecom new infrastructure * feat(ci): adding a flatten script to reduce the size of the target image * fix(ci): no need to do the unshallow. Jenkins job is now properly configured * fix(ci): fix typo * fix(ci): doing the requested changes by code reviewer Signed-off-by: Raphael Defosseux <raphael.defosseux@openairinterface.org>
1 parent f588f2e commit ca545de

3 files changed

+112
-8
lines changed

ci-scripts/JenkinsFile-OAI-Container-GitHub

+6-8
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,9 @@ pipeline {
121121
branch = 'master'
122122
u18_image_tag = 'master'
123123
u18_docker_file = 'lte/gateway/docker/mme/Dockerfile.ubuntu18.04'
124-
u18_options = ' --build-arg GIT_PROXY="http://proxy.eurecom.fr:8080"'
125124
} else {
126125
branch = sha1
127126
u18_docker_file = 'ci-scripts/docker/Dockerfile.mme.ci.ubuntu18'
128-
u18_options = ''
129127
}
130128
checkout(
131129
changelog: false,
@@ -143,7 +141,6 @@ pipeline {
143141
// If so, we will run the OAI pipeline
144142
// For security reasons, we retrieve from a trusted forked repository
145143
sh 'wget --quiet https://raw.githubusercontent.com/' + trustedGHuser + '/magma/' + trustedBranch + '/ci-scripts/check_pr_modified_files_for_oai_pipeline.py -O ci-scripts/ci-check_pr_modified_files_for_oai_pipeline.py || true'
146-
sh 'git fetch --unshallow || true'
147144
sh 'python3 ci-scripts/ci-check_pr_modified_files_for_oai_pipeline.py'
148145
// If the previous command is OK, no need to run
149146
// All the following stages will be bypassed and the CI
@@ -190,7 +187,9 @@ pipeline {
190187
// Create the image to use
191188
// Once again, we are not using the full dockerfile from scratch: too long --> when it is a pull request
192189
// On the daily master build, we are doing from scratch
193-
sh('docker build --no-cache --target magma-mme --tag magma-mme:' + u18_image_tag + ' --file ' + u18_docker_file + u18_options + ' . > archives/build_magma_mme.log 2>&1')
190+
sh('docker build --no-cache --target magma-mme --tag magma-mme:' + u18_image_tag + ' --file ' + u18_docker_file + ' . > archives/build_magma_mme.log 2>&1')
191+
sh('wget --quiet https://raw.githubusercontent.com/' + trustedGHuser + '/magma/' + trustedBranch + '/ci-scripts/flatten_image.py -O ci-scripts/ci-flatten_image.py')
192+
sh('python3 ./ci-scripts/ci-flatten_image.py --tag magma-mme:' + u18_image_tag)
194193
sh('docker image prune --force > /dev/null 2>&1')
195194
sh('docker image ls >> archives/build_magma_mme.log')
196195
}
@@ -240,11 +239,9 @@ pipeline {
240239
branch = 'master'
241240
rhel8_image_tag = 'master'
242241
rhel8_docker_file = 'lte/gateway/docker/mme/Dockerfile.rhel8'
243-
rhel8_options = ' --build-arg GIT_PROXY="http://proxy.eurecom.fr:8080"'
244242
} else {
245243
branch = sha1
246244
rhel8_docker_file = 'ci-scripts/docker/Dockerfile.mme.ci.rhel8'
247-
rhel8_options = ''
248245
}
249246
checkout(
250247
changelog: false,
@@ -259,7 +256,6 @@ pipeline {
259256
if (!params.REGRESSION_TEST) {
260257
try {
261258
sh 'wget --quiet https://raw.githubusercontent.com/' + trustedGHuser + '/magma/' + trustedBranch + '/ci-scripts/check_pr_modified_files_for_oai_pipeline.py -O ci-scripts/ci-check_pr_modified_files_for_oai_pipeline.py || true'
262-
sh 'git fetch --unshallow || true'
263259
sh 'python3 ci-scripts/ci-check_pr_modified_files_for_oai_pipeline.py'
264260
runAllRHELPipelineStages = false
265261
} catch (Exception e) {
@@ -308,7 +304,9 @@ pipeline {
308304
// Create the image to use
309305
// Once again, we are not using the full dockerfile from scratch: too long --> when it is a pull request
310306
// On the daily master build, we are doing from scratch
311-
sh('sudo podman build --no-cache --target magma-mme --tag magma-mme:' + rhel8_image_tag + ' --file ' + rhel8_docker_file + rhel8_options + ' . > archives/build_magma_mme_rhel8.log 2>&1')
307+
sh('sudo podman build --no-cache --target magma-mme --tag magma-mme:' + rhel8_image_tag + ' --file ' + rhel8_docker_file + ' . > archives/build_magma_mme_rhel8.log 2>&1')
308+
sh('wget --quiet https://raw.githubusercontent.com/' + trustedGHuser + '/magma/' + trustedBranch + '/ci-scripts/flatten_image.py -O ci-scripts/ci-flatten_image.py')
309+
sh('python3 ./ci-scripts/ci-flatten_image.py --tag magma-mme:' + rhel8_image_tag)
312310
sh('sudo podman image prune --force > /dev/null 2>&1')
313311
sh('sudo podman image ls >> archives/build_magma_mme_rhel8.log')
314312
}

ci-scripts/flatten_image.py

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"""
2+
Copyright 2022 The Magma Authors.
3+
4+
This source code is licensed under the BSD-style license found in the
5+
LICENSE file in the root directory of this source tree.
6+
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
"""
13+
14+
import argparse
15+
import subprocess # noqa: S404
16+
import sys
17+
18+
19+
def main() -> None:
20+
"""Provide command-line options to flatten MAGMA-MME OAI image"""
21+
args = _parse_args()
22+
status = perform_flattening(args.tag)
23+
sys.exit(status)
24+
25+
26+
def _parse_args() -> argparse.Namespace:
27+
"""Parse the command line args
28+
29+
Returns:
30+
argparse.Namespace: the created parser
31+
"""
32+
parser = argparse.ArgumentParser(description='Flattening Image')
33+
34+
parser.add_argument(
35+
'--tag', '-t',
36+
action='store',
37+
required=True,
38+
help='Image Tag in image-name:image tag format',
39+
)
40+
return parser.parse_args()
41+
42+
43+
def perform_flattening(tag):
44+
"""Parse the command line args
45+
46+
Args:
47+
tag: Image Tag in image-name:image tag format
48+
49+
Returns:
50+
int: pass / fail status
51+
"""
52+
# First detect which docker/podman command to use
53+
cli = ''
54+
image_prefix = ''
55+
cmd = 'which podman || true'
56+
podman_check = subprocess.check_output(cmd, shell=True, universal_newlines=True) # noqa: S602
57+
if podman_check.strip():
58+
cli = 'sudo podman'
59+
image_prefix = 'localhost/'
60+
else:
61+
cmd = 'which docker || true'
62+
docker_check = subprocess.check_output(cmd, shell=True, universal_newlines=True) # noqa: S602
63+
if docker_check.strip():
64+
cli = 'docker'
65+
image_prefix = ''
66+
else:
67+
print('No docker / podman installed: quitting')
68+
return -1
69+
70+
print(f'Flattening {tag}')
71+
# Creating a container
72+
cmd = cli + ' run --name test-flatten --entrypoint /bin/true -d ' + tag
73+
print(cmd)
74+
subprocess.check_call(cmd, shell=True, universal_newlines=True) # noqa: S602
75+
76+
# Export / Import trick
77+
cmd = cli + ' export test-flatten | ' + cli + ' import '
78+
# Bizarro syntax issue with podman
79+
if cli == 'docker':
80+
cmd += ' --change "ENV PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" '
81+
else:
82+
cmd += ' --change "ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" '
83+
cmd += ' --change "WORKDIR /magma-mme" '
84+
cmd += ' --change "EXPOSE 3870/tcp" '
85+
cmd += ' --change "EXPOSE 5870/tcp" '
86+
cmd += ' --change "EXPOSE 2123/udp" '
87+
cmd += ' --change "CMD [\\"sleep\\", \\"infinity\\"]" ' # noqa: WPS342
88+
cmd += ' - ' + image_prefix + tag
89+
print(cmd)
90+
subprocess.check_call(cmd, shell=True, universal_newlines=True) # noqa: S602
91+
92+
# Remove container
93+
cmd = cli + ' rm -f test-flatten'
94+
print(cmd)
95+
subprocess.check_call(cmd, shell=True, universal_newlines=True) # noqa: S602
96+
97+
# At this point the original image is a dangling image.
98+
# CI pipeline will clean up (`image prune --force`)
99+
return 0
100+
101+
102+
if __name__ == '__main__':
103+
main()

ci-scripts/generateHtmlReport-OAI-pipeline.py

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def main() -> None:
4646

4747
if args.mode == 'TestWithDsTest':
4848
append_build_summary(args, 'test_results_magma_oai_epc.html')
49+
append_build_summary(args, 'test_results_magma_epc_u18.html')
4950

5051
if args.mode == 'RHEL8SanityCheck':
5152
append_build_summary(args, 'test_results_magma_epc_rhel8.html')
@@ -163,6 +164,8 @@ def append_build_summary(args, filename):
163164
filename: file to append to
164165
"""
165166
cwd = os.getcwd()
167+
if not os.path.isfile(cwd + '/' + filename):
168+
return
166169
report = ''
167170
org_file = os.path.join(cwd, filename)
168171
with open(org_file, 'r') as org_f:

0 commit comments

Comments
 (0)