Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/git-lfs/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "git-lfs",
"version": "1.1.1",
"version": "1.2.0",
"name": "Git Large File Support (LFS)",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/git-lfs",
"description": "Installs Git Large File Support (Git LFS) along with needed dependencies. Useful for base Dockerfiles that often are missing required install dependencies like git and curl.",
Expand All @@ -18,6 +18,11 @@
"type": "boolean",
"default": true,
"description": "Automatically pull LFS files when creating the container. When false, running 'git lfs pull' in the container will have the same effect."
},
"installDirectlyFromGitHubRelease": {
"type": "boolean",
"default": false,
"description": "Installs 'git-lfs' from GitHub releases instead of package manager feeds"
}
},
"postCreateCommand": "/usr/local/share/pull-git-lfs-artifacts.sh",
Expand Down
37 changes: 29 additions & 8 deletions src/git-lfs/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

GIT_LFS_VERSION=${VERSION:-"latest"}
AUTO_PULL=${AUTOPULL:="true"}
INSTALL_WITH_GITHUB=${INSTALLDIRECTLYFROMGITHUBRELEASE:="false"}

GIT_LFS_ARCHIVE_GPG_KEY_URI="https://packagecloud.io/github/git-lfs/gpgkey"
GIT_LFS_ARCHIVE_ARCHITECTURES="amd64 arm64"
Expand Down Expand Up @@ -130,14 +131,34 @@ install_using_apt() {
git-lfs install --skip-repo
}

# Function to fetch the version released prior to the latest version
get_previous_version() {
repo_url=$1
curl -s "$repo_url" | jq -r 'del(.[].assets) | .[0].tag_name'
}

install_from_release() {
git_lfs_filename="git-lfs-linux-${architecture}-v${GIT_LFS_VERSION}.tar.gz"
echo "Looking for release artfact: ${git_lfs_filename}"
curl -sSL -o "${git_lfs_filename}" "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/${git_lfs_filename}"
}

install_using_github() {
echo "(*) No apt package for ${VERSION_CODENAME} ${architecture}. Installing manually."
mkdir -p /tmp/git-lfs
cd /tmp/git-lfs
find_version_from_git_tags GIT_LFS_VERSION "https://github.com/git-lfs/git-lfs"
git_lfs_filename="git-lfs-linux-${architecture}-v${GIT_LFS_VERSION}.tar.gz"
echo "Looking for release artfact: ${git_lfs_filename}"
curl -sSL -o "${git_lfs_filename}" "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/${git_lfs_filename}"
install_from_release

if grep -q "Not Found" "${git_lfs_filename}"; then
echo -e "\n(!) Failed to fetch the latest artifacts for Git lfs v${GIT_LFS_VERSION}..."
repo_url=https://api.github.com/repos/git-lfs/git-lfs/releases
requested_version=$(get_previous_version "${repo_url}")
echo -e "\nAttempting to install ${requested_version}"
GIT_LFS_VERSION=${requested_version#v}
install_from_release
fi

# Verify file
curl -sSL -o "sha256sums.asc" "https://github.com/git-lfs/git-lfs/releases/download/v${GIT_LFS_VERSION}/sha256sums.asc"
receive_gpg_keys GIT_LFS_CHECKSUM_GPG_KEYS
Expand Down Expand Up @@ -165,7 +186,7 @@ export DEBIAN_FRONTEND=noninteractive

# Install git, curl, gpg, dirmngr and debian-archive-keyring if missing
. /etc/os-release
check_packages curl ca-certificates gnupg2 dirmngr apt-transport-https
check_packages curl ca-certificates gnupg2 dirmngr apt-transport-https jq
if ! type git > /dev/null 2>&1; then
check_packages git
fi
Expand All @@ -176,14 +197,14 @@ fi
# Install Git LFS
echo "Installing Git LFS..."
architecture="$(dpkg --print-architecture)"
if [[ "${GIT_LFS_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${GIT_LFS_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]]; then
install_using_apt || use_github="true"
if [[ "${GIT_LFS_ARCHIVE_ARCHITECTURES}" = *"${architecture}"* ]] && [[ "${GIT_LFS_ARCHIVE_VERSION_CODENAMES}" = *"${VERSION_CODENAME}"* ]] && [[ "${INSTALL_WITH_GITHUB}" = "false" ]]; then
install_using_apt || INSTALL_WITH_GITHUB="true"
else
use_github="true"
INSTALL_WITH_GITHUB="true"
fi

# If no archive exists or apt install fails, try direct from github
if [ "${use_github}" = "true" ]; then
if [ "${INSTALL_WITH_GITHUB}" = "true" ]; then
install_using_github
fi

Expand Down
10 changes: 10 additions & 0 deletions test/git-lfs/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@
"autoPull": false
}
}
},
"use_github": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"remoteUser": "vscode",
"features": {
"git-lfs": {
"version": "latest",
"installDirectlyFromGitHubRelease": true
}
}
}
}
10 changes: 10 additions & 0 deletions test/git-lfs/use_github.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

check "git-lfs" bash -c "git-lfs --version"

reportResults