Skip to content

Instantly share code, notes, and snippets.

@drAlberT
Last active September 25, 2020 15:15
Show Gist options
  • Save drAlberT/f8adaa76518dba72b2c91a9d787ea76e to your computer and use it in GitHub Desktop.
Save drAlberT/f8adaa76518dba72b2c91a9d787ea76e to your computer and use it in GitHub Desktop.
Bash script to update docker-compose to the latest release
#!/bin/bash
#
# Updates docker-compose to the latest release
#
# Author: Emiliano Gabrielli <[email protected]>
DESTINATION_FILE="${DESTINATION_FILE:-$(command -v docker-compose)}"
set -e -o pipefail
if [ -x "$DESTINATION_FILE" ]; then
current_version=$("${DESTINATION_FILE}" --version | sed 's/.*version\s\+\([^,]\+\).*/\1/')
printf "Previously downloaded release found: '%s'...\n" "$current_version"
fi
LATEST_RELEASE=$(curl -Ls -w "%{url_effective}\n" -o /dev/null https://github.com/docker/compose/releases/latest | sed -n 's#^.*/tag/##p')
printf "Latest vendor release is '%s'...\n" "${LATEST_RELEASE}"
if [ "$current_version" = "$LATEST_RELEASE" ]; then
printf "\nYou are already up to date. Nothing to do.\n\n"
exit 0
fi
printf "Going to download...\n\n"
curl -Ls "https://github.com/docker/compose/releases/download/${LATEST_RELEASE}/docker-compose-$(uname -s)-$(uname -m)" -o "${DESTINATION_FILE}"
chmod +x "${DESTINATION_FILE}"
"${DESTINATION_FILE}" --version
# vim: ai ts=4 sw=4 et sts=4 ft=sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment