Make the revision param for deployments optional

The deployment script now uses the current revision of the set branch in this case. Does not work together with a custom value of $CONFIG_HASH_LENGTH though.
master 1.1.0
Lukas Bestle 11 years ago
parent 11f05ab078
commit bb033b58cc

@ -33,11 +33,15 @@ This is a tutorial on how you would implement this setup with this toolset.
Using `project_add` is similar, but it uses a custom project path the headers of the files in `bin/` contain detailed usage information. Using `project_add` is similar, but it uses a custom project path the headers of the files in `bin/` contain detailed usage information.
3. **Get the current state from your GitHub repository (other Git repositories work the same)** 3. **Get the current state from your GitHub repository (other Git repositories work the same)**
As "main_site" was setup using a clone URL, you can use `site_deploy <site> <revision>` to get and install the current state of your project: As "main_site" was setup using a clone URL, you can use `site_deploy <site> [<revision>]` to fetch and install the current state of your project automatically:
```bash
site_deploy main_site
```
If you omit the Git revision, the latest one is used instead. But if you want to deploy a specific revision, that's easy too:
```bash ```bash
# You need the full SHA-1 hash of your commit for this to work.
# Automatic deployments using web hooks do this for you automatically.
site_deploy main_site 78ca1d2fa93147b0... site_deploy main_site 78ca1d2fa93147b0...
``` ```

