Commit 1f117b51 authored by Raphael Defosseux's avatar Raphael Defosseux
Browse files

feat(ci): improvements


  -- Adding push to Docker-Hub
  -- Adding skeleton for sanity check deployment
Signed-off-by: Raphael Defosseux's avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent 6764287a
......@@ -97,6 +97,14 @@ pipeline {
}
}
echo "Git URL is ${GIT_URL}"
if (params.DockerHubCredentials == null) {
echo '\u26D4 \u001B[31mNo Credentials to push to DockerHub!\u001B[0m'
error "Stopping pipeline!"
}
if (params.SanityCheckDockerContainers == null) {
echo '\u26D4 \u001B[31mNo Resource to do sanity check deployment!\u001B[0m'
error "Stopping pipeline!"
}
}
}
}
......@@ -105,16 +113,15 @@ pipeline {
script {
sh "git clean -x -d -f > /dev/null 2>&1"
if ("MERGE".equals(env.gitlabActionType)) {
// Need a public repo
//gitlabMergeRequestLink = sh "curl --silent \"https://gitlab.eurecom.fr/api/v4/projects/oai%2Fcn5g%2Foai-cn5g-upf-vpp/merge_requests/${env.gitlabMergeRequestIid}\" | jq .web_url | sed 's#\"##g'"
gitlabMergeRequestLink = sh returnStdout: true, script: "curl --silent 'https://gitlab.eurecom.fr/api/v4/projects/oai%2Fcn5g%2Foai-cn5g-upf-vpp/merge_requests/${env.gitlabMergeRequestIid}' | jq .web_url | sed 's#\"##g'"
gitlabMergeRequestLink = gitlabMergeRequestLink.trim()
echo "========= THIS IS A MERGE REQUEST =========="
echo "MR ID is ${env.gitlabMergeRequestIid}"
//echo "MR LINK is ${gitlabMergeRequestLink}"
echo "MR LINK is ${gitlabMergeRequestLink}"
echo "MR TITLE is ${env.gitlabMergeRequestTitle}"
gitCommitAuthorEmailAddr = env.gitlabUserEmail
echo "GitLab Usermail is ${gitCommitAuthorEmailAddr}"
// Need a public repo
//sh "git fetch --prune --unshallow"
sh "git fetch --prune --unshallow"
shortenShaOne = sh returnStdout: true, script: 'git log -1 --pretty=format:"%h" ' + env.gitlabMergeRequestLastCommit
shortenShaOne = shortenShaOne.trim()
sh "./ci-scripts/doGitLabMerge.sh --src-branch ${env.gitlabSourceBranch} --src-commit ${env.gitlabMergeRequestLastCommit} --target-branch ${env.gitlabTargetBranch} --target-commit ${GIT_COMMIT}"
......@@ -161,6 +168,10 @@ pipeline {
myShCmd('mkdir -p archives', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd('docker build --no-cache --target oai-upf-vpp --tag oai-upf-vpp:' + upf_tag + ' --file docker/Dockerfile.upf-vpp.ubuntu18 --build-arg NEEDED_GIT_PROXY="http://proxy.eurecom.fr:8080" . > archives/upf_docker_image_build.log 2>&1', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd('docker image ls >> archives/upf_docker_image_build.log', rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
// We will keep also the TMP image in U18 case.
if ("MERGE".equals(env.gitlabActionType)) {
myShCmd('docker image tag oai-upf-vpp:' + upf_tag + ' oai-upf-vpp:' + rhel_upf_tag, rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
}
}
}
}
......@@ -213,7 +224,49 @@ pipeline {
}
}
}
}
}
stage ('Sanity Check Deployment') {
steps {
lock(params.SanityCheckDockerContainers)
script {
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode Deploy --service mysql'
// NRF SHALL BE DEPLOYED BEFORE UPF-VPP
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode Deploy --service oai-nrf'
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode Deploy --service vpp-upf --upf_tag ' + upf_tag
// SMF is dependant on AMF and EXT-DN: they will be deploy as well
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode Deploy --service oai-smf'
// Check if deployment is OK
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode Check --service all'
// Undeploy once OK
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode UnDeploy --service all'
}
}
post {
unsuccessful {
sh 'python3 ./ci-scripts/sanityCheckDeployment.py --mode UnDeploy --service all'
}
}
}
// For the moment it is Docker-Hub, but we might have a new one internally.
stage ('Pushing Image to Official Registry') {
steps {
script {
// Only in case of push to target branch!
if ("PUSH".equals(env.gitlabActionType)) {
withCredentials([
[$class: 'UsernamePasswordMultiBinding', credentialsId: "${params.DockerHubCredentials}", usernameVariable: 'DH_Username', passwordVariable: 'DH_Password']
]) {
myShCmd("echo ${DH_Password} | docker login --username ${DH_Username} --password-stdin", rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd("docker image tag oai-upf-vpp:develop ${DH_Username}/oai-upf-vpp:develop", rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd("docker push ${DH_Username}/oai-upf-vpp:develop", rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd("docker rmi ${DH_Username}/oai-upf-vpp:develop", rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
myShCmd("docker logout", rem_u18_host_flag, rem_u18_host_user, rem_u18_host)
}
}
}
}
}
}
......
"""
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
"""
import argparse
import logging
import os
import re
import sys
import subprocess
logging.basicConfig(
level=logging.DEBUG,
format="[%(asctime)s] %(name)s:%(levelname)s: %(message)s"
)
def main() -> None:
"""Provide command-line options to deploy a simple sanity check"""
args = _parse_args()
if args.mode == 'Deploy':
deployObject(args.service, args.upf_tag)
if args.mode == 'Check':
logging.info ('Performing Check')
if args.mode == 'UnDeploy':
logging.info ('Un-Deploying ' + args.service)
def _parse_args() -> argparse.Namespace:
"""Parse the command line args
Returns:
argparse.Namespace: the created parser
"""
parser = argparse.ArgumentParser(description='OAI UPF-VPP Sanity Check Deployment for CI')
# Service to deploy
parser.add_argument(
'--service',
action='store',
required=True,
help='Service to Deploy',
)
# UPF tag to deploy
parser.add_argument(
'--upf_tag',
action='store',
default='develop',
help='UPF tag to Deploy',
)
# Docker-compose file to use
parser.add_argument(
'--docker_compose',
action='store',
default='docker-compose.yml',
help='Docker-compose file to use (default: docker-compose.yml)',
)
# Mode
parser.add_argument(
'--mode',
action='store',
required=True,
choices=['Deploy', 'Check', 'UnDeploy'],
help='Mode',
)
return parser.parse_args()
def deployObject(service, tag):
logging.info ('Deploying ' + service)
os.chdir('docker-compose')
subprocess_run_w_echo ('ls')
def subprocess_run_w_echo(cmd):
logging.debug(cmd)
subprocess.run(cmd, shell=True)
if __name__ == '__main__':
main()
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