Merge ~smoser/cloud-init:cleanup/tools-run-centos-use-git-clone into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: e9a3a02229c9569bda2529cf3abe0500dd0f1616
Merged at revision: a1ca220d137cf7b3f79b516980a042ec800a8d91
Proposed branch: ~smoser/cloud-init:cleanup/tools-run-centos-use-git-clone
Merge into: cloud-init:master
Diff against target: 149 lines (+76/-12)
1 file modified
tools/run-centos (+76/-12)
Reviewer Review Type Date Requested Status
Joshua Powers (community) Approve
Server Team CI bot continuous-integration Approve
cloud-init Commiters Pending
Review via email: mp+337499@code.launchpad.net

Commit message

tools: run-centos: only collect .git dir.

I have lots of files in my checkout dir. tar <dir> causes
all those files to get copied into the container.

This instead collects only the .git dir and then checks out
the branch inside the container. That means a lot less
disk IO, given that .tox/ can be 300M+ while .git is just
about 40M.

Description of the change

using 'git clone' makes this work from a worktree.
I couldnt' figure out how to easily find "the real .git" if inside a worktree.

Figuring that out, and then just using 'tar -cf .git' would avoid the local tmpdir copy

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

PASSED: Continuous integration, rev:bca132c1b66d7f9f53a2120b8155a984de4fd95f
https://jenkins.ubuntu.com/server/job/cloud-init-ci/767/
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/767/rebuild

review: Approve (continuous-integration)
Revision history for this message
Joshua Powers (powersj) wrote :

Did you push for the right branch? This looks like packaging of a new release.

Revision history for this message
Scott Moser (smoser) wrote :

Josh, yeah, I had wrong base branch.
that is fixed.

Also fixed, now we dont use a temp dir, so it is basically
  tar -cf .git | tar -xf

that means ~ 42M which is an improvement over the current solution.
Espeically when my .tox is now 316M.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:dd2a9f2c8e7b006e3dfee01e4ff5bde0e9e33613
https://jenkins.ubuntu.com/server/job/cloud-init-ci/768/
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/768/rebuild

review: Approve (continuous-integration)
Revision history for this message
Joshua Powers (powersj) wrote :

LGTM and tested locally seems to make execution go faster. Thanks!

review: Approve
Revision history for this message
Joshua Powers (powersj) wrote :

thinking about this some more, this will not pull in uncommitted code. Do we want to have a message print a warning to the user that they have uncommitted code and it won't be pulled in?

Revision history for this message
Scott Moser (smoser) wrote :

You're correct that it will not bring in un-committed code. I can address
that. I dont think its all that big of a deal really, the git work flow is
generally "git commit"... git ammend. other parts of cloud-init also do
not pick up uncommitted changes.

On Mon, Feb 12, 2018 at 11:51 AM, Joshua Powers <email address hidden>
wrote:

> thinking about this some more, this will not pull in uncommitted code. Do
> we want to have a message print a warning to the user that they have
> uncommitted code and it won't be pulled in?
> --
> https://code.launchpad.net/~smoser/cloud-init/+git/cloud-
> init/+merge/337499
> You are the owner of ~smoser/cloud-init:cleanup/tools-run-centos-use-git-
> clone.
>

Revision history for this message
Scott Moser (smoser) wrote :

Josh, please see new commit. I think this is sane.

On Mon, Feb 12, 2018 at 12:03 PM, Scott Moser <email address hidden>
wrote:

> You're correct that it will not bring in un-committed code. I can address
> that. I dont think its all that big of a deal really, the git work flow is
> generally "git commit"... git ammend. other parts of cloud-init also do
> not pick up uncommitted changes.
>
>
> On Mon, Feb 12, 2018 at 11:51 AM, Joshua Powers <<email address hidden>
> >
> wrote:
>
> > thinking about this some more, this will not pull in uncommitted code. Do
> > we want to have a message print a warning to the user that they have
> > uncommitted code and it won't be pulled in?
> > --
> > https://code.launchpad.net/~smoser/cloud-init/+git/cloud-
> > init/+merge/337499
> > You are the owner of ~smoser/cloud-init:cleanup/
> tools-run-centos-use-git-
> > clone.
> >
>
> --
> https://code.launchpad.net/~smoser/cloud-init/+git/cloud-
> init/+merge/337499
> You are the owner of ~smoser/cloud-init:cleanup/tools-run-centos-use-git-
> clone.
>

Revision history for this message
Joshua Powers (powersj) wrote :

