Skip to content

Open-source event management and ticket selling platform — perfect for concerts, conferences, and everything in between 🎟️ If you find this project helpful, please consider giving us a star ⭐️

Add Amp orb setup, resume and services (#1387)

Dave Earley6ee9a113208a
diff --git a/.agents/resume b/.agents/resume
new file mode 100755
index 000000000..042c4e127
--- /dev/null
+++ b/.agents/resume
@@ -0,0 +1,10 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+if ! grep -Eq '^127\.0\.0\.1[[:space:]].*\bpgsql\b' /etc/hosts; then
+ echo "127.0.0.1 pgsql" | sudo tee -a /etc/hosts >/dev/null
+fi
+
+if ! pg_isready -q -h 127.0.0.1; then
+ sudo systemctl start postgresql@15-main
+fi
diff --git a/.agents/setup b/.agents/setup
new file mode 100755
index 000000000..0a2d0465e
--- /dev/null
+++ b/.agents/setup
@@ -0,0 +1,140 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+cd "$repo_root"
+
+php_version=8.5
+pg_version=15
+
+step() {
+ printf '\n==> %s\n' "$*"
+ step_started=$SECONDS
+}
+
+done_step() {
+ printf ' (%ss)\n' "$((SECONDS - step_started))"
+}
+
+export DEBIAN_FRONTEND=noninteractive
+
+step "System packages (PHP $php_version, PostgreSQL $pg_version)"
+php_packages=(
+ "php$php_version-cli" "php$php_version-bcmath" "php$php_version-curl" "php$php_version-gd"
+ "php$php_version-intl" "php$php_version-mbstring" "php$php_version-pgsql" "php$php_version-sqlite3"
+ "php$php_version-xml" "php$php_version-zip" "php$php_version-imagick" "php$php_version-redis"
+)
+apt_packages=("${php_packages[@]}" "postgresql-$pg_version" postgresql-client nginx unzip)
+missing=()
+for pkg in "${apt_packages[@]}"; do
+ dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -q 'install ok installed' || missing+=("$pkg")
+done
+if ((${#missing[@]})); then
+ if [ ! -f /etc/apt/sources.list.d/php.list ]; then
+ sudo install -m 0755 -d /etc/apt/keyrings
+ sudo curl -fsSL https://packages.sury.org/php/apt.gpg -o /etc/apt/keyrings/sury-php.gpg
+ echo "deb [signed-by=/etc/apt/keyrings/sury-php.gpg] https://packages.sury.org/php/ $(. /etc/os-release && echo "$VERSION_CODENAME") main" |
+ sudo tee /etc/apt/sources.list.d/php.list >/dev/null
+ fi
+ sudo apt-get update -qq
+ sudo -E apt-get install -y -qq --no-install-recommends "${missing[@]}"
+fi
+if systemctl is-enabled --quiet nginx 2>/dev/null; then
+ sudo systemctl disable --now nginx
+fi
+done_step
+
+step "Composer"
+if ! command -v composer >/dev/null 2>&1; then
+ sudo curl -fsSL https://getcomposer.org/download/latest-stable/composer.phar -o /usr/local/bin/composer
+ sudo chmod 0755 /usr/local/bin/composer
+fi
+composer --version
+done_step
+
+step "PostgreSQL"
+pg_conf="/etc/postgresql/$pg_version/main/conf.d/zz-amp-orb.conf"
+if [ ! -f "$pg_conf" ]; then
+ printf '%s\n' "fsync = off" "synchronous_commit = off" "full_page_writes = off" |
+ sudo tee "$pg_conf" >/dev/null
+ sudo systemctl restart "postgresql@$pg_version-main"
+fi
+sudo systemctl enable --now "postgresql@$pg_version-main" >/dev/null 2>&1
+for _ in $(seq 1 30); do
+ pg_isready -q -h 127.0.0.1 && break
+ sleep 1
+done
+pg_isready -h 127.0.0.1
+if ! sudo -u postgres psql -tAc "SELECT 1 FROM pg_roles WHERE rolname = 'username'" | grep -q 1; then
+ sudo -u postgres psql -qc "CREATE ROLE username LOGIN SUPERUSER PASSWORD 'password'"
+fi
+for db in backend hievents_test; do
+ if ! sudo -u postgres psql -tAc "SELECT 1 FROM pg_database WHERE datname = '$db'" | grep -q 1; then
+ sudo -u postgres createdb -O username "$db"
+ fi
+done
+if ! grep -Eq '^127\.0\.0\.1[[:space:]].*\bpgsql\b' /etc/hosts; then
+ echo "127.0.0.1 pgsql" | sudo tee -a /etc/hosts >/dev/null
+fi
+done_step
+
+step "Backend environment"
+if [ ! -f backend/.env ]; then
+ sed \
+ -e 's|^APP_URL=.*|APP_URL=http://localhost:8000|' \
+ -e 's|^APP_FRONTEND_URL=.*|APP_FRONTEND_URL=http://localhost:5678|' \
+ -e 's|^APP_CDN_URL=.*|APP_CDN_URL=http://localhost:8000/storage|' \
+ -e 's|^FILESYSTEM_PUBLIC_DISK=.*|FILESYSTEM_PUBLIC_DISK=public|' \
+ -e 's|^FILESYSTEM_PRIVATE_DISK=.*|FILESYSTEM_PRIVATE_DISK=local|' \
+ -e 's|^MAIL_MAILER=.*|MAIL_MAILER=log|' \
+ backend/.env.example >backend/.env
+fi
+mkdir -p backend/bootstrap/cache backend/storage/framework/{cache,sessions,views} backend/storage/logs
+done_step
+
+step "Composer install (backend)"
+(cd backend && composer install --no-interaction --no-progress --prefer-dist)
+done_step
+
+step "Migrate development database"
+(cd backend && php artisan migrate --force --no-interaction)
+[ -e backend/public/storage ] || (cd backend && php artisan storage:link --no-interaction)
+done_step
+
+step "Frontend environment and dependencies"
+if [ ! -f frontend/.env ]; then
+ sed \
+ -e 's|^VITE_API_URL_CLIENT=.*|VITE_API_URL_CLIENT=http://localhost:8000|' \
+ -e 's|^VITE_API_URL_SERVER=.*|VITE_API_URL_SERVER=http://localhost:8000|' \
+ -e 's|^VITE_FRONTEND_URL=.*|VITE_FRONTEND_URL=http://localhost:5678|' \
+ frontend/.env.example >frontend/.env
+fi
+(cd frontend && yarn install --frozen-lockfile --non-interactive --silent)
+done_step
+
+step "E2E dependencies"
+if [ ! -d e2e/node_modules ] || [ e2e/package-lock.json -nt e2e/node_modules/.package-lock.json ]; then
+ (cd e2e && npm ci --no-audit --no-fund --loglevel=error)
+fi
+done_step
+
+step "Orb agent notes"
+notes_marker="<!-- hi-events orb notes -->"
+agents_file="$HOME/.config/amp/AGENTS.md"
+mkdir -p "$(dirname "$agents_file")"
+if ! grep -Fqx "$notes_marker" "$agents_file" 2>/dev/null; then
+ cat >>"$agents_file" <<'EOF'
+
+<!-- hi-events orb notes -->
+# Hi.Events in an orb
+
+- There is no Docker stack in the orb. Run the `docker compose ... exec backend` commands from CLAUDE.md directly in `backend/`, e.g. `php artisan test --testsuite=Unit`, `php artisan test --filter=Name`, `./vendor/bin/pint --test`.
+- PHP 8.5, Composer, and PostgreSQL 15 are installed natively. Postgres runs under systemd on 127.0.0.1:5432 (role `username` / `password`, databases `backend` and `hievents_test`); the hostname `pgsql` resolves to 127.0.0.1, so `backend/.env` and `backend/.env.testing` work unchanged.
+- `backend/.env` is set up for a native dev server: `php artisan serve --port 8000` (API at http://localhost:8000, no `/api` prefix), mail goes to the log, files use local disks, no Redis or Mailpit.
+- `frontend/.env` points at that API; run the SSR dev server with `yarn dev:ssr` in `frontend/` (http://localhost:5678).
+- `amp orb services ensure` starts the whole app behind one portal (`.amp/services.yaml`): nginx routes `/api/` to the backend and everything else to the frontend, like the Docker dev stack.
+EOF
+fi
+done_step
+
+printf '\nSetup complete.\n'
diff --git a/.amp/nginx.conf b/.amp/nginx.conf
new file mode 100644
index 000000000..9c4c681a6
--- /dev/null
+++ b/.amp/nginx.conf
@@ -0,0 +1,42 @@
+daemon off;
+pid /tmp/hievents-nginx/nginx.pid;
+error_log stderr;
+
+events {}
+
+http {
+ access_log off;
+ client_body_temp_path /tmp/hievents-nginx/body;
+ proxy_temp_path /tmp/hievents-nginx/proxy;
+ fastcgi_temp_path /tmp/hievents-nginx/fastcgi;
+ uwsgi_temp_path /tmp/hievents-nginx/uwsgi;
+ scgi_temp_path /tmp/hievents-nginx/scgi;
+
+ map $http_x_forwarded_proto $forwarded_proto {
+ default $http_x_forwarded_proto;
+ "" $scheme;
+ }
+
+ server {
+ listen 127.0.0.1:__PORT__;
+ client_max_body_size 20M;
+
+ location / {
+ proxy_pass http://127.0.0.1:5678;
+ proxy_set_header Host localhost;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $forwarded_proto;
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "Upgrade";
+ }
+
+ location /api/ {
+ proxy_pass http://127.0.0.1:8000/;
+ proxy_set_header Host $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header X-Forwarded-Proto $forwarded_proto;
+ }
+ }
+}
diff --git a/.amp/public-url-env.sh b/.amp/public-url-env.sh
new file mode 100644
index 000000000..100b9ba40
--- /dev/null
+++ b/.amp/public-url-env.sh
@@ -0,0 +1,3 @@
+url="${WEB_URL%/}"
+export APP_URL="$url/api" APP_FRONTEND_URL="$url" APP_CDN_URL="$url/api/storage"
+export VITE_API_URL_CLIENT="$url/api" VITE_FRONTEND_URL="$url" VITE_API_URL_SERVER=http://localhost:8000
diff --git a/.amp/services.yaml b/.amp/services.yaml
new file mode 100644
index 000000000..fa0cc59ea
--- /dev/null
+++ b/.amp/services.yaml
@@ -0,0 +1,20 @@
+services:
+ web:
+ command: mkdir -p /tmp/hievents-nginx && sed "s/__PORT__/$PORT/" .amp/nginx.conf > /tmp/hievents-nginx/nginx.conf && exec /usr/sbin/nginx -e stderr -c /tmp/hievents-nginx/nginx.conf
+ portal:
+ url: /
+ title: Hi.Events
+ description: Register a new account to sign in. Emails are printed to the backend service log (amp orb service logs backend).
+ backend:
+ command: . ../.amp/public-url-env.sh && exec php artisan serve --host=127.0.0.1 --port="$PORT"
+ cwd: backend
+ port: 8000
+ env:
+ WEB_URL: ${services.web.publicURL}
+ PHP_CLI_SERVER_WORKERS: "4"
+ frontend:
+ command: . ../.amp/public-url-env.sh && exec yarn dev:ssr
+ cwd: frontend
+ port: 5678
+ env:
+ WEB_URL: ${services.web.publicURL}
diff --git a/.gitignore b/.gitignore
index d5e6e939a..1299f2b5a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -32,3 +32,5 @@ test_results/
/release-notes/**
/release-notes/
/release-notes.md
+
+.amp/portals/*