def _modify_script(utils: Utils, jobpair: JobPair): for j in jobpair.jobs: script_path = join(utils.get_jobpair_dir(jobpair.jobs[0]), j.job_id + '.sh') if not isfile(script_path): log.error('Script file not found at', script_path) return 1 lines = [] with open(script_path) as f: found_cd_line = False for l in f: if r'travis_cmd cd\ ' + j.repo in l: found_cd_line = True lines.append(_replace_repo_path(j, l)) elif 'export TRAVIS_BUILD_DIR=$HOME/build/' in l: lines.append(_replace_repo_path(j, l)) else: lines.append(l) if not found_cd_line: raise ReproduceError('found_cd_line is False for {}'.format( j.job_id)) with open( join(utils.get_jobpair_dir(jobpair.jobs[0]), j.job_id + '-p.sh'), 'w') as f: for l in lines: f.write(l)
def _write_package_dockerfile(utils: Utils, jobpair: JobPair): failed_job_id = jobpair.jobs[0].job_id passed_job_id = jobpair.jobs[1].job_id failed_dockerfile_path = join(utils.get_jobpair_dir(jobpair.jobs[0]), failed_job_id + '-Dockerfile') passed_dockerfile_path = join(utils.get_jobpair_dir(jobpair.jobs[1]), passed_job_id + '-Dockerfile') with open(failed_dockerfile_path) as f: failed_lines = list(map(str.strip, f.readlines())) with open(passed_dockerfile_path) as f: passed_lines = list(map(str.strip, f.readlines())) # Check that both the failed job and the passed job used the same Travis Docker image. if failed_lines[0] != passed_lines[0]: raise ReproduceError( 'The failed job and the passed job used different Travis Docker images.' ) lines = [ failed_lines[0], # Remove PPA and clean APT 'RUN sudo rm -rf /var/lib/apt/lists/*', 'RUN sudo rm -rf /etc/apt/sources.list.d/*', 'RUN sudo apt-get clean', # Update OpenSSL and libssl to avoid using deprecated versions of TLS (TLSv1.0 and TLSv1.1). # TODO: Do we actually only want to do this when deriving from an image that has an out-of-date version of TLS? 'RUN sudo apt-get update && sudo apt-get install --only-upgrade openssl libssl-dev', # Add the repositories. 'ADD failed.tar /home/travis/build/failed/', 'ADD passed.tar /home/travis/build/passed/', # Add the original logs. 'ADD {}-orig.log /home/travis/build/'.format(failed_job_id), 'ADD {}-orig.log /home/travis/build/'.format(passed_job_id), 'RUN chmod 777 -R /home/travis/build', # Add the build scripts. 'ADD {}-p.sh /usr/local/bin/run_failed.sh'.format(failed_job_id), 'ADD {}-p.sh /usr/local/bin/run_passed.sh'.format(passed_job_id), 'RUN chmod +x /usr/local/bin/run_failed.sh', 'RUN chmod +x /usr/local/bin/run_passed.sh', # Set the user to use when running the image. 'USER travis', ] # Append a newline to each line and then concatenate all the lines. content = ''.join(map(lambda l: l + '\n', lines)) package_dockerfile = utils.get_abs_jobpair_dockerfile_path(jobpair) with open(package_dockerfile, 'w') as f: f.write(content)