<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_rpm(ctx, target):
 """ build an RPM package """

    if target not in ('centos6', 'centos7'):
        print('Error: unknown target "{0}"!'.format(target), file=sys.stderr)
        sys.exit(1)

    os.chdir(PROJECT_DIR)
    rpmbuild_dir = os.path.join(DIST_DIR, 'rpmbuild')

    # Create directories layout
    ctx.run('mkdir -p {0}'.format(' '.join(os.path.join(rpmbuild_dir, d)
                                           for d in ('BUILD', 'RPMS', 'SOURCES', 'SPECS', 'SRPMS'))))

    # Copy the sources & spec file
    build_src(ctx, dest=os.path.join(rpmbuild_dir, 'SOURCES'))
    ctx.run('cp -f {0} {1}'.format(os.path.join(PROJECT_DIR, 'rpm/centos/mssh-copy-id.spec'),
                                   os.path.join(rpmbuild_dir, 'SPECS')))

    # Build the RPM
    ctx.run('docker run -e LOCAL_USER_ID={local_user_id} -v {local}:{cont} {img}'
            .format(local_user_id=os.getuid(),
                    local=rpmbuild_dir,
                    cont='/rpmbuild',
                    img=DOCKER_IMGS[target]['name']))

    ctx.run('mv -f {0} {1}'.format(os.path.join(rpmbuild_dir, 'RPMS/noarch/mssh-copy-id-*.rpm'), DIST_DIR))