Add dev compose deployment for anal-front
This commit is contained in:
10
deploy/anal-front/compose.yml
Normal file
10
deploy/anal-front/compose.yml
Normal file
@@ -0,0 +1,10 @@
|
||||
name: anal-front
|
||||
|
||||
services:
|
||||
web:
|
||||
image: ${ANAL_FRONT_WEB_IMAGE:?ANAL_FRONT_WEB_IMAGE is required}
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
BACKEND_UPSTREAM: ${BACKEND_UPSTREAM:?BACKEND_UPSTREAM is required}
|
||||
ports:
|
||||
- "${FRONTEND_BIND_HOST:-10.10.0.124}:${FRONTEND_PORT:-18011}:80"
|
||||
84
deploy/anal-front/deploy.sh
Executable file
84
deploy/anal-front/deploy.sh
Executable file
@@ -0,0 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
APP_DIR="${APP_DIR:-/opt/anal-front}"
|
||||
COMPOSE_FILE="${COMPOSE_FILE:-$APP_DIR/compose.yml}"
|
||||
ENV_FILE="${ENV_FILE:-$APP_DIR/.env}"
|
||||
IMAGE_ENV_FILE="${IMAGE_ENV_FILE:-$APP_DIR/releases/current.env}"
|
||||
HEALTH_URL="${HEALTH_URL:-http://10.10.0.124:18011/}"
|
||||
ANAL_FRONT_WEB_IMAGE="${1:-${ANAL_FRONT_WEB_IMAGE:-}}"
|
||||
|
||||
if [[ -z "$ANAL_FRONT_WEB_IMAGE" ]]; then
|
||||
echo "ANAL_FRONT_WEB_IMAGE argument or environment variable is required" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
install -d -m 0770 "$APP_DIR" "$APP_DIR/releases"
|
||||
|
||||
if [[ ! -f "$ENV_FILE" ]]; then
|
||||
umask 077
|
||||
cat >"$ENV_FILE" <<EOF
|
||||
BACKEND_UPSTREAM=https://anal-back.dev.nii-ecos.ru
|
||||
FRONTEND_BIND_HOST=10.10.0.124
|
||||
FRONTEND_PORT=18011
|
||||
EOF
|
||||
chmod 0600 "$ENV_FILE"
|
||||
fi
|
||||
|
||||
umask 027
|
||||
cat >"$IMAGE_ENV_FILE" <<EOF
|
||||
ANAL_FRONT_WEB_IMAGE=$ANAL_FRONT_WEB_IMAGE
|
||||
EOF
|
||||
chmod 0640 "$IMAGE_ENV_FILE"
|
||||
|
||||
compose() {
|
||||
docker compose \
|
||||
--env-file "$ENV_FILE" \
|
||||
--env-file "$IMAGE_ENV_FILE" \
|
||||
-f "$COMPOSE_FILE" \
|
||||
"$@"
|
||||
}
|
||||
|
||||
wait_for_service_health() {
|
||||
local service="$1"
|
||||
local container_id=""
|
||||
local health_status=""
|
||||
|
||||
for _ in $(seq 1 120); do
|
||||
container_id="$(compose ps -q "$service" 2>/dev/null || true)"
|
||||
if [[ -n "$container_id" ]]; then
|
||||
health_status="$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$container_id" 2>/dev/null || true)"
|
||||
if [[ "$health_status" == "healthy" || "$health_status" == "running" ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Service $service did not become healthy" >&2
|
||||
compose ps >&2 || true
|
||||
compose logs --tail=100 "$service" >&2 || true
|
||||
exit 1
|
||||
}
|
||||
|
||||
compose config >/dev/null
|
||||
if [[ "$ANAL_FRONT_WEB_IMAGE" == */* ]]; then
|
||||
compose pull web
|
||||
else
|
||||
echo "Using local image $ANAL_FRONT_WEB_IMAGE"
|
||||
fi
|
||||
compose up -d --remove-orphans web
|
||||
wait_for_service_health web
|
||||
|
||||
for _ in $(seq 1 60); do
|
||||
if curl -fsS "$HEALTH_URL" >/dev/null; then
|
||||
compose ps
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "Anal Front did not become healthy at $HEALTH_URL" >&2
|
||||
compose ps >&2 || true
|
||||
compose logs --tail=100 web >&2 || true
|
||||
exit 1
|
||||
Reference in New Issue
Block a user