Skip to content

Commit

Permalink
Fix setup issues (#538)
Browse files Browse the repository at this point in the history
* Fix issue with setting GATEWAYD_VERSION which fails because git is not installed
* Add more logging
* Add better exit codes and comments on why the error might be happening
* Add env-var to set GatewayD architecture to install
* Use x86_64 to set the architecture if none is given
* Fix comments
  • Loading branch information
mostafa authored May 22, 2024
1 parent 624abee commit adf0b21
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 21 deletions.
39 changes: 25 additions & 14 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ services:
# If you want to install a specific version of GatewayD, you can set the
# GATEWAYD_VERSION environment variable to the desired version. Otherwise,
# the latest version will be installed.
# - GATEWAYD_VERSION=v0.9.2
# - GATEWAYD_VERSION=v0.9.5
# The architecture of the GatewayD and plugins to install.
# Default: amd64
# Possible values: amd64 or arm64
- ARCH=amd64
postgres:
image: postgres:latest
environment:
Expand All @@ -33,25 +37,32 @@ services:
retries: 5
gatewayd:
image: gatewaydio/gatewayd:latest
command: [
"run",
"--config", "/gatewayd-files/gatewayd.yaml",
"--plugin-config", "/gatewayd-files/gatewayd_plugins.yaml"
]
command:
[
"run",
"--config",
"/gatewayd-files/gatewayd.yaml",
"--plugin-config",
"/gatewayd-files/gatewayd_plugins.yaml",
]
environment:
# For more information about the environment variables, see:
# https://docs.gatewayd.io/using-gatewayd/configuration#environment-variables
- GATEWAYD_CLIENTS_DEFAULT_ADDRESS=postgres:5432
# - GATEWAYD_LOGGERS_DEFAULT_LEVEL=debug
ports:
- "15432:15432" # GatewayD server for PostgreSQL clients to connect to
- "9090:9090" # Prometheus metrics:
# http://localhost:9090/metrics
- "18080:18080" # GatewayD HTTP gateway:
# http://localhost:18080/swagger-ui/ for the API documentation
# http://localhost:18080/healthz for the health check
- "19090:19090" # GatewayD gRPC API with reflection enabled:
# You can use grpcurl or grpc-client-cli to interact with it
# GatewayD server for PostgreSQL clients to connect to
- "15432:15432"
# Prometheus metrics:
# http://localhost:9090/metrics
- "9090:9090"
# GatewayD HTTP gateway:
# http://localhost:18080/swagger-ui/ for the API documentation
# http://localhost:18080/healthz for the health check
- "18080:18080"
# GatewayD gRPC API with reflection enabled:
# You can use grpcurl or grpc-client-cli to interact with it
- "19090:19090"
volumes:
- ./gatewayd-files:/gatewayd-files:ro
links:
Expand Down
54 changes: 47 additions & 7 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,66 @@
# This script is used to install the required packages and download
# the latest version of GatewayD from GitHub and install the plugins.

# Set the architecture to amd64 if it is not set
if [ -z "${ARCH}" ]; then
architecture=$(uname -m)
if [[ "${architecture}" = "x86_64" ]]; then
echo "Setting architecture to amd64"
ARCH=amd64 && export ARCH
elif [[ "${architecture}" = "aarch64" ]] || [[ "${architecture}" = "arm64" ]]; then
echo "Setting architecture to arm64"
ARCH=arm64 && export ARCH
fi
fi
echo "Using architecture: ${ARCH}"

# Install the required packages
apk add --no-cache curl git

# Get the latest released version of GatewayD from GitHub
[ -z "${GATEWAYD_VERSION}" ] && GATEWAYD_VERSION=$(git ls-remote --tags --sort=v:refname "https://github.com/gatewayd-io/gatewayd" | cut -d/ -f3- | tail -n1) && export GATEWAYD_VERSION

# Check if the GatewayD version is set
if [ -z "${GATEWAYD_VERSION}" ]; then
echo "Failed to set GatewayD version. Consider setting the GATEWAYD_VERSION environment variable manually."
exit 126
fi

echo "Installing GatewayD ${GATEWAYD_VERSION}"

# Set the environment variables if they are not set
[ -z "${GATEWAYD_FILES}" ] && GATEWAYD_FILES=/gatewayd-files && export GATEWAYD_FILES

# Install the required packages
apk add --no-cache curl git

# Create the directory to store the gatewayd files
[ -d "${GATEWAYD_FILES}" ] || mkdir "${GATEWAYD_FILES}"

cd "${GATEWAYD_FILES}" || exit 1
# Change the directory to the gatewayd-files directory to download the GatewayD archive
# and install the plugins. This will fail exit code 127 (file or directory not found).
cd "${GATEWAYD_FILES}" || exit 127

# Download the GatewayD archive if it doesn't exist
[ -f "${GATEWAYD_FILES}"/gatewayd-linux-amd64-"${GATEWAYD_VERSION}".tar.gz ] || curl -L https://github.com/gatewayd-io/gatewayd/releases/download/"${GATEWAYD_VERSION}"/gatewayd-linux-amd64-"${GATEWAYD_VERSION}".tar.gz | tar zxvf -
[ -f "${GATEWAYD_FILES}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz ] || curl -L https://github.com/gatewayd-io/gatewayd/releases/download/"${GATEWAYD_VERSION}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz -o gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz
if [ -f "${GATEWAYD_FILES}"/gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz ]; then
echo "GatewayD archive downloaded successfully."
else
echo "GatewayD archive download failed."
exit 1
fi

# Extract the GatewayD archive
echo "Extracting GatewayD archive..."
tar zxvf gatewayd-linux-"${ARCH}"-"${GATEWAYD_VERSION}".tar.gz -C "${GATEWAYD_FILES}"

# Set execute permission for the GatewayD binary
echo "Setting execute permission for the GatewayD binary..."
chmod +x gatewayd

# Install the GatewayD plugins
"${GATEWAYD_FILES}"/gatewayd plugin install --skip-path-slip-verification --output-dir "${GATEWAYD_FILES}" --plugin-config "${GATEWAYD_FILES}"/gatewayd_plugins.yaml --cleanup=false --update --overwrite-config
# If the installation fails, the script will exit with exit code 126 (command invoke error).
echo "Installing GatewayD plugins..."
"${GATEWAYD_FILES}"/gatewayd plugin install --skip-path-slip-verification --output-dir "${GATEWAYD_FILES}" --plugin-config "${GATEWAYD_FILES}"/gatewayd_plugins.yaml --cleanup=false --update --overwrite-config || exit 126

# Replace the default Redis URL
# Replace the default Redis URL with the Redis container URL
sed -i 's/redis:\/\/localhost:6379/redis:\/\/redis:6379/' "${GATEWAYD_FILES}"/gatewayd_plugins.yaml

echo "GatewayD ${GATEWAYD_VERSION} and plugins installed successfully. Exiting..."

0 comments on commit adf0b21

Please sign in to comment.