Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions deploy/ci/deployment-scripts.test.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions deploy/ci/validate-domain-subprocess.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Test-only harness: sources the deployment lib and validates the domain
# passed as $1. Invoked as an explicit positional argument to `bash` (no
# `-c` shell string), so the caller never interpolates a path into shell
# command text.

set -euo pipefail

script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
source "$script_dir/../scripts/lib.sh"

validate_domain "$1"
5 changes: 3 additions & 2 deletions deploy/scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ if [ "$database_mode" = "external" ] && ! env_has_key "$env_file" DATABASE_URL;
die "--database external requires DATABASE_URL in $env_file"
fi

if [ "$manage_dns" = "true" ] && [ -z "$dns_zone" ]; then
die "--dns-zone is required with --manage-dns"
if [ "$manage_dns" = "true" ]; then
[ -n "$dns_zone" ] || die "--dns-zone is required with --manage-dns"
validate_domain "$dns_zone"
fi

if [ "${#ssh_allowed_cidrs[@]}" -eq 0 ]; then
Expand Down
15 changes: 14 additions & 1 deletion deploy/scripts/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,20 @@ validate_slug() {
}

validate_domain() {
[[ "$1" =~ ^[A-Za-z0-9][A-Za-z0-9.-]*[A-Za-z0-9]$ ]] || die "invalid domain: $1"
local domain="$1"
local label
local -a labels

if [ -z "$domain" ] || [ "${#domain}" -gt 253 ] || [[ "$domain" = .* || "$domain" = *. ]]; then
die "invalid domain: $domain"
fi
case "$domain" in
*$'\n'* | *$'\r'*) die "invalid domain: $domain" ;;
esac
IFS='.' read -r -a labels <<<"$domain"
Comment thread
roomote-roomote[bot] marked this conversation as resolved.
for label in "${labels[@]}"; do
[[ "$label" =~ ^[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?$ ]] || die "invalid domain: $domain"
done
}

validate_image_part() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"db:reset": "pnpm db:down && docker volume rm -f roomote_pg_data roomote_redis_data roomote_minio_data && pnpm db:up",
"db:seed": "pnpm --silent --filter @roomote/db db:seed",
"db:seed:demo": "pnpm --silent --filter @roomote/db db:seed:demo",
"deployment:validate": "node deploy/ci/validate-deployment-artifacts.mjs",
"deployment:validate": "node --test deploy/ci/deployment-scripts.test.mjs && node deploy/ci/validate-deployment-artifacts.mjs",
"deployment:smoke": "bash deploy/ci/deployment-smoke.sh",
"dev": "pnpm --silent --filter @roomote/dev dev",
"doctor": "pnpm --filter @roomote/dev run doctor",
Expand Down
Loading