Only clone each repository once

The repository is now only fetched for each deployment, which makes the whole process much faster especially for large repositories and repositories with many submodules.
master
Lukas Bestle 10 years ago
parent df677877f6
commit 77005052a5

@ -57,7 +57,7 @@ This is a tutorial on how you would implement this setup with this toolset.
When deleting a site with `site_remove`, all of these domain links are automatically removed as well. You can also use `site_unlink` to unlink specific domains.
If you setup automatic deployments (see below), your sites are automatically updated to the newest revision. This is done by cloning the project using `project_deploy` and updating the links, so the domain always points to the latest revision.
If you setup automatic deployments (see below), your sites are automatically updated to the newest revision. This is done by cloning or fetching the repository using `project_deploy` and updating the links, so the domain link always points to the latest revision.
Let's say you committed a mistake (haha) and you want to rollback to the last deployed (working) revision.
Since our example site "main_site" is deployable (it has an origin repository), it stores a history of (by default) 5 versions and keeps the link to the last version. This means that you can easily return to the last version and manually to an even older version:
@ -98,7 +98,9 @@ Every project/site follows this directory structure:
logs # Logs of all deployments
├── <commit-hash>.log
├── <commit-hash>.log
versions # Fully separate Git repositories of the project
repo # Clone of the project's Git repository
├── …
versions # Copies of the repository checked out to a specific revision
├── <id>-<commit-hash>
│ └── <project files>
└── <id>-<commit-hash>

@ -102,6 +102,26 @@ echo -e "\033[1;35mRun on \033[34m$(date)\033[35m by \033[34m$USER\033[35m:\n---
else
# No, fetch and install
# Check if the repository has already been cloned
url=$(cat "$project/.origin")
if ! [[ -d "$project/repo" ]]; then
# No, clone it now
echo -e "\033[1mCloning from \033[34m$url\033[0;1m for the first time...\033[0m"
if ! git clone --recursive "$url" "$project/repo"; then
echo -e " => \033[31mCould not clone project \033[34m$project\033[31m from \033[34m$url\033[31m.\033[0m" >&2
exit 1
fi
echo -e " => \033[32mSuccess.\033[0m"
else
# Yes, only fetch from the remote repository
echo -e "\033[1mFetching new commits from \033[34m$url\033[0;1m...\033[0m"
if ! (cd "$project/repo"; git fetch; git submodule update --init --recursive); then
echo -e " => \033[31mCould not fetch from \033[34m$url\033[31m.\033[0m" >&2
exit 1
fi
echo -e " => \033[32mSuccess.\033[0m"
fi
# Build the pathname of the destination directory
# Get all version names, get the last one, split it by "-" and get the first part, remove leading zeros
latestVersion=$(echo "$(ls "$project/versions" | tail -1)" | cut -f1 -d- | sed 's/^0*//')
@ -109,13 +129,12 @@ echo -e "\033[1;35mRun on \033[34m$(date)\033[35m by \033[34m$USER\033[35m:\n---
versionName="$(printf "%05d" "$versionNumber")-$revision"
buildVersionPath
# Clone the project
url=$(cat "$project/.origin")
echo -e "\033[1mCloning from \033[34m$url\033[0;1m...\033[0m"
if ! git clone --recursive "$url" "$destination"; then
echo -e " => \033[31mCould not clone project \033[34m$project\033[31m from \033[34m$url\033[31m.\033[0m" >&2
# Copy repository to new destination
echo -e "\033[1mCopying repository to deployment destination...\033[0m"
if ! cp -R "$project/repo" "$destination"; then
echo -e " => \033[31mCould not copy repository.\033[0m" >&2
project_deploy::reverse "$project" "$destination"
exit
exit 1
fi
echo -e " => \033[32mSuccess.\033[0m"

@ -96,4 +96,12 @@ else
echo -e " => \033[32mSuccess.\033[0m"
fi
exit 0
# Remove repo to make sure the new origin is used in the future
if [[ -d "$project/repo" ]]; then
echo -e "\033[1mDeleting the old repository for project \033[34m$project\033[0;1m...\033[0m"
if ! rm -Rf "$project/repo"; then
echo -e " => \033[31mSomething went wrong.\033[0m" >&2
exit 1
fi
echo -e " => \033[32mSuccess.\033[0m"
fi

Loading…
Cancel
Save