Commit a02adbdc authored by Raphael Defosseux's avatar Raphael Defosseux

feat(ci): mechanism to create multiple unique tags per week

  -- In case we do multiple merges per week
  -- Also use the proper week numbering (ISO week number, with Monday as first day of week (01..53))
Signed-off-by: default avatarRaphael Defosseux <raphael.defosseux@eurecom.fr>
parent dab954d7
......@@ -55,7 +55,9 @@ pipeline {
stage ("Push to DockerHub") {
steps {
script {
WEEK_TAG = sh returnStdout: true, script: 'date +"%Y.w%U"'
WEEK_REF = sh returnStdout: true, script: 'date +"%Y.w%V"'
WEEK_REF = WEEK_REF.trim()
WEEK_TAG = sh returnStdout: true, script: 'python3 ./ci-scripts/provideUniqueImageTag.py --start_tag ' + WEEK_REF
WEEK_TAG = WEEK_TAG.trim()
withCredentials([
......
import argparse
import os
import re
import subprocess
import sys
AUTH_SERVICE = 'registry.docker.io'
AUTH_SCOPE = 'repository:rdefosseoai/oai-enb:pull'
def main() -> None:
args = _parse_args()
cmd = 'curl -fsSL "https://auth.docker.io/token?service=' + AUTH_SERVICE + '&scope=' + AUTH_SCOPE + '" | jq --raw-output ".token"'
token = subprocess.check_output(cmd, shell=True, universal_newlines=True)
token = str(token).strip()
cmd = 'curl -fsSL -H "Authorization: Bearer ' + token + '" "https://index.docker.io/v2/rdefosseoai/oai-enb/tags/list" | jq .'
listOfTags = subprocess.check_output(cmd, shell=True, universal_newlines=True)
foundTag = False
for tag in listOfTags.split('\n'):
if re.search('"' + args.start_tag + '"', tag) is not None:
foundTag = True
if not foundTag:
print (args.start_tag)
sys.exit(0)
proposedVariants = ['a', 'b', 'c', 'd']
for variant in proposedVariants:
foundTag = False
currentVariant = variant
for tag in listOfTags.split('\n'):
if re.search('"' + args.start_tag + variant + '"', tag) is not None:
foundTag = True
break
if not foundTag:
break
if not foundTag:
print (args.start_tag + currentVariant)
def _parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description='Provides an unique new image tag for DockerHub')
parser.add_argument(
'--start_tag', '-st',
action='store',
required=True,
help='Proposed Starting Tag',
)
return parser.parse_args()
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