Merge ~smoser/usd-importer:fix/1749609-build-non-1000 into usd-importer:master

Proposed by Scott Moser on 2018-09-10
Status: Merged
Merged at revision: 772811277a5bd7a02f8dbee719e53c6b20ed5221
Proposed branch: ~smoser/usd-importer:fix/1749609-build-non-1000
Merge into: usd-importer:master
Diff against target: 148 lines (+38/-52)
1 file modified
gitubuntu/build.py (+38/-52)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve on 2018-09-18
Karl Stenerud (community) 2018-09-12 Approve on 2018-09-13
Robie Basak 2018-09-10 Pending
Review via email: mp+354634@code.launchpad.net

Commit message

Fix 'git ubuntu build' when user id does not match container user id.

If the user running 'git ubuntu build' did not have the same user-id
as the user 'ubuntu' inside the container, then the build would fail.
This fixes the specific issue.

The changes along the way are:
a.) builds as 'build-user' rather than 'ubuntu'.
    A consistent distro-nuetral user just seems to make more sense.
b.) build in /home/build-user/buildd rather than /tmp/.
    This seems cleaner as other no other system processes will be
    adding or removing files from that directory.

LP: #1749609

Description of the change

see commit message

To post a comment you must log in.

FAILED: Continuous integration, rev:fa40cb0db81680d20e2b48401797c90489c59bea
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/25/
Executed test runs:
    FAILED: VM Setup

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/25/rebuild

review: Needs Fixing (continuous-integration)
Joshua Powers (powersj) wrote :

Ignore the bot, he is still not 100% working due to proxy issues.

PASSED: Continuous integration, rev:fa40cb0db81680d20e2b48401797c90489c59bea
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/27/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/27/rebuild

review: Approve (continuous-integration)
Scott Moser (smoser) wrote :

@Karl,
Since you reported/re-reported this issue, I wonder if you could test to see if this fixes your problem.

Heres how to test:

 $ git clone https://git.launchpad.net/~smoser/usd-importer
 $ cd usd-importer
 $ git checkout fix/1749609-build-non-1000
 $ PATH=$PWD/bin:$PATH
 $ cd ..
 $ git ubuntu clone postfix
 $ cd postfix
 $ git ubuntu build --verbose --lxd-image=ubuntu-daily:bionic

We currently need to tell it to build in bionic (--lxd-image=ubuntu-daily:bionic) just because of bug 1791691.

I've done the above test locally, but it'd be good to make sure it also fixes the problem for you.

I *have* gone through the above

Karl Stenerud (kstenerud) wrote :

Works for me! Thanks!

review: Approve

PASSED: Continuous integration, rev:772811277a5bd7a02f8dbee719e53c6b20ed5221
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/29/
Executed test runs:
    SUCCESS: VM Setup
    SUCCESS: Build
    SUCCESS: Unit Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/29/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/gitubuntu/build.py b/gitubuntu/build.py
