Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to checkout tags via pihole checkout #5259

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

yubiuser
Copy link
Member

@yubiuser yubiuser commented Apr 21, 2023

What does this PR aim to accomplish?:

Allow to checkout specific tags via pihole checkout for core and web. So far only branches were allowed.

P.S. Checking out tags for FTLwas possible already (as we don't download via git repo but a binary directly from our own server).

How does this PR accomplish the above?:

  1. Fetch with --tags added when getting upstream references.
  2. When performing a "checkout" we check the upstream repo if the requested ref is a branch or a tag and depending on that we create a new branch with or without --tracking set (which is set by default when using checkout without -b/B)
  3. "Guard" all git pull executions by first checking if the current branch is a branch or tag upstreams and skipping the pull in the latter case (does not make any sense to pull in case we checked out a tag)
  4. Moves all relevant functions from basic-install.sh to piholeCheckout.sh as they have been used only there and nowhere else.

By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

@rdwebdesign
Copy link
Member

rdwebdesign commented Apr 21, 2023

I tried the branch (I know it's still a draft).

This is the current output:

root@pihole:/# pihole checkout web v5.15          
  Please note that changing branches or tags severely alters your Pi-hole subsystems
  Features that work on the master branch, may not on a development branch
  This feature is NOT supported unless a Pi-hole developer explicitly asks!
  Have you read and understood this? [y/N] y

  [✓] Fetching branches/tags from https://github.com/pi-hole/AdminLTE.git
  [i] 127 branches/tags available for Web Admin

  [✓] Switching to branch/tag: 'v5.15' from 'refs/heads/devel'
You are not currently on a branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

The tag was correctly used:

root@pihole:/var/www/html/admin# git status
HEAD detached at v5.15
nothing to commit, working tree clean

But pihole -v still shows the branch devel and the original commit:

root@pihole:/var/www/html/admin# pihole -v
  Pi-hole version is checkout/tags v5.15.5-81-g6d2ceca6 (Latest: v5.16.2)
  AdminLTE version is devel v5.19-33-gefddf9c7 (Latest: v5.19)
  FTL version is development vDev-b0bf9c0 (Latest: v5.22)

EDIT:
After executing pihole updatechecker the tag is shown correctly:

root@pihole:/var/www/html/admin# pihole updatechecker
root@pihole:/var/www/html/admin# pihole -v                
  Pi-hole version is checkout/tags v5.15.5-81-g6d2ceca6 (Latest: v5.16.2)
  AdminLTE version is HEAD v5.15 (Latest: v5.19)
  FTL version is development vDev-b0bf9c0 (Latest: v5.22)

rdwebdesign
rdwebdesign previously approved these changes Apr 22, 2023
advanced/Scripts/piholeCheckout.sh Outdated Show resolved Hide resolved
@yubiuser yubiuser marked this pull request as ready for review April 23, 2023 10:16
@yubiuser yubiuser marked this pull request as draft April 23, 2023 10:17
Signed-off-by: Christian König <[email protected]>
Signed-off-by: Christian König <[email protected]>
@yubiuser
Copy link
Member Author

This PR needed more changes than I thought. I squashed and forced push, now there are two commits: the first includes all necessary changes (for easier review) and the second moves the relevant functions from basic-install.sh to piholeCheckout.sh.
I'll adjust the PR message to explain all changes. The PR should be ready now for testing.

@yubiuser yubiuser marked this pull request as ready for review April 23, 2023 12:13
@yubiuser yubiuser requested review from a team and rdwebdesign April 23, 2023 12:13
@yubiuser yubiuser added Testing Required PR: Approval Required Open Pull Request, needs approval labels Apr 23, 2023
@yubiuser yubiuser marked this pull request as draft May 4, 2023 20:16
Signed-off-by: Christian König <[email protected]>
@yubiuser yubiuser marked this pull request as ready for review May 5, 2023 12:51
Copy link
Member

@DL6ER DL6ER left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really very minor criticism at this point (only two typos). I will have to test this in on a new install with a shallow cloned repository to be meaningful

advanced/Scripts/update.sh Outdated Show resolved Hide resolved
automated install/basic-install.sh Outdated Show resolved Hide resolved
Co-authored-by: DL6ER <[email protected]>
Signed-off-by: yubiuser <[email protected]>
Copy link
Member

@DL6ER DL6ER left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I did during review was creating a fresh VM and installing latest Pi-hole on it. Then I replaced the files in ´/opt/pihole` with the versions proposed in this PR.

Then, I tried pihole checkout web v5.18:
Screenshot from 2023-05-12 10-18-28

Seems to work fine.

Then I repeated this for core (where v5.18 does not exist), and this seems to work, too:
Screenshot from 2023-05-12 10-19-15
(cropped screenshot)

This also revealed some interesting tag that does not show up on Github:
Screenshot from 2023-05-12 10-21-56

All in all this seems to be doing what it supposed to do. I don't think we'll be able to anticipate any possible user system (mis)configuration but for a plain simple-and-easy standard installation, this seems to work fine.

As changing the update.sh script has the potential to break things in a bad way, I'd liek to ask @dschaper for his opinion. The change in this script is small.

Comment on lines +61 to +66
# check if the local branch ref is a branch or a tag on remote repo
if git show-ref -q --verify "refs/remotes/origin/$curBranch" 2>/dev/null; then
ref_is_tag=false
elif git show-ref -q --verify "refs/tags/$curBranch" 2>/dev/null; then
ref_is_tag=true
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no else here, what happens if neither of the two are true? ref_is_tag seems to stay random in this case (empty, likely). Can this happen? (I'm thinking about users doing local changes and committing them so the head is not pointing to anything on origin and also isn't a tag)

Comment on lines +482 to +486
if git show-ref -q --verify "refs/remotes/origin/$curBranch" 2>/dev/null; then
ref_is_branch=true
elif git show-ref -q --verify "refs/tags/$curBranch" 2>/dev/null; then
ref_is_branch=false
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment in update.sh, this is the same code.

@DL6ER
Copy link
Member

DL6ER commented May 12, 2023

Well, I hit [Comment] too soon. I did try to checkout the latest tag (coming from most recent master) but this failed:

root@ubuntu-s-4vcpu-8gb-fra1-01:/etc/.pihole# pihole checkout core v5.16.2
  Please note that changing branches or tags severely alters your Pi-hole subsystems
  Features that work on the master branch, may not on a development branch
  This feature is NOT supported unless a Pi-hole developer explicitly asks!
  Have you read and understood this? [y/N] y

  [✓] Fetching branches/tags from https://github.com/pi-hole/pi-hole.git
  [i] 122 branches/tags available for Pi-hole Core

  [✓] Switching to branch/tag: 'v5.16.2' from 'refs/heads/master'
  [i] Running installer to upgrade your installation

  [✓] Root user check

        .;;,.
        .ccccc:,.
         :cccclll:.      ..,,
          :ccccclll.   ;ooodc
           'ccll:;ll .oooodc
             .;cll.;;looo:.
                 .. ','.
                .',,,,,,'.
              .',,,,,,,,,,.
            .',,,,,,,,,,,,....
          ....''',,,,,,,'.......
        .........  ....  .........
        ..........      ..........
        ..........      ..........
        .........  ....  .........
          ........,,,,,,,'......
            ....',,,,,,,,,,,,.
               .',,,,,,,,,'.
                .',,,,,,'.
                  ..'''.

  [i] SELinux not detected
  [✓] Update local cache of available packages
  [i] Existing PHP installation detected : PHP version 8.1.2-1ubuntu2.11

  [✓] Checking apt-get for upgraded packages... 49 updates available
  [i] It is recommended to update your OS after installing the Pi-hole!

  [i] Checking for / installing Required dependencies for OS Check...
  [✓] Checking for grep
  [✓] Checking for dnsutils

  [✓] Supported OS detected
  [i] Checking for / installing Required dependencies for this install script...
  [✓] Checking for git
  [✓] Checking for iproute2
  [✓] Checking for dialog
  [✓] Checking for ca-certificates

  [i] Performing unattended setup, no dialogs will be displayed
  [✓] Check for existing repository in /etc/.pihole
  [i] Update repo in /etc/.pihole...
  : Could not update local repository. Contact support.
   Error: Unable to complete update, please contact support
root@ubuntu-s-4vcpu-8gb-fra1-01:/etc/.pihole# git status
On branch v5.16.2
nothing to commit, working tree clean
root@ubuntu-s-4vcpu-8gb-fra1-01:/etc/.pihole# git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/<branch> v5.16.2

@yubiuser
Copy link
Member Author

The failure is expected as you only replaced the files in /opt/pihole but not the local repo in /etc/.pihole. We call the installer from the repo after checkout of core

echo -e " ${INFO} Running installer to upgrade your installation"
if "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh" --unattended; then

The old file is missing the handling of tags

# only pull if we are on a branch not a tag
if [ "$ref_is_branch" = true ]; then
# Pull the latest commits
git pull --no-rebase --quiet &> /dev/null || return $?
fi

@DL6ER
Copy link
Member

DL6ER commented May 12, 2023

I also replaced them in the repo (and committed that to master to not be in a dirty state), but this was obviously overwritten with

  [✓] Switching to branch/tag: 'v5.16.2' from 'refs/heads/master'
  [i] Running installer to upgrade your installation

So is this a general issue here? Whenever users will want to checkout something before (the coming) v5.17 possibly including this, they will always run the installer that is not aware of tags or am I mistaken here?

@yubiuser
Copy link
Member Author

I fear you are right. Checking out any tag before this is merged and tagged will fail on core because the handing of tags obviously was not implemented back then.
How to proceed? We could prevent checking out tags before 5.17?

@DL6ER
Copy link
Member

DL6ER commented May 13, 2023

We could prevent checking out tags before 5.17?

I'd say it depends on how much code would be required to do this. We could also simply show an additional warning when we detect that users try to checkout core + tag telling them that below v5.17 won't work and giving the option to cancel without actually doing anything [y/N] at this point

@yubiuser
Copy link
Member Author

It would be quite some code.... I tried yesterday: we would separate getting branches and tags, convert the tags to numbers (could re-use some code from PADD) and only include tags above a certain number.

@yubiuser
Copy link
Member Author

pi@s740:~$ pihole checkout core v5.9.1
  Please note that changing branches or tags severely alters your Pi-hole subsystems
  Features that work on the master branch, may not on a development branch
  This feature is NOT supported unless a Pi-hole developer explicitly asks!
  Have you read and understood this? [y/N] y

  [✓] Fetching branches/tags from https://github.com/pi-hole/pi-hole.git
  [i] 122 branches/tags available for Pi-hole Core

  [i] Switching to branch/tag: 'v5.9.1' from 'refs/heads/checkout/tags'

  [i] Your are trying to checkout the tag v5.9.1 on the core repo
  Please note that checking out core tags <v5.17  will break your local repo 
  Proceed anyway? [y/N] 

@DL6ER DL6ER requested a review from dschaper May 14, 2023 07:19
@pralor-bot
Copy link

This pull request has been mentioned on Pi-hole Userspace. There might be relevant details there:

https://discourse.pi-hole.net/t/how-do-i-revert-to-a-previous-version-of-pi-hole/7168/28

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Approval Required Open Pull Request, needs approval Testing Required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants