Skip to content

Commit

Permalink
Do more migrating to Docker Compose v2 (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre authored Nov 30, 2021
1 parent 02026ac commit 4593233
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/problem-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ body:
placeholder: |-
e.g.:
- latest install logs: `ls -1 sentry_install_log-*.txt | tail -1 | xargs cat`
- `docker-compose logs` output
- `docker compose logs` output
validations:
required: true
- type: markdown
Expand Down
1 change: 1 addition & 0 deletions install/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ else
_endgroup=""
fi

# Some environments still use `docker-compose` even for Docker Compose v2.
dc_base="$(docker compose version &> /dev/null && echo 'docker compose' || echo 'docker-compose')"
dc="$dc_base --ansi never --env-file ${_ENV}"
dcr="$dc run --rm"
Expand Down
28 changes: 14 additions & 14 deletions install/check-minimum-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,37 @@ echo "${_group}Checking minimum requirements ..."

source "$(dirname $0)/_min-requirements.sh"

DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
# Get semantic version of Docker Compose v2
if docker compose version &>/dev/null; then
COMPOSE_VERSION=$(docker compose version --short | sed 's/v\{0,1\}\(.\{1,\}\)/\1/')
else
# Do NOT use $dc instead of `docker-compose` below as older versions don't support certain options and fail
COMPOSE_VERSION=$(docker-compose --version | sed 's/docker-compose version \(.\{1,\}\),.*/\1/')
fi
RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}');
CPU_AVAILABLE_IN_DOCKER=$(docker run --rm busybox nproc --all);

# Compare dot-separated strings - function below is inspired by https://stackoverflow.com/a/37939589/808368
function ver () { echo "$@" | awk -F. '{ printf("%d%03d%03d", $1,$2,$3); }'; }

DOCKER_VERSION=$(docker version --format '{{.Server.Version}}')
if [[ "$(ver $DOCKER_VERSION)" -lt "$(ver $MIN_DOCKER_VERSION)" ]]; then
echo "FAIL: Expected minimum Docker version to be $MIN_DOCKER_VERSION but found $DOCKER_VERSION"
exit 1
fi

if [[ "$(ver $COMPOSE_VERSION)" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
exit 1
if docker compose version &>/dev/null; then
# If `docker compose` exists then it's guaranteed to be Docker Compose v2, which is good enough for us.
true
else
# If we have `docker-compose` instead then it could be either v1 or v2 (also, use portable sed).
# See https://github.com/getsentry/self-hosted/issues/1132#issuecomment-982823712 ff. for regex testing.
COMPOSE_VERSION=$(docker-compose version | head -n1 | sed -E 's/^.* version:? v?([0-9.]+),?.*$/\1/')
if [[ "$(ver $COMPOSE_VERSION)" -lt "$(ver $MIN_COMPOSE_VERSION)" ]]; then
echo "FAIL: Expected minimum docker-compose version to be $MIN_COMPOSE_VERSION but found $COMPOSE_VERSION"
exit 1
fi
fi

CPU_AVAILABLE_IN_DOCKER=$(docker run --rm busybox nproc --all);
if [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_HARD" ]]; then
echo "FAIL: Required minimum CPU cores available to Docker is $MIN_CPU_HARD, found $CPU_AVAILABLE_IN_DOCKER"
exit 1
elif [[ "$CPU_AVAILABLE_IN_DOCKER" -lt "$MIN_CPU_SOFT" ]]; then
echo "WARN: Recommended minimum CPU cores available to Docker is $MIN_CPU_SOFT, found $CPU_AVAILABLE_IN_DOCKER"
fi

RAM_AVAILABLE_IN_DOCKER=$(docker run --rm busybox free -m 2>/dev/null | awk '/Mem/ {print $2}');
if [[ "$RAM_AVAILABLE_IN_DOCKER" -lt "$MIN_RAM_HARD" ]]; then
echo "FAIL: Required minimum RAM available to Docker is $MIN_RAM_HARD MB, found $RAM_AVAILABLE_IN_DOCKER MB"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion install/error-handling.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cleanup () {
echo "An error occurred, caught SIG$1 on line $2";

if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
echo "*NOT* cleaning up, to clean your environment run \"docker-compose stop\"."
echo "*NOT* cleaning up, to clean your environment run \"docker compose stop\"."
else
echo "Cleaning up..."
fi
Expand Down
2 changes: 1 addition & 1 deletion install/parse-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ show_help() {
cat <<EOF
Usage: $0 [options]
Install Sentry with docker-compose.
Install Sentry with `docker compose`.
Options:
-h, --help Show this message and exit.
Expand Down
2 changes: 1 addition & 1 deletion install/set-up-and-migrate-database.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [[ -n "${CI:-}" || "${SKIP_USER_PROMPT:-0}" == 1 ]]; then
echo "Did not prompt for user creation due to non-interactive shell."
echo "Run the following command to create one yourself (recommended):"
echo ""
echo " docker-compose run --rm web createuser"
echo " docker compose run --rm web createuser"
echo ""
else
$dcr web upgrade
Expand Down
11 changes: 6 additions & 5 deletions install/update-docker-images.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
echo "${_group}Fetching and updating Docker images ..."

# We tag locally built images with an '-onpremise-local' suffix. docker-compose
# pull tries to pull these too and shows a 404 error on the console which is
# confusing and unnecessary. To overcome this, we add the stderr>stdout
# redirection below and pass it through grep, ignoring all lines having this
# '-onpremise-local' suffix.
# We tag locally built images with an '-onpremise-local' suffix. `docker
# compose pull` tries to pull these too and shows a 404 error on the console
# which is confusing and unnecessary. To overcome this, we add the
# stderr>stdout redirection below and pass it through grep, ignoring all lines
# having this '-onpremise-local' suffix.

$dc pull -q --ignore-pull-failures 2>&1 | grep -v -- -onpremise-local || true

# We may not have the set image on the repo (local images) so allow fails
Expand Down
2 changes: 1 addition & 1 deletion reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ confirm "☠️ Warning! 😳 This is highly destructive! 😱 Are you sure you
echo "Okay ... good luck! 😰"

# Hit the reset button.
docker-compose down --volumes --remove-orphans --rmi local
docker compose down --volumes --remove-orphans --rmi local

# Remove any remaining (likely external) volumes with name matching 'sentry-.*'.
for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do
Expand Down

0 comments on commit 4593233

Please sign in to comment.