feat: add platform frontend deployment
This commit is contained in:
1 parent
7eb0e5186d
commit
bd3d409836
12 files changed
+219
-6
No files matched your search
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
env_file="${1:-compose/.env}"
|
||||
source_directory="${2:-/srv/ai-soulmate/sources/ai-soulmate-server}"
|
||||
|
||||
for required_command in docker git sed; do
|
||||
if ! command -v "$required_command" >/dev/null 2>&1; then
|
||||
printf 'Required command is unavailable: %s\n' "$required_command" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [[ ! -r "$env_file" ]]; then
|
||||
printf 'Environment file not found: %s\n' "$env_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -r "$source_directory/frontend-vue/Dockerfile" ]]; then
|
||||
printf 'Frontend Dockerfile not found under: %s\n' "$source_directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
source_branch="$(git -C "$source_directory" branch --show-current)"
|
||||
source_commit="$(git -C "$source_directory" rev-parse HEAD)"
|
||||
source_short_commit="${source_commit:0:12}"
|
||||
image="$(sed -n 's/^FRONTEND_IMAGE=//p' "$env_file" | head -n 1)"
|
||||
if [[ "$source_branch" != "local-deployment" ]]; then
|
||||
printf 'Expected source branch local-deployment, found: %s\n' "$source_branch" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -n "$(git -C "$source_directory" status --short --untracked-files=no)" ]]; then
|
||||
printf 'Tracked source changes are present; refusing to build an uncommitted image.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$image" != "ai-soulmate-frontend:${source_short_commit}" ]]; then
|
||||
printf 'FRONTEND_IMAGE does not match source commit; rerun configure-backend-env.sh.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
docker build \
|
||||
--label "org.opencontainers.image.revision=${source_commit}" \
|
||||
--tag "$image" \
|
||||
"$source_directory/frontend-vue"
|
||||
|
||||
docker image inspect "$image" \
|
||||
--format 'Frontend image built: {{index .RepoTags 0}} id={{.Id}} size={{.Size}}'
|
||||
@@ -81,6 +81,11 @@ set_value BACKEND_MEMORY_LIMIT 4g
|
||||
set_value BACKEND_CPU_LIMIT 2.0
|
||||
set_value BACKEND_UPLOADS_VOLUME_NAME ai-soulmate-backend-uploads
|
||||
set_value BACKEND_LOGS_VOLUME_NAME ai-soulmate-backend-logs
|
||||
set_value FRONTEND_IMAGE "ai-soulmate-frontend:${source_short_commit}"
|
||||
set_value FRONTEND_BIND_ADDRESS "$public_host"
|
||||
set_value FRONTEND_HOST_PORT 8080
|
||||
set_value FRONTEND_MEMORY_LIMIT 1g
|
||||
set_value FRONTEND_CPU_LIMIT 1.0
|
||||
|
||||
set_value APP_ENV production
|
||||
ensure_secret SECRET_KEY
|
||||
|
||||
@@ -60,6 +60,11 @@ BACKEND_MEMORY_LIMIT=4g
|
||||
BACKEND_CPU_LIMIT=2.0
|
||||
BACKEND_UPLOADS_VOLUME_NAME=ai-soulmate-backend-uploads
|
||||
BACKEND_LOGS_VOLUME_NAME=ai-soulmate-backend-logs
|
||||
FRONTEND_IMAGE=ai-soulmate-frontend:local-deployment
|
||||
FRONTEND_BIND_ADDRESS=127.0.0.1
|
||||
FRONTEND_HOST_PORT=8080
|
||||
FRONTEND_MEMORY_LIMIT=1g
|
||||
FRONTEND_CPU_LIMIT=1.0
|
||||
|
||||
APP_ENV=production
|
||||
SECRET_KEY=$(random_secret)
|
||||
|
||||
@@ -33,5 +33,5 @@ compose_command=(
|
||||
-f "$compose_file"
|
||||
)
|
||||
"${compose_command[@]}" config --quiet
|
||||
"${compose_command[@]}" up -d
|
||||
"${compose_command[@]}" up -d backend
|
||||
"${compose_command[@]}" ps --all
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
env_file="${1:-compose/.env}"
|
||||
compose_file="${BACKEND_COMPOSE_FILE:-compose/docker-compose.backend.yml}"
|
||||
|
||||
if [[ ! -r "$env_file" ]]; then
|
||||
printf 'Environment file not found: %s\n' "$env_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
env_value() {
|
||||
sed -n "s/^${1}=//p" "$env_file" | head -n 1
|
||||
}
|
||||
|
||||
project_name="$(env_value BACKEND_COMPOSE_PROJECT_NAME)"
|
||||
frontend_image="$(env_value FRONTEND_IMAGE)"
|
||||
if [[ -z "$project_name" || "$project_name" == "$(env_value COMPOSE_PROJECT_NAME)" ]]; then
|
||||
printf 'BACKEND_COMPOSE_PROJECT_NAME must be set and differ from the infrastructure project.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ -z "$frontend_image" ]] || ! docker image inspect "$frontend_image" >/dev/null 2>&1; then
|
||||
printf 'Configured frontend image is not available locally: %s\n' "$frontend_image" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
compose_command=(
|
||||
docker compose
|
||||
--project-name "$project_name"
|
||||
--env-file "$env_file"
|
||||
-f "$compose_file"
|
||||
)
|
||||
"${compose_command[@]}" config --quiet
|
||||
"${compose_command[@]}" up -d frontend
|
||||
"${compose_command[@]}" ps --all
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
set -Eeuo pipefail
|
||||
|
||||
env_file="${1:-compose/.env}"
|
||||
compose_file="${BACKEND_COMPOSE_FILE:-compose/docker-compose.backend.yml}"
|
||||
|
||||
for required_command in curl docker jq sed; do
|
||||
if ! command -v "$required_command" >/dev/null 2>&1; then
|
||||
printf 'Required command is unavailable: %s\n' "$required_command" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
if [[ ! -r "$env_file" ]]; then
|
||||
printf 'Environment file not found: %s\n' "$env_file" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
env_value() {
|
||||
sed -n "s/^${1}=//p" "$env_file" | head -n 1
|
||||
}
|
||||
|
||||
project_name="$(env_value BACKEND_COMPOSE_PROJECT_NAME)"
|
||||
frontend_bind_address="$(env_value FRONTEND_BIND_ADDRESS)"
|
||||
frontend_host_port="$(env_value FRONTEND_HOST_PORT)"
|
||||
if [[ -z "$project_name" || "$project_name" == "$(env_value COMPOSE_PROJECT_NAME)" ]]; then
|
||||
printf 'BACKEND_COMPOSE_PROJECT_NAME must be set and differ from the infrastructure project.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
compose_command=(
|
||||
docker compose
|
||||
--project-name "$project_name"
|
||||
--env-file "$env_file"
|
||||
-f "$compose_file"
|
||||
)
|
||||
"${compose_command[@]}" config --quiet
|
||||
|
||||
base_url="http://${frontend_bind_address}:${frontend_host_port}"
|
||||
api_json=""
|
||||
for _attempt in $(seq 1 18); do
|
||||
if curl --fail --silent --show-error --max-time 5 "${base_url}/health" | grep -q '^ok'; then
|
||||
if api_json="$(curl --fail --silent --show-error --max-time 5 "${base_url}/api/health" 2>/dev/null)"; then
|
||||
if printf '%s' "$api_json" | jq -e '.status == "healthy" and .database == "connected"' >/dev/null; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
api_json=""
|
||||
sleep 5
|
||||
done
|
||||
if [[ -z "$api_json" ]]; then
|
||||
printf 'Frontend or proxied API health check did not become healthy: %s\n' "$base_url" >&2
|
||||
"${compose_command[@]}" ps >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
index_html="$(curl --fail --silent --show-error --max-time 5 "${base_url}/")"
|
||||
if ! printf '%s' "$index_html" | grep -q 'id="app"'; then
|
||||
printf 'Frontend index does not contain the Vue application mount point.\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$api_json" | jq .
|
||||
"${compose_command[@]}" ps
|
||||
printf 'Frontend static site and proxied backend health checks passed.\n'
|
||||
Reference in new issue
Block a user