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: Raphael Defosseux <raphael.defosseux@eurecom.fr>
This commit is contained in:
@@ -55,7 +55,9 @@ pipeline {
|
|||||||
stage ("Push to DockerHub") {
|
stage ("Push to DockerHub") {
|
||||||
steps {
|
steps {
|
||||||
script {
|
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()
|
WEEK_TAG = WEEK_TAG.trim()
|
||||||
|
|
||||||
withCredentials([
|
withCredentials([
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
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()
|
||||||
Reference in New Issue
Block a user