Exemplo n.º 1
0
def main():
    """
    generate a package and upload it to artifactory
    """
    logger.info('creating archive')
    args = parse_cli()
    package_config = read_configuration(args.configuration_file)
    archive = create_archive(package_config)
    archive = os.path.basename(archive)
    logger.info('uploading archive {0}'.format(archive))
    config = read_configuration(DEFAULT_CONFIG_FILE)
    artifactory_config = config['artifactory']
    username = artifactory_config['username']
    username = username.replace('$CI_PROJECT_NAME',
                                os.environ['CI_PROJECT_NAME'])
    # pipeline.json contains the NAME of the variable
    # the actual password is stored within gitlab variables
    password = artifactory_config['password']
    password = password.replace('$ARTIFACTORY_PASSWORD',
                                os.environ['ARTIFACTORY_PASSWORD'])

    if password == 'Not defined':
        logger.warning('no password defined for artifactory')
    for url in artifactory_urls():
        url = url.replace('$CI_PROJECT_NAME', os.environ['CI_PROJECT_NAME'])
        artifactory.upload(url=url,
                           username=username,
                           password=password,
                           file_to_upload=archive)
Exemplo n.º 2
0
def deploy(config_file, environment, version):
    """
    The only function you want to call from main(). A nice cozy wrapper for the
    deployment operations, nothing more, nothing less.

    Args:
        config_file (str): path to the configuration file
        environment (str): the environment you're about to deploy

    Raises:
        PipelineError: something when wrong during this deployment, please
            file a bug
    """
    try:
        config = read_configuration(config_file=config_file, environment='deploy')
        config = config[environment]
        project_name = os.environ['CI_PROJECT_NAME']
    except KeyError as error:
        msg = "missing key in configuration! {0}".format(error)
        logger.error(msg)
        raise PipelineError(msg)
    kerberos.check(config)
    image_name = docker_image_name(environment)
    create_docker_configuration(config)
    dockerfile = dockerfile_path(config)
    create_docker_image(image_name, dockerfile)
    execute_deployment(config, image_name, version)
    mark_deployment_as_done(config, project_name)
Exemplo n.º 3
0
def main():
    args = parse_cli()
    stage = args.stage
    try:
        project_name = os.environ['CI_PROJECT_NAME']
    except KeyError:
        raise PipelineError('CI_PROJECT_NAME is not defilend')
    project_config = read_configuration(DEFAULT_CONFIG_FILE, 'build')
    steps = project_config[stage]['steps']

    for step in steps:
        logger.info('\nstep: {0}'.format(step))
        image_name = "{0}{1}".format(project_name,
                                     steps[step]['docker-image-suffix'])
        dockerfile = steps[step]['dockerfile']
        options = steps[step]['options']
        command = steps[step]['command']
        volumes = steps[step]['volumes']
        try:
            output = steps[step]['output']
        except KeyError:
            output = None
        docker.execute(image_name=image_name,
                       dockerfile=dockerfile,
                       options=options,
                       command=command,
                       volumes=volumes,
                       output=output)

    # if this is the package stage, we need to create an archive with our
    # php dependencies, and upload it to artifactory
    if stage == 'package':
        archive_and_upload()

    docker.cleanup_volumes('/app')
Exemplo n.º 4
0
def main():
    args = parse_cli()
    stage = args.stage
    try:
        project_name = os.environ['CI_PROJECT_NAME']
    except KeyError:
        raise PipelineError('CI_PROJECT_NAME is not defilend')
    project_config = read_configuration(DEFAULT_CONFIG_FILE)
    steps = project_config[stage]['steps']

    for step in steps:
        logger.info('\nstep: {0}'.format(step))
        image_name = "{0}{1}".format(project_name,
                                     steps[step]['docker-image-suffix'])
        dockerfile = steps[step]['dockerfile']
        options = steps[step]['options']
        command = steps[step]['command']
        volumes = steps[step]['volumes']
        try:
            output = steps[step]['output']
        except KeyError:
            output = None
        docker.execute(image_name=image_name,
                       dockerfile=dockerfile,
                       options=options,
                       command=command,
                       volumes=volumes,
                       output=output)
        docker.cleanup_volumes('/app')
Exemplo n.º 5
0
def signoff(config_file, environment):
    """
    The only function you want to call from main(). A nice cozy wrapper for the
    singoff operations, nothing more, nothing less.

    Args:
        config_file (str): path to the configuration file
        environment (str): the environment you're about to deploy
    """
    config = read_configuration(config_file=config_file,
                                environment=environment)
    user = kerberos.current_user_email()
    try:
        kerberos.check(config)
    except PipelineError as error:
        raise PipelineError(error)
    # user is authorized to trigger this job
    print('{0} signed off by: {1}'.format(SUCCESS, environment, user))
Exemplo n.º 6
0
def archive_and_upload():
    """
    generate a package and upload it to artifactory
    """
    logger.info('creating archive')
    archive = create_archive()
    archive = os.path.basename(archive)
    logger.info('uploading archive {0}'.format(archive))
    artifactory_config = read_configuration(DEFAULT_CONFIG_FILE, 'artifactory')
    username = artifactory_config['username']
    username = username.replace('$CI_PROJECT_NAME',
                                os.environ['CI_PROJECT_NAME'])
    # pipeline.json contains the NAME of the variable
    # the actual password is stored within gitlab variables
    password = artifactory_config['password']
    password = gitlab_var(password, default='Not defined')
    for url in artifactory_urls():
        url = url.replace('$CI_PROJECT_NAME', os.environ['CI_PROJECT_NAME'])
        artifactory.upload(url=url,
                           username=username,
                           password=password,
                           file_to_upload=archive)