@ -6,10 +6,11 @@
# .postdeploy.sh in the repository (if existing) and links the version # .postdeploy.sh in the repository (if existing) and links the version
# as current. # as current.
# #
# Usage: project_deploy <project> <revision> # Usage: project_deploy <project> [<revision>]
# #
# <project> Path to the project # <project> Path to the project
# <revision> SHA-1 commit hash of the revision to checkout # <revision> SHA-1 commit hash of the revision to checkout
# Defaults to the latest commit on the set branch
######################################################################## ########################################################################
# Functions # Functions
@ -56,11 +57,20 @@ if [[ $CONFIG_PRESERVE_VERSIONS == 1 ]]; then
CONFIG_PRESERVE_VERSIONS=2 CONFIG_PRESERVE_VERSIONS=2
fi fi
if [[ -z "$revision" ]]; then if [[ -z "$project" ]]; then
# Print help # Print help
echo -e "\033[1mUsage:\033[0m \033[34mproject_deploy\033[0m <project> <revision>" echo -e "\033[1mUsage:\033[0m \033[34mproject_deploy\033[0m <project> [<revision>]"
exit 1 exit 1
fi fi
if [[ -z "$revision" ]]; then
revision="latest"
# Check if the default value for $CONFIG_HASH_LENGTH has been changed
if [[ $CONFIG_HASH_LENGTH != 40 ]]; then
echo -e "\033[31mYou changed the default value of \033[34m\$CONFIG_HASH_LENGTH\033[31m. To make sure the deployed revisions are unique and never duplicated, deployments of the latest revision aren't supported with a custom value of this option. Please give me the exact revision string in your custom length.\033[0m" >&2
exit 1
fi
fi
# Check if the project exists # Check if the project exists
if [[ ! -f "$project/.project" ]]; then if [[ ! -f "$project/.project" ]]; then
@ -74,12 +84,6 @@ if [[ ! -f "$project/.origin" ]]; then
exit 1 exit 1
fi fi
# Check if the commit hash is valid
if [[ ${#revision} != $CONFIG_HASH_LENGTH ]]; then
echo -e "\033[31mThe length of the revision name \033[34m$revision\033[31m is not equal to the configured \033[34m$CONFIG_HASH_LENGTH\033[31m characters.\033[0m" >&2
exit 1
fi
# Add header to log # Add header to log
log="$project/logs/$revision.log" log="$project/logs/$revision.log"
if [[ -f "$log" ]]; then if [[ -f "$log" ]]; then
@ -90,18 +94,9 @@ echo -e "\033[1;35mRun on \033[34m$(date)\033[35m by \033[34m$USER\033[35m:\n---
# Log everything beginning here # Log everything beginning here
{ {
# Check if we already installed this version # Make sure the repository exists and is updated
if ls "$project/versions"/*-$revision &> /dev/null; then # We only need to do this if the revision was not deployed yet
# Yes, use that if ! ls "$project/versions"/*-$revision &> /dev/null; then
# Build the pathname of the destination directory
versionName=$(basename $(echo "$project/versions"/*-$revision))
buildVersionPath
echo -e "\033[1mThis revision has already been installed, using previous installation \033[34m$versionName\033[0;1m.\033[0m"
else
# No, fetch and install
# Check if the repository has already been cloned # Check if the repository has already been cloned
url=$(cat "$project/.origin") url=$(cat "$project/.origin")
if ! [[ -d "$project/repo" ]]; then if ! [[ -d "$project/repo" ]]; then
@ -121,6 +116,45 @@ echo -e "\033[1;35mRun on \033[34m$(date)\033[35m by \033[34m$USER\033[35m:\n---
fi fi
echo -e " => \033[32mSuccess.\033[0m" echo -e " => \033[32mSuccess.\033[0m"
fi fi
fi
# Determine the actual revision to use
if [[ "$revision" != "latest" ]]; then
# Check if the given commit hash is valid
if [[ ${#revision} != $CONFIG_HASH_LENGTH ]]; then
echo -e "\033[31mThe length of the revision name \033[34m$revision\033[31m is not equal to the configured \033[34m$CONFIG_HASH_LENGTH\033[31m characters.\033[0m" >&2
exit 1
fi
else
# Check if the set branch exists
branch=$(cat "$project/.branch")
echo -e "\033[1mDetermining current revision for branch \033[34m$branch\033[0;1m...\033[0m"
if ! (cd "$project/repo"; git show-branch "$branch" &> /dev/null); then
echo -e "\033[31mThe set branch \033[34m$branch\033[31m does not exist.\033[0m" >&2
exit 1
fi
# Get the commit hash from the set branch
revision="$(cd "$project/repo"; git show --format=format:%H "$branch")"
if [[ $? != 0 ]]; then
echo -e " => \033[31mCould not determine current revision.\033[0m" >&2
exit 1
fi
echo -e " => \033[32mUsing revision \033[34m$revision\033[32m.\033[0m"
fi
# Check if we already installed this version
if ls "$project/versions"/*-$revision &> /dev/null; then
# Yes, use that
# Build the pathname of the destination directory
versionName=$(basename $(echo "$project/versions"/*-$revision))
buildVersionPath
echo -e "\033[1mThis revision has already been installed, using previous installation \033[34m$versionName\033[0;1m.\033[0m"
else
# No, fetch and install
# Build the pathname of the destination directory # 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 # Get all version names, get the last one, split it by "-" and get the first part, remove leading zeros

@ -6,18 +6,19 @@
# .postdeploy.sh in the repository (if existing) and links the version # .postdeploy.sh in the repository (if existing) and links the version
# as current. # as current.
# #
# Usage: site_deploy <site> <revision> # Usage: site_deploy <site> [<revision>]
# #
# <site> Name of the site (directory in ~/web/sites/) # <site> Name of the site (directory in ~/web/sites/)
# <revision> SHA-1 commit hash of the revision to checkout # <revision> SHA-1 commit hash of the revision to checkout
# Defaults to the latest commit on the set branch
######################################################################## ########################################################################
site="$1" site="$1"
revision="$2" revision="$2"
if [[ -z "$revision" ]]; then if [[ -z "$site" ]]; then
# Print help # Print help
echo -e "\033[1mUsage:\033[0m \033[34msite_deploy\033[0m <site> <revision>" echo -e "\033[1mUsage:\033[0m \033[34msite_deploy\033[0m <site> [<revision>]"
exit 1 exit 1
fi fi

Loading…
Cancel
Save