From 48ecdd1bc08d84e8637d708a8624aadc04551e5d Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Fri, 23 Dec 2022 16:13:50 +0100 Subject: [PATCH] feat(git-lfs): convert to v2 --- src/usr/local/buildpack/tools/git-lfs.sh | 35 ------------------ src/usr/local/buildpack/tools/v2/git-lfs.sh | 39 +++++++++++++++++++++ test/latest/Dockerfile | 4 +++ 3 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 src/usr/local/buildpack/tools/git-lfs.sh create mode 100644 src/usr/local/buildpack/tools/v2/git-lfs.sh diff --git a/src/usr/local/buildpack/tools/git-lfs.sh b/src/usr/local/buildpack/tools/git-lfs.sh deleted file mode 100644 index fce584af4a..0000000000 --- a/src/usr/local/buildpack/tools/git-lfs.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -e - -require_root -check_semver "$TOOL_VERSION" - -if [[ ! "${MAJOR}" || ! "${MINOR}" || ! "${PATCH}" ]]; then - echo "Invalid version: ${TOOL_VERSION}" - exit 1 -fi - -if [[ -x "$(command -v git-lfs)" ]]; then - echo "Skipping, already installed" - exit 0 -fi - -ARCH=linux-amd64 -LFS_FILE="git-lfs-${ARCH}-v${TOOL_VERSION}.tar.gz" -strip=0 - -# v3.2+ has a subdir https://github.com/git-lfs/git-lfs/pull/4980 -if [[ ${MAJOR} -gt 3 || (${MAJOR} -eq 3 && ${MINOR} -ge 2) ]]; then - strip=1 -fi - -curl -sSfLo git-lfs.tgz "https://github.com/git-lfs/git-lfs/releases/download/v${TOOL_VERSION}/${LFS_FILE}" -mkdir -p /tmp/git-lfs -bsdtar --strip $strip -C /tmp/git-lfs -xf git-lfs.tgz -mv /tmp/git-lfs/git-lfs /usr/local/bin/ -rm git-lfs.tgz -rm -rf /tmp/git-lfs - -git lfs version -git lfs install diff --git a/src/usr/local/buildpack/tools/v2/git-lfs.sh b/src/usr/local/buildpack/tools/v2/git-lfs.sh new file mode 100644 index 0000000000..3330cb400f --- /dev/null +++ b/src/usr/local/buildpack/tools/v2/git-lfs.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +function check_tool_requirements () { + check_semver "$TOOL_VERSION" "all" +} + +function install_tool () { + local versioned_tool_path + local file + local arch=linux-amd64 + local lfs_file="${TOOL_NAME}-${arch}-v${TOOL_VERSION}.tar.gz" + local strip=0 + + versioned_tool_path=$(create_versioned_tool_path) + + # v3.2+ has a subdir https://github.com/git-lfs/git-lfs/pull/4980 + if [[ ${MAJOR} -gt 3 || (${MAJOR} -eq 3 && ${MINOR} -ge 2) ]]; then + strip=1 + fi + + file=$(get_from_url "https://github.com/${TOOL_NAME}/${TOOL_NAME}/releases/download/v${TOOL_VERSION}/${lfs_file}") + temp_dir="$(mktemp -d)" + bsdtar --strip $strip -C "${temp_dir}" -xf "${file}" + mkdir "${versioned_tool_path}/bin" + mv "${temp_dir}/git-lfs" "${versioned_tool_path}/bin/" + rm -rf "${temp_dir}" +} + +function link_tool () { + shell_wrapper "${TOOL_NAME}" "$(find_versioned_tool_path)/bin" + + git lfs version + + if [ "$(is_root)" -eq 0 ]; then + git lfs install --system + else + git lfs install + fi +} diff --git a/test/latest/Dockerfile b/test/latest/Dockerfile index a95b1efe2a..99e4b83de9 100644 --- a/test/latest/Dockerfile +++ b/test/latest/Dockerfile @@ -165,6 +165,10 @@ RUN mkdir $HOME/.tf-cache && TF_PLUGIN_CACHE_DIR=$HOME/.tf-cache terraform init #-------------------------------------- FROM build as testh +RUN prepare-tool docker + +USER 1000 + ARG APT_HTTP_PROXY ARG IGNORED_TOOLS=powershell,node