add version support in env

This commit is contained in:
yhua 2016-09-05 15:45:36 +08:00
parent 18015ed05a
commit 3ae4b71c9a
2 changed files with 12 additions and 11 deletions

View File

@ -7,6 +7,7 @@ import string
import os
import sys
import argparse
import commands
from io import open
if sys.version_info[:3][0] == 2:
@ -17,10 +18,6 @@ if sys.version_info[:3][0] == 3:
import configparser as ConfigParser
import io as StringIO
def validate(conf):
if len(conf.get("configuration", "secret_key")) != 16:
raise Exception("Error: The length of secret key has to be 16 characters!")
parser = argparse.ArgumentParser()
parser.add_argument('-conf', dest='cfgfile', default = 'harbor.cfg',type=str,help="the path of Harbor configuration file")
args = parser.parse_args()
@ -33,8 +30,6 @@ conf.seek(0, os.SEEK_SET)
rcp = ConfigParser.RawConfigParser()
rcp.readfp(conf)
validate(rcp)
hostname = rcp.get("configuration", "hostname")
ui_url = rcp.get("configuration", "ui_url_protocol") + "://" + hostname
email_server = rcp.get("configuration", "email_server")
@ -61,9 +56,16 @@ crt_email = rcp.get("configuration", "crt_email")
max_job_workers = rcp.get("configuration", "max_job_workers")
token_expiration = rcp.get("configuration", "token_expiration")
verify_remote_cert = rcp.get("configuration", "verify_remote_cert")
secret_key = rcp.get("configuration", "secret_key")
########
#Read version form .git
status, output = commands.getstatusoutput('git describe --tags')
if status == 0:
version = output
else:
version = 'UNKNOWN'
#######
ui_secret = ''.join(random.choice(string.ascii_letters+string.digits) for i in range(16))
base_dir = os.path.dirname(__file__)
@ -114,9 +116,9 @@ render(os.path.join(templates_dir, "ui", "env"),
self_registration=self_registration,
use_compressed_js=use_compressed_js,
ui_secret=ui_secret,
secret_key=secret_key,
verify_remote_cert=verify_remote_cert,
token_expiration=token_expiration)
token_expiration=token_expiration,
version=version)
render(os.path.join(templates_dir, "ui", "app.conf"),
ui_conf,
@ -141,7 +143,6 @@ render(os.path.join(templates_dir, "jobservice", "env"),
db_password=db_password,
ui_secret=ui_secret,
max_job_workers=max_job_workers,
secret_key=secret_key,
ui_url=ui_url,
verify_remote_cert=verify_remote_cert)

View File

@ -12,7 +12,6 @@ AUTH_MODE=$auth_mode
LDAP_URL=$ldap_url
LDAP_BASE_DN=$ldap_basedn
UI_SECRET=$ui_secret
SECRET_KEY=$secret_key
SELF_REGISTRATION=$self_registration
USE_COMPRESSED_JS=$use_compressed_js
LOG_LEVEL=debug
@ -21,3 +20,4 @@ EXT_ENDPOINT=$ui_url
TOKEN_URL=http://ui
VERIFY_REMOTE_CERT=$verify_remote_cert
TOKEN_EXPIRATION=$token_expiration
VERSION=$version