Skip to content

Conversation

yubiuser
Copy link
Member

Builds upon #1866.

Instead of cloning master with depth of 5 and checking out the lastest tag 'backwards' we now checkout the tag directly. To fool the version script we need to fake checkout 'master' branch.

Saves 1 MB.

Signed-off-by: yubiuser <github@yubiuser.dev>
Copy link
Member

@PromoFaux PromoFaux left a comment

Choose a reason for hiding this comment

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

Lets use the API to get the latest tag, but also I'm not a fan of the effective duplication of the git clone command - so maybe something more like:

RUN CLONE_BRANCH="${WEB_BRANCH}" && \
    if [ "${WEB_BRANCH}" = "master" ]; then \
        CLONE_BRANCH=$(curl -s https://api.github.com/repos/${WEB_FORK}/web/releases/latest | jq -r .tag_name); \
    fi && \
    git clone --branch "${CLONE_BRANCH}" --single-branch --depth 1 https://github.com/${WEB_FORK}/web.git /var/www/html/admin && \    
    if [ "${WEB_BRANCH}" = "master" ]; then cd /var/www/html/admin && git checkout -b master; fi

RUN CLONE_BRANCH="${CORE_BRANCH}" && \
    if [ "${CORE_BRANCH}" = "master" ]; then \
        CLONE_BRANCH=$(curl -s https://api.github.com/repos/${CORE_FORK}/pi-hole/releases/latest | jq -r .tag_name); \
    fi && \
    git clone --branch "${CLONE_BRANCH}" --single-branch --depth 1 https://github.com/${CORE_FORK}/pi-hole.git /etc/.pihole && \
    if [ "${CORE_BRANCH}" = "master" ]; then cd /etc/.pihole && git checkout -b master; fi

@PromoFaux
Copy link
Member

Actually... or to further reduce duplication:

RUN clone_repo() { \
        REPO_FORK="$1"; \
        REPO_NAME="$2"; \
        BRANCH="$3"; \
        DEST="$4"; \
        CLONE_BRANCH="$BRANCH"; \
        if [ "$BRANCH" = "master" ]; then \
            CLONE_BRANCH=$(curl -s https://api.github.com/repos/${REPO_FORK}/${REPO_NAME}/releases/latest | jq -r .tag_name); \
        fi; \
        git clone --branch "$CLONE_BRANCH" --single-branch --depth 1 "https://github.com/${REPO_FORK}/${REPO_NAME}.git" "$DEST"; \
        cd "$DEST"; \
        if [ "$BRANCH" = "master" ]; then git checkout -b master; fi; \
    }; \
    clone_repo "${WEB_FORK}" "web" "${WEB_BRANCH}" "/var/www/html/admin"; \
    clone_repo "${CORE_FORK}" "pi-hole" "${CORE_BRANCH}" "/etc/.pihole"

@rdwebdesign
Copy link
Member

I like the last suggestion using a function.

yubiuser added 2 commits July 21, 2025 13:56
Signed-off-by: yubiuser <github@yubiuser.dev>
Signed-off-by: yubiuser <github@yubiuser.dev>
@PromoFaux PromoFaux merged commit 6576bfb into development Jul 21, 2025
10 checks passed
@PromoFaux PromoFaux deleted the tweak/master branch July 21, 2025 16:33
@PromoFaux PromoFaux changed the title Only clone depth 1 when checking out tags Only clone depth 1, even when checking out tags Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants