76 lines
2.2 KiB
Bash
76 lines
2.2 KiB
Bash
#!/usr/bin/env sh
|
|
set -eu
|
|
|
|
script_dir=$(CDPATH= cd "$(dirname "$0")" && pwd)
|
|
|
|
ENVIRONMENT=${ENVIRONMENT:-Production}
|
|
APPHOST_PATH=${APPHOST_PATH:-"$script_dir/../src/AppHost/AppHost.csproj"}
|
|
OUTPUT_PATH=${OUTPUT_PATH:-"$script_dir/aspire-output"}
|
|
|
|
env_file="$script_dir/.env"
|
|
if [ -f "$env_file" ]; then
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
line=$(printf '%s' "$line" | tr -d '\r')
|
|
case "$line" in
|
|
""|\#*) continue ;;
|
|
esac
|
|
|
|
key=${line%%=*}
|
|
value=${line#*=}
|
|
|
|
case "$key" in
|
|
[A-Za-z_][A-Za-z0-9_]*) ;;
|
|
*) continue ;;
|
|
esac
|
|
|
|
eval "existing=\${$key-}"
|
|
if [ -n "$key" ] && [ -z "$existing" ]; then
|
|
export "$key=$value"
|
|
fi
|
|
done < "$env_file"
|
|
fi
|
|
|
|
missing=""
|
|
for name in REGISTRY_USERNAME REGISTRY_TOKEN REGISTRY_REPOSITORY; do
|
|
eval "value=\${$name-}"
|
|
if [ -z "$value" ]; then
|
|
if [ -z "$missing" ]; then
|
|
missing=$name
|
|
else
|
|
missing="$missing, $name"
|
|
fi
|
|
fi
|
|
done
|
|
|
|
if [ -n "$missing" ]; then
|
|
echo "Missing required environment variables: $missing. Load deploy/.env values before running this script." >&2
|
|
exit 1
|
|
fi
|
|
|
|
IMAGE_TAG=${IMAGE_TAG:-latest}
|
|
REGISTRY_ENDPOINT=git.recroomarchive.org
|
|
export IMAGE_TAG REGISTRY_ENDPOINT
|
|
|
|
if [ -n "${ASPIRE_CLI-}" ]; then
|
|
aspire_cli=$ASPIRE_CLI
|
|
elif command -v aspire >/dev/null 2>&1; then
|
|
aspire_cli=aspire
|
|
elif [ -x "$HOME/.aspire/bin/aspire" ]; then
|
|
aspire_cli="$HOME/.aspire/bin/aspire"
|
|
elif [ -x "$HOME/.dotnet/tools/aspire" ]; then
|
|
aspire_cli="$HOME/.dotnet/tools/aspire"
|
|
else
|
|
echo "Aspire CLI was not found in this shell." >&2
|
|
echo "Install it in WSL with: curl -sSL https://aspire.dev/install.sh | bash" >&2
|
|
echo "Or install it as a .NET tool with: dotnet tool install -g Aspire.Cli" >&2
|
|
echo "If it is installed somewhere else, rerun with: ASPIRE_CLI=/path/to/aspire sh ./deploy/push-images.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
printf '%s' "$REGISTRY_TOKEN" | docker login "$REGISTRY_ENDPOINT" -u "$REGISTRY_USERNAME" --password-stdin
|
|
|
|
"$aspire_cli" do push \
|
|
--apphost "$APPHOST_PATH" \
|
|
--environment "$ENVIRONMENT" \
|
|
--output-path "$OUTPUT_PATH"
|