-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a8c7f3
commit 48e6b93
Showing
3 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/bin/sh | ||
# Collect.sh - A script to run Infrahub's support data collection in Docker mode. | ||
# | ||
# This script runs the following docker command: | ||
# | ||
# docker run --rm \ | ||
# -v /var/run/docker.sock:/var/run/docker.sock \ | ||
# -v "$(pwd)/exports":/source/exports \ | ||
# -e INFRAHUB_BUILD_NAME=infrahub \ | ||
# registry.opsmill.io/opsmill/infrahub invoke dev.collect [additional options] | ||
# | ||
# Usage: | ||
# curl https://infrahub.opsmill.io/collect.sh | sh [--include-queries] | ||
# | ||
# Options: | ||
# --include-queries Pass an extra flag to collect database queries logs | ||
# --version VERSION Specify the version of the Infrahub image to use (default: latest) | ||
# | ||
# Environment Variables: | ||
# INFRAHUB_BUILD_NAME Name of the Infrahub build (default: infrahub) | ||
# VERSION Version of the Infrahub image to use (default: latest) | ||
|
||
set -e | ||
|
||
# Check if docker is available | ||
if ! command -v docker >/dev/null 2>&1; then | ||
echo "Error: Docker is not installed or not in PATH." | ||
exit 1 | ||
fi | ||
|
||
# Use INFRAHUB_BUILD_NAME from the environment or default to "infrahub" | ||
if [ -z "$INFRAHUB_BUILD_NAME" ]; then | ||
export INFRAHUB_BUILD_NAME="infrahub" | ||
fi | ||
|
||
# Use VERSION from the environment or default to "latest" | ||
if [ -z "$VERSION" ]; then | ||
export VERSION="latest" | ||
fi | ||
|
||
# Default: no extra options | ||
EXTRA_OPTS="" | ||
|
||
# Process command-line options | ||
while [ "$#" -gt 0 ]; do | ||
case "$1" in | ||
--include-queries) | ||
EXTRA_OPTS="$EXTRA_OPTS --include-queries" | ||
;; | ||
--version) | ||
if [ -z "$2" ]; then | ||
echo "Error: --version requires an argument." | ||
exit 1 | ||
fi | ||
export VERSION="$2" | ||
shift | ||
;; | ||
--help|-h) | ||
echo "Usage: sh collect.sh [--include-queries] [--version VERSION]" | ||
echo "" | ||
echo "Options:" | ||
echo " --include-queries Pass an extra flag to collect database queries logs" | ||
echo " --version VERSION Specify the version of the Infrahub image to use (default: latest)" | ||
exit 0 | ||
;; | ||
*) | ||
echo "Unknown option: $1" | ||
echo "Usage: sh collect.sh [--include-queries] [--version VERSION]" | ||
exit 1 | ||
;; | ||
esac | ||
shift | ||
done | ||
|
||
# Create the exports directory if it doesn't exist | ||
if [ ! -d "$(pwd)/exports" ]; then | ||
mkdir -p "$(pwd)/exports" | ||
fi | ||
|
||
# Build the docker run command | ||
DOCKER_CMD="docker run --rm \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v $(pwd)/exports:/source/exports \ | ||
-e INFRAHUB_BUILD_NAME=${INFRAHUB_BUILD_NAME} \ | ||
registry.opsmill.io/opsmill/infrahub:${VERSION} invoke dev.collect $EXTRA_OPTS" | ||
|
||
echo "Running command with image version: ${VERSION}" | ||
echo "$DOCKER_CMD" | ||
|
||
# Execute the command | ||
eval $DOCKER_CMD | ||
echo "Support archive created in the ./exports directory." |