39 lines
1000 B
Bash
39 lines
1000 B
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
# BLOCK 1: config + sanity checks
|
|
APP_DIR="/srv/proxyfier"
|
|
REPO_URL="ssh://git@git.ornot.ru:2223/alexanderOrNot/proxyfier.git"
|
|
BRANCH="main"
|
|
IMAGE="proxyfier:latest"
|
|
CONTAINER="proxyfier"
|
|
PORT="9000"
|
|
|
|
command -v git >/dev/null 2>&1 || { echo "git not found"; exit 1; }
|
|
command -v docker >/dev/null 2>&1 || { echo "docker not found"; exit 1; }
|
|
|
|
# BLOCK 2: get/update source code
|
|
if [[ ! -d "$APP_DIR/.git" ]]; then
|
|
mkdir -p "$APP_DIR"
|
|
git clone "$REPO_URL" "$APP_DIR"
|
|
fi
|
|
cd "$APP_DIR"
|
|
git fetch --all
|
|
git reset --hard "origin/${BRANCH}"
|
|
|
|
# BLOCK 3: build image
|
|
docker build -t "$IMAGE" .
|
|
|
|
# BLOCK 4: run container
|
|
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER}$"; then
|
|
docker rm -f "$CONTAINER"
|
|
fi
|
|
docker run -d --name "$CONTAINER" \
|
|
--restart unless-stopped \
|
|
-p "${PORT}:${PORT}" \
|
|
-v "$APP_DIR/config.yaml:/app/config.yaml:ro" \
|
|
-e PROXYFIER_CONFIG=/app/config.yaml \
|
|
"$IMAGE"
|
|
|
|
echo "OK: deployed ${CONTAINER} on port ${PORT}"
|