LGTM thanks for this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tools/run-centos b/tools/run-centos
2index d58ef3e..6ac6c11 100755
3--- a/tools/run-centos
4+++ b/tools/run-centos
5@@ -23,6 +23,9 @@ Usage: ${0##*/} [ options ] version
6
7 options:
8 -a | --artifact keep .rpm artifacts
9+ --dirty apply local changes before running tests.
10+ If not provided, a clean checkout of branch is tested.
11+ Inside container, changes are in local-changes.diff.
12 -k | --keep keep container after tests
13 -r | --rpm build .rpm
14 -s | --srpm build .src.rpm
15@@ -80,25 +83,84 @@ inside() {
16 inject_cloud_init(){
17 # take current cloud-init git dir and put it inside $name at
18 # ~$user/cloud-init.
19- local name="$1" user="$2" top_d="" dname="" pstat=""
20- top_d=$(git rev-parse --show-toplevel) || {
21- errorrc "Failed to get git top level in $PWD";
22+ local name="$1" user="$2" dirty="$3"
23+ local changes="" top_d="" dname="cloud-init" pstat=""
24+ local gitdir="" commitish=""
25+ gitdir=$(git rev-parse --git-dir) || {
26+ errorrc "Failed to get git dir in $PWD";
27 return
28 }
29- dname=$(basename "${top_d}") || return
30- debug 1 "collecting ${top_d} ($dname) into user $user in $name."
31- tar -C "${top_d}/.." -cpf - "$dname" |
32+ local t=${gitdir%/*}
33+ case "$t" in
34+ */worktrees)
35+ if [ -f "${t%worktrees}/config" ]; then
36+ gitdir="${t%worktrees}"
37+ fi
38+ esac
39+
40+ # attempt to get branch name.
41+ commitish=$(git rev-parse --abbrev-ref HEAD) || {
42+ errorrc "Failed git rev-parse --abbrev-ref HEAD"
43+ return
44+ }
45+ if [ "$commitish" = "HEAD" ]; then
46+ # detached head
47+ commitish=$(git rev-parse HEAD) || {
48+ errorrc "failed git rev-parse HEAD"
49+ return
50+ }
51+ fi
52+
53+ local local_changes=false
54+ if ! git diff --quiet "$commitish"; then
55+ # there are local changes not committed.
56+ local_changes=true
57+ if [ "$dirty" = "false" ]; then
58+ error "WARNING: You had uncommitted changes. Those changes will "
59+ error "be put into 'local-changes.diff' inside the container. "
60+ error "To test these changes you must pass --dirty."
61+ fi
62+ fi
63+
64+ debug 1 "collecting ${gitdir} ($dname) into user $user in $name."
65+ tar -C "${gitdir}" -cpf - . |
66 inside_as "$name" "$user" sh -ec '
67 dname=$1
68+ commitish=$2
69 rm -Rf "$dname"
70+ mkdir -p $dname/.git
71+ cd $dname/.git
72 tar -xpf -
73- [ "$dname" = "cloud-init" ] || mv "$dname" cloud-init' \
74- extract "$dname"
75+ cd ..
76+ git config core.bare false
77+ out=$(git checkout $commitish 2>&1) ||
78+ { echo "failed git checkout $commitish: $out" 1>&2; exit 1; }
79+ out=$(git checkout . 2>&1) ||
80+ { echo "failed git checkout .: $out" 1>&2; exit 1; }
81+ ' extract "$dname" "$commitish"
82 [ "${PIPESTATUS[*]}" = "0 0" ] || {
83- error "Failed to push tarball of '$top_d' into $name" \
84+ error "Failed to push tarball of '$gitdir' into $name" \
85 " for user $user (dname=$dname)"
86 return 1
87 }
88+
89+ echo "local_changes=$local_changes dirty=$dirty"
90+ if [ "$local_changes" = "true" ]; then
91+ git diff "$commitish" |
92+ inside_as "$name" "$user" sh -exc '
93+ cd "$1"
94+ if [ "$2" = "true" ]; then
95+ git apply
96+ else
97+ cat > local-changes.diff
98+ fi
99+ ' insert_changes "$dname" "$dirty"
100+ [ "${PIPESTATUS[*]}" = "0 0" ] || {
101+ error "Failed to apply local changes."
102+ return 1
103+ }
104+ fi
105+
106 return 0
107 }
108
109@@ -179,7 +241,7 @@ delete_container() {
110
111 main() {
112 local short_opts="ahkrsuv"
113- local long_opts="artifact,help,keep,rpm,srpm,unittest,verbose"
114+ local long_opts="artifact,dirty,help,keep,rpm,srpm,unittest,verbose"
115 local getopt_out=""
116 getopt_out=$(getopt --name "${0##*/}" \
117 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
118@@ -188,11 +250,13 @@ main() {
119
120 local cur="" next=""
121 local artifact="" keep="" rpm="" srpm="" unittest="" version=""
122+ local dirty=false
123
124 while [ $# -ne 0 ]; do
125 cur="${1:-}"; next="${2:-}";
126 case "$cur" in
127 -a|--artifact) artifact=1;;
128+ --dirty) dirty=true;;
129 -h|--help) Usage ; exit 0;;
130 -k|--keep) KEEP=true;;
131 -r|--rpm) rpm=1;;
132@@ -231,7 +295,7 @@ main() {
133 inside "$name" useradd "$user"
134
135 debug 1 "inserting cloud-init"
136- inject_cloud_init "$name" "$user" || {
137+ inject_cloud_init "$name" "$user" "$dirty" || {
138 errorrc "FAIL: injecting cloud-init into $name failed."
139 return
140 }
141@@ -244,7 +308,7 @@ main() {
142
143 local errors=0
144 inside_as_cd "$name" "$user" "$cdir" \
145- sh -ec "git checkout .; git status" ||
146+ sh -ec "git status" ||
147 { errorrc "git checkout failed."; errors=$(($errors+1)); }
148
149 if [ -n "$unittest" ]; then

Subscribers

People subscribed via source and target branches