index b7ea657..5e892e0 100644
--- a/gitubuntu/build.py
+++ b/gitubuntu/build.py
@@ -957,6 +957,8 @@ def do_build_lxd_exitstack(
957 raise RuntimeError("LXD running?") from e957 raise RuntimeError("LXD running?") from e
958958
959 container_name = petname.Generate(2, '-')959 container_name = petname.Generate(2, '-')
960 user = 'buildd'
961 buildd = "/home/%s/build" % user
960962
961 args = ['launch', '-e']963 args = ['launch', '-e']
962 if profile:964 if profile:
@@ -1019,61 +1021,50 @@ def do_build_lxd_exitstack(
1019 "Failed to run apt-get in ephemeral build container"1021 "Failed to run apt-get in ephemeral build container"
1020 )1022 )
10211023
1024 input_files = [archive_tarball_name] + tarballs
1025 try:
1026 _run_in_lxd(container_name, ['mkdir', '-p', buildd], user=user)
1027 except Exception as e:
1028 raise RuntimeError(
1029 "Failed creating '%s' as user '%s' in container '%s'" %
1030 (buildd, user, container_name)) from e
1031
1032 logging.debug("container=%s build_dir=%s user=%s",
1033 container_name, buildd, user)
1034
1022 try:1035 try:
1023 run_lxc(1036 run_lxc(
1024 [1037 ['file', 'push'] + input_files +
1025 'file',1038 ['%s/%s/' % (container_name, buildd)])
1026 'push',
1027 archive_tarball_name,
1028 '%s/tmp/' % container_name,
1029 ],
1030 )
1031 except Exception as e:1039 except Exception as e:
1032 raise RuntimeError(1040 raise RuntimeError(
1033 "Failed to push archive tarball to ephemeral build container"1041 "Failed to push archive tarball to ephemeral build container"
1034 ) from e1042 ) from e
10351043
1036 args = ['file', 'push']1044 logging.info(
1037 args.extend(tarballs)1045 "Copied build files to %s %s: %s",
1038 args.extend(['%s/tmp/' % container_name,])1046 container_name, buildd,
1039 try:1047 [os.path.basename(f) for f in input_files])
1040 run_lxc(args)
1041 except Exception as e:
1042 raise RuntimeError("Failed to push orig tarballs to container") from e
10431048
1044 logging.info("Copied build files to %s", container_name)1049 _run_in_lxd(container_name, ['chown', '--recursive', user, buildd])
10451050
1046 try:1051 try:
1047 _run_in_lxd(1052 _run_in_lxd(
1048 container_name,1053 container_name,
1049 [1054 [
1050 'tar',1055 'tar',
1051 'zxCf',1056 'zxCf',
1052 '/tmp',1057 buildd,
1053 '/tmp/%s' % os.path.basename(archive_tarball_name),1058 '%s/%s' % (buildd, os.path.basename(archive_tarball_name)),
1054 ],1059 ],
1055 user='ubuntu',1060 user=user,
1056 )1061 )
1057 except Exception as e:1062 except Exception as e:
1058 raise RuntimeError(1063 raise RuntimeError(
1059 "Failed to untar archive tarball in container"1064 "Failed to untar archive tarball in container"
1060 ) from e1065 ) from e
10611066
1062 stdout, _ = _run_in_lxd(1067 container_path = buildd + '/%s-%s' % (
1063 container_name,
1064 ['ls', '/tmp',],
1065 user='ubuntu',
1066 )
1067 orig_temp_contents = set(
1068 filename_stripped
1069 for filename_stripped in (
1070 filename.strip() for filename in
1071 stdout.splitlines()
1072 )
1073 if filename_stripped
1074 )
1075
1076 container_path = '/tmp/%s-%s' % (
1077 changelog.srcpkg,1068 changelog.srcpkg,
1078 changelog.version,1069 changelog.version,
1079 )1070 )
@@ -1113,36 +1104,31 @@ def do_build_lxd_exitstack(
1113 ' '.join(rem_args),1104 ' '.join(rem_args),
1114 ),1105 ),
1115 ],1106 ],
1116 user='ubuntu',1107 user=user,
1117 )1108 )
1118 except Exception as e:1109 except Exception as e:
1119 raise RuntimeError("dpkg-buildpackage failed in the container") from e1110 raise RuntimeError("dpkg-buildpackage failed in the container") from e
11201111
1121 stdout, _ = _run_in_lxd(1112 ls_out, _ = _run_in_lxd(
1122 container_name,1113 container_name, ['ls', buildd], user=user)
1123 ['ls', '/tmp',],1114 new_contents = [f for f in ls_out.splitlines() if f]
1124 user='ubuntu',1115 built_contents = (
1125 )1116 set(new_contents) - set([os.path.basename(i) for i in input_files]) -
1126 new_temp_contents = set(1117 set((os.path.basename(container_path),)))
1127 filename_stripped1118 if not built_contents:
1128 for filename_stripped in (1119 raise RuntimeError("No new files in build dir. build failed?")
1129 filename.strip() for filename in1120 logging.debug("Build produced files: %s" % built_contents)
1130 stdout.splitlines()
1131 )
1132 if filename_stripped
1133 )
11341121
1135 built_temp_contents = new_temp_contents - orig_temp_contents
1136 args = ['file', 'pull']1122 args = ['file', 'pull']
1137 args.extend([1123 args.extend([
1138 '%s%s' % (container_name, os.path.join('/tmp', f))1124 '%s%s' % (container_name, os.path.join(buildd, f))
1139 for f in built_temp_contents1125 for f in built_contents
1140 ]1126 ]
1141 )1127 )
1142 args.extend([os.pardir,])1128 args.extend([os.pardir,])
1143 run_lxc(args)1129 run_lxc(args)
11441130
1145 return [os.path.join(os.pardir, f) for f in built_temp_contents]1131 return [os.path.join(os.pardir, f) for f in built_contents]
11461132
11471133
1148def fetch_orig(1134def fetch_orig(

Subscribers

People subscribed via source and target branches