Merge ~smoser/cloud-init:feature/reproducible-builds into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: 0f5d42898e423f89c9a13fa5a846926c2a719999
Merged at revision: 8f162b6603aefef400b784ab70dc57080978cffc
Proposed branch: ~smoser/cloud-init:feature/reproducible-builds
Merge into: cloud-init:master
Diff against target: 62 lines (+24/-1)
1 file modified
setup.py (+24/-1)
Reviewer Review Type Date Requested Status
Ryan Harper Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+334991@code.launchpad.net

Commit message

setup.py: Do not include rendered files in SOURCES.txt

cloud-init renders template files during its run of setup.py.
Those rendered files were in a temp dir and were making their
way into the SOURCES.txt file.

We do not want to include those, so here we explicitly prune them out.

The issue of SOURCES.txt containing tmp files was reproducible with:
  $ rm -Rf cloud_init.egg-info
  $ git clean --force
  $ rm -Rf ../root.d; python3 setup.py install --root=../root.d
  $ grep ^tmp cloud_init.egg-info/SOURCES.txt

The SOURCES.txt under ../root.d/ would have tmp files.

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:0f5d42898e423f89c9a13fa5a846926c2a719999
https://jenkins.ubuntu.com/server/job/cloud-init-ci/602/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/602/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

I reproduced the issue with your script, applied the patch from this branch and it's fixed.

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/setup.py b/setup.py
2index bf697d7..bc3f52a 100755
3--- a/setup.py
4+++ b/setup.py
5@@ -18,11 +18,14 @@ import tempfile
6
7 import setuptools
8 from setuptools.command.install import install
9+from setuptools.command.egg_info import egg_info
10
11 from distutils.errors import DistutilsArgError
12
13 import subprocess
14
15+RENDERED_TMPD_PREFIX = "RENDERED_TEMPD"
16+
17
18 def is_f(p):
19 return os.path.isfile(p)
20@@ -107,7 +110,7 @@ def render_tmpl(template):
21 return template
22
23 topdir = os.path.dirname(sys.argv[0])
24- tmpd = tempfile.mkdtemp(dir=topdir)
25+ tmpd = tempfile.mkdtemp(dir=topdir, prefix=RENDERED_TMPD_PREFIX)
26 atexit.register(shutil.rmtree, tmpd)
27 bname = os.path.basename(template).rstrip(tmpl_ext)
28 fpath = os.path.join(tmpd, bname)
29@@ -156,6 +159,25 @@ elif os.path.isfile('/etc/redhat-release'):
30 USR_LIB_EXEC = "usr/libexec"
31
32
33+class MyEggInfo(egg_info):
34+ """This makes sure to not include the rendered files in SOURCES.txt."""
35+
36+ def find_sources(self):
37+ ret = egg_info.find_sources(self)
38+ # update the self.filelist.
39+ self.filelist.exclude_pattern(RENDERED_TMPD_PREFIX + ".*",
40+ is_regex=True)
41+ # but since mfname is already written we have to update it also.
42+ mfname = os.path.join(self.egg_info, "SOURCES.txt")
43+ if os.path.exists(mfname):
44+ with open(mfname) as fp:
45+ files = [f for f in fp
46+ if not f.startswith(RENDERED_TMPD_PREFIX)]
47+ with open(mfname, "w") as fp:
48+ fp.write(''.join(files))
49+ return ret
50+
51+
52 # TODO: Is there a better way to do this??
53 class InitsysInstallData(install):
54 init_system = None
55@@ -229,6 +251,7 @@ if os.uname()[0] != 'FreeBSD':
56 # adding on the right init system configuration files
57 cmdclass = {
58 'install': InitsysInstallData,
59+ 'egg_info': MyEggInfo,
60 }
61
62 requirements = read_requires()

Subscribers

People subscribed via source and target branches