def METHOD_NAME(args, cfg, job, script=None):
    s = ''
    s += 'FROM {}\n'.format(args.image or job['image'])
    s += 'SHELL [ "/bin/bash", "-c" ]\n'
    # do all ENV's in a single line to reduce intermediate images
    envs = []
    for k, v in cfg['variables'].items():
        envs.append('{}="{}"'.format(k, v))
    for k, v in job.get('variables', {}).items():
        envs.append('{}="{}"'.format(k, v))
    for e in args.env:
        if '=' in e:
            k, v = e.split('=', 1)
            envs.append('{}="{}"'.format(k, v))
        else:
            envs.append('{}=1'.format(e))
    if envs:
        s += 'ENV ' + '\\\n    '.join(envs) + '\n'
    if args.localtree:
        reclone = False
        # does it look like a git repo?  if so, just copy in .git and clone
        #  from that
        if os.path.isdir(os.path.join(args.localtree, '.git')):
            # check to see if HEAD is up to date with tree
            ret = subprocess.call([ 'git', '-C', args.localtree, 'diff-index', '--quiet', 'HEAD'])
            if ret == 0:
                reclone = True
            else:
                if args.localchanges == 'ignore':
                    print('WARNING: local tree looks like a git repository, but has uncommitted changes - ignoring them')
                    reclone = True
                elif args.localchanges == 'copy':
                    print('WARNING: local tree looks like a git repository, but has uncommitted changes - copying entire tree to be safe')
                else:
                    print('WARNING: local tree looks like a git repository, but has uncommitted changes - use -L {ignore,copy} to specify desired action')
                    exit(1)
        if reclone:
            args.localtree = os.path.join(args.localtree, '.git')
            s += 'COPY / localtree.git\n'
            s += 'RUN git clone localtree.git repo\n'
        else:
            # no?  just copy the whole thing in and hope for the best
            s += 'COPY / repo\n'
    else:
        s += 'RUN git clone -b {} {} repo\n'.format(args.branch, args.repo)
    s += 'WORKDIR "/repo"\n'
    if script:
        b64 = base64.b64encode(bytes(script, 'latin-1')).decode('latin-1')
        b64 = b64.replace('\n', '\\\n')
        s += 'RUN echo \\\n' + b64 + ' | base64 -d > /script.sh\n'
    else:
        s += 'COPY script.sh /\n'
    s += 'RUN chmod a+x /script.sh\n'
    if not args.noscript:
        s += 'RUN /script.sh\n'
    return s