add a postCreateCommand to git-lfs
Feature (#511)
* add a postCreateCommand to git-lfs Feature * debug passing locally but not in CI * update scenario * add GIT_LFS_SKIP_SMUDGE=1 to prevent fetching lfs arifacts in github actions * arguments should be booleans * move example repo to devcontainers org * place script literally anywhere other than /tmp
This commit is contained in:
parent
1118b992d9
commit
2952d87f1d
5 changed files with 83 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"id": "git-lfs",
|
||||
"version": "1.0.7",
|
||||
"version": "1.1.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.",
|
||||
|
@ -13,8 +13,14 @@
|
|||
],
|
||||
"default": "latest",
|
||||
"description": "Select version of Git LFS to install"
|
||||
},
|
||||
"autoPull": {
|
||||
"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."
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "/usr/local/share/pull-git-lfs-artifacts.sh",
|
||||
"installsAfter": [
|
||||
"ghcr.io/devcontainers/features/common-utils"
|
||||
]
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
# Maintainer: The VS Code and Codespaces Teams
|
||||
|
||||
GIT_LFS_VERSION=${VERSION:-"latest"}
|
||||
AUTO_PULL=${AUTOPULL:="true"}
|
||||
|
||||
GIT_LFS_ARCHIVE_GPG_KEY_URI="https://packagecloud.io/github/git-lfs/gpgkey"
|
||||
GIT_LFS_ARCHIVE_ARCHITECTURES="amd64 arm64"
|
||||
|
@ -185,6 +186,37 @@ if [ "${use_github}" = "true" ]; then
|
|||
install_using_github
|
||||
fi
|
||||
|
||||
# --- Generate a 'pull-git-lfs-artifacts.sh' script to be executed by the 'postCreateCommand' lifecycle hook
|
||||
PULL_GIT_LFS_SCRIPT_PATH="/usr/local/share/pull-git-lfs-artifacts.sh"
|
||||
|
||||
tee "$PULL_GIT_LFS_SCRIPT_PATH" > /dev/null \
|
||||
<< EOF
|
||||
#!/bin/sh
|
||||
set -e
|
||||
AUTO_PULL=${AUTO_PULL}
|
||||
EOF
|
||||
|
||||
tee -a "$PULL_GIT_LFS_SCRIPT_PATH" > /dev/null \
|
||||
<< 'EOF'
|
||||
|
||||
echo "Fetching git lfs artifacts..."
|
||||
|
||||
if [ "${AUTO_PULL}" != "true" ]; then
|
||||
echo "(!) Skipping 'git lfs pull' because 'autoPull' is not set to 'true'"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Check if repo is a git lfs repo.
|
||||
if ! git lfs ls-files > /dev/null 2>&1; then
|
||||
echo "(!) Skipping automatic 'git lfs pull' because no git lfs files were detected"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git lfs pull
|
||||
EOF
|
||||
|
||||
chmod 755 "$PULL_GIT_LFS_SCRIPT_PATH"
|
||||
|
||||
# Clean up
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
|
11
test/git-lfs/autoPullDisabled.sh
Normal file
11
test/git-lfs/autoPullDisabled.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Optional: Import test library
|
||||
source dev-container-features-test-lib
|
||||
|
||||
check "target file exists" cat big-file-1.txt
|
||||
check "lfs file has not been expanded" cat "big-file-1.txt" | grep "git-lfs\.github\.com"
|
||||
|
||||
reportResults
|
11
test/git-lfs/autoPullEnabled.sh
Normal file
11
test/git-lfs/autoPullEnabled.sh
Normal file
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Optional: Import test library
|
||||
source dev-container-features-test-lib
|
||||
|
||||
check "target file exists" cat big-file-1.txt
|
||||
check "lfs file has been expanded" cat "big-file-1.txt" | grep "this is test file 1"
|
||||
|
||||
reportResults
|
22
test/git-lfs/scenarios.json
Normal file
22
test/git-lfs/scenarios.json
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"autoPullEnabled": {
|
||||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
|
||||
"initializeCommand": "(GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/devcontainers/git-lfs-example /tmp/testRepo-1 || true) && (cp -r /tmp/testRepo-1/.git* . && cp -r /tmp/testRepo-1/* .)",
|
||||
"remoteUser": "vscode",
|
||||
"features": {
|
||||
"git-lfs": {
|
||||
"autoPull": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoPullDisabled": {
|
||||
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
|
||||
"initializeCommand": "(GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/devcontainers/git-lfs-example /tmp/testRepo-2 || true) && (cp -r /tmp/testRepo-2/.git* . && cp -r /tmp/testRepo-2/* .)",
|
||||
"remoteUser": "vscode",
|
||||
"features": {
|
||||
"git-lfs": {
|
||||
"autoPull": false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue