4.0.1 - fixes
This commit is contained in:
@@ -5,11 +5,13 @@ ARCHIVE_PATH=""
|
||||
DEPLOY_PATH=""
|
||||
COMPOSE_FILE=""
|
||||
PROJECT_NAME=""
|
||||
SERVICE_NAME=""
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage:
|
||||
deploy-remote.sh --archive <path> --deploy-path <path> --compose-file <name> --project-name <name>
|
||||
deploy-remote.sh --archive <path> --deploy-path <path> --compose-file <name> --project-name <name> [--service <name>]
|
||||
|
||||
This script only updates the main Goodwalk compose project at the specified
|
||||
deployment path. It does not touch unrelated Docker projects or global Docker
|
||||
@@ -40,6 +42,10 @@ while [[ $# -gt 0 ]]; do
|
||||
PROJECT_NAME="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
--service)
|
||||
SERVICE_NAME="${2:-}"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
@@ -54,6 +60,9 @@ done
|
||||
[[ -n "$DEPLOY_PATH" ]] || fail "--deploy-path is required"
|
||||
[[ -n "$COMPOSE_FILE" ]] || fail "--compose-file is required"
|
||||
[[ -n "$PROJECT_NAME" ]] || fail "--project-name is required"
|
||||
if [[ -n "$SERVICE_NAME" ]]; then
|
||||
SERVICE_NAME="$(printf '%s' "$SERVICE_NAME" | xargs)"
|
||||
fi
|
||||
[[ "$DEPLOY_PATH" != "/" ]] || fail "Refusing to deploy to /"
|
||||
[[ -f "$ARCHIVE_PATH" ]] || fail "Archive not found: $ARCHIVE_PATH"
|
||||
|
||||
@@ -77,6 +86,9 @@ echo "[deploy-remote] Deploying main Goodwalk stack"
|
||||
echo "[deploy-remote] Target deployment path: $DEPLOY_PATH"
|
||||
echo "[deploy-remote] Compose file: $COMPOSE_FILE"
|
||||
echo "[deploy-remote] Docker project: $PROJECT_NAME"
|
||||
if [[ -n "$SERVICE_NAME" ]]; then
|
||||
echo "[deploy-remote] Target service: $SERVICE_NAME"
|
||||
fi
|
||||
echo "[deploy-remote] Staging archive in: $STAGING_DIR"
|
||||
|
||||
mkdir -p "$DEPLOY_PATH"
|
||||
@@ -130,13 +142,33 @@ cd "$DEPLOY_PATH"
|
||||
echo "[deploy-remote] Validating compose configuration"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" config >/dev/null
|
||||
|
||||
echo "[deploy-remote] Stopping only the Goodwalk project containers"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" stop || true
|
||||
if [[ -n "$SERVICE_NAME" ]]; then
|
||||
AVAILABLE_SERVICES="$("${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" config --services)"
|
||||
if ! grep -Fxq "$SERVICE_NAME" <<<"$AVAILABLE_SERVICES"; then
|
||||
fail "Service '$SERVICE_NAME' was not found in $COMPOSE_FILE. Available services: $(tr '\n' ',' <<<"$AVAILABLE_SERVICES" | sed 's/,$//')"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "[deploy-remote] Rebuilding and starting only the Goodwalk project containers"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" up -d --build --remove-orphans
|
||||
if [[ -n "$SERVICE_NAME" ]]; then
|
||||
echo "[deploy-remote] Stopping only the Goodwalk service: $SERVICE_NAME"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" stop "$SERVICE_NAME" || true
|
||||
|
||||
echo "[deploy-remote] Rebuilding and starting only the Goodwalk service: $SERVICE_NAME"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" up -d --build "$SERVICE_NAME"
|
||||
else
|
||||
echo "[deploy-remote] Stopping only the Goodwalk project containers"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" stop || true
|
||||
|
||||
echo "[deploy-remote] Rebuilding and starting only the Goodwalk project containers"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" up -d --build --remove-orphans
|
||||
fi
|
||||
|
||||
echo "[deploy-remote] Current Goodwalk container status"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" ps
|
||||
|
||||
if [[ -z "$SERVICE_NAME" || "$SERVICE_NAME" == "app" || "$SERVICE_NAME" == "db" ]]; then
|
||||
echo "[deploy-remote] Syncing homepage content into PostgreSQL"
|
||||
"${COMPOSE_CMD[@]}" -p "$PROJECT_NAME" -f "$COMPOSE_FILE" exec -T app node scripts/sync-homepage-content.mjs
|
||||
fi
|
||||
|
||||
echo "[deploy-remote] Remote deployment finished"
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url';
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const projectRoot = path.resolve(__dirname, '..');
|
||||
const outputPath = process.argv[2]
|
||||
? path.resolve(process.argv[2])
|
||||
: path.join(projectRoot, 'deploy-data', 'homepage-content.json');
|
||||
|
||||
const homepageModuleUrl = pathToFileURL(
|
||||
path.join(projectRoot, 'src', 'lib', 'content', 'homepage.ts')
|
||||
).href;
|
||||
|
||||
const { homepageContent } = await import(homepageModuleUrl);
|
||||
|
||||
await mkdir(path.dirname(outputPath), { recursive: true });
|
||||
await writeFile(outputPath, `${JSON.stringify(homepageContent, null, 2)}\n`, 'utf8');
|
||||
|
||||
console.log(`[deploy] Exported homepage content to ${outputPath}`);
|
||||
@@ -0,0 +1,41 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import pg from 'pg';
|
||||
|
||||
const { Pool } = pg;
|
||||
const contentPath = process.argv[2]
|
||||
? path.resolve(process.argv[2])
|
||||
: path.resolve('deploy-data', 'homepage-content.json');
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
|
||||
if (!connectionString) {
|
||||
throw new Error('DATABASE_URL is required for homepage content sync.');
|
||||
}
|
||||
|
||||
const rawContent = await readFile(contentPath, 'utf8');
|
||||
const homepageContent = JSON.parse(rawContent);
|
||||
const pool = new Pool({ connectionString });
|
||||
|
||||
try {
|
||||
await pool.query(`
|
||||
create table if not exists site_content (
|
||||
key text primary key,
|
||||
value jsonb not null,
|
||||
updated_at timestamptz not null default now()
|
||||
)
|
||||
`);
|
||||
|
||||
await pool.query(
|
||||
`
|
||||
insert into site_content (key, value)
|
||||
values ($1, $2::jsonb)
|
||||
on conflict (key)
|
||||
do update set value = excluded.value, updated_at = now()
|
||||
`,
|
||||
['homepage', JSON.stringify(homepageContent)]
|
||||
);
|
||||
|
||||
console.log(`[content-sync] Synced homepage content from ${contentPath}`);
|
||||
} finally {
|
||||
await pool.end();
|
||||
}
|
||||
Reference in New Issue
Block a user