Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-3913

Problems with cfbs and masterfiles prepare.sh

    XMLWordPrintable

    Details

      Description

      I am having an issue with how cfbs build sets version when it builds masterfiles. It's taking on a commit SHA if I am under some git directory. This SHA is not from the masterfiles repo and it results in the default target version for self upgrade being set to a version that includes this SHA making it invalid. If I am not under a git directory then I do not get this SHA appended.

      Notable Information

      cfbs --version
      
      cfbs 1.2.1
      • I use version in body common control as a signal about what version of the MPF someone is using. It's not 100% useful for that, I know some users alter this string to refer to their own versioning.

      What happens when NOT under a git directory

      Let's see what happens when I cfbs from a directory that is not under git.

      Shell command
      rm -rf /tmp/cfbs; mkdir -p /tmp/cfbs
      cd /tmp/cfbs 
      cfbs init 
      cfbs add masterfiles 
      cfbs build 
      grep -PR '\s+version =>|\"current_version\"\s+string' out/masterfiles
      

      In the following output we can see that the version gets set to 3.20.0.

      Initialized - edit name and description cfbs.json
      To add your first module, type: cfbs add masterfiles
      Added module: masterfiles
      
      Modules:
      001 masterfiles @ f3a8f65e77428a6ab9d62c34057a7ace6ae54ce9 (Downloaded)
      
      Steps:
      001 masterfiles : run './prepare.sh -y'
      001 masterfiles : copy './' 'masterfiles/'
      
      Generating tarball...
      
      Build complete, ready to deploy 🐿
       -> Directory: out/masterfiles
       -> Tarball:   out/masterfiles.tgz
      
      To install on this machine: cfbs install
      To deploy on remote hub(s): cf-remote deploy --hub hub out/masterfiles.tgz
      out/masterfiles/controls/update_def.cf:      "current_version" string => "3.20.0";
      out/masterfiles/standalone_self_upgrade.cf:      version => "CFEngine Standalone Self Upgrade 3.20.0";
      out/masterfiles/update.cf:      version => "update.cf $(update_def.current_version)";
      out/masterfiles/promises.cf:      version => "CFEngine Promises.cf 3.20.0";
      

      I am not sure if this is okay. The masterfiles module may get a different commit SHA and be updated but the built policy will still indicate 3.20.0 when in fact it is not 3.20.0.

      What happens when under a git directory

      Let's see what happens when I cfbs from a directory that is under git.

      Shell command
      rm -rf /tmp/cfbs; mkdir -p /tmp/cfbs
      cd /tmp/cfbs 
      git init 
      cfbs init 
      git add cfbs.json 
      cfbs add masterfiles 
      git commit -m "cfbs added masterfiles" 
      cfbs build 
      grep -PR '\s+version =>|\"current_version\"\s+string' out/masterfiles
      

      In the output we can see that a commit SHA was added on to the version string.

      Initialized empty Git repository in /tmp/cfbs/.git/
      Initialized - edit name and description cfbs.json
      To add your first module, type: cfbs add masterfiles
      Added module: masterfiles
      [master (root-commit) df9c6ac] cfbs added masterfiles
       1 file changed, 6 insertions(+)
       create mode 100644 cfbs.json
      
      Modules:
      001 masterfiles @ f3a8f65e77428a6ab9d62c34057a7ace6ae54ce9 (Downloaded)
      
      Steps:
      001 masterfiles : run './prepare.sh -y'
      001 masterfiles : copy './' 'masterfiles/'
      
      Generating tarball...
      
      Build complete, ready to deploy 🐿
       -> Directory: out/masterfiles
       -> Tarball:   out/masterfiles.tgz
      
      To install on this machine: cfbs install
      To deploy on remote hub(s): cf-remote deploy --hub hub out/masterfiles.tgz
      out/masterfiles/controls/update_def.cf:      "current_version" string => "3.20.0a.df9c6ac4e";
      out/masterfiles/standalone_self_upgrade.cf:      version => "CFEngine Standalone Self Upgrade 3.20.0a.df9c6ac4e";
      out/masterfiles/update.cf:      version => "update.cf $(update_def.current_version)";
      out/masterfiles/promises.cf:      version => "CFEngine Promises.cf 3.20.0a.df9c6ac4e";
      

      This commit SHA is the commit SHA of my cfbs project dir HEAD. It comes from misc/determine-version.sh.

      Problems:

      • This makes the default version for standalone self upgrade invalid
      • The SHA doesn't relate to any SHA in masterfiles
        • This might be OK in some regard. It's the version of the built policy if the built policy is from a fully commited change set. E.g. i didnt do cfbs add and then cfbs build before git commit the change from cfbs add.

      Potential Fix

      A potential fix suggested by Craig Comstock is to set GIT_DIR to ../ in determine-version.sh

      For example:

      # Get the current commit SHA (HEAD):
      current_sha=$(export GIT_DIR="../"; git rev-parse HEAD)
      

      This change does prevent the commit sha from being injected, but I am uncertain if that is the correct thing to do.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            a10042 Nick Anderson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: