37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
ENV_NAME="${1:-prod}"
|
|
IMAGE="marketing-system-data-tool"
|
|
TAG="$ENV_NAME"
|
|
PORT="${PORT:-8077}"
|
|
cd "$ROOT_DIR"
|
|
ENV_FILE=".env.$ENV_NAME"
|
|
if [ ! -f "$ENV_FILE" ] && [ -f "server/.env.$ENV_NAME" ]; then
|
|
ENV_FILE="server/.env.$ENV_NAME"
|
|
fi
|
|
if [ ! -f "$ENV_FILE" ]; then
|
|
echo "$ENV_FILE not found" >&2
|
|
exit 1
|
|
fi
|
|
docker build -t "$IMAGE:$TAG" -f Dockerfile .
|
|
mkdir -p log storage/export
|
|
CID_NAME="marketing-data-$ENV_NAME"
|
|
RUNNING=$(docker inspect -f '{{.State.Running}}' "$CID_NAME" 2>/dev/null || echo false)
|
|
if [ "$RUNNING" = "true" ]; then
|
|
docker stop "$CID_NAME" >/dev/null 2>&1 || true
|
|
fi
|
|
if docker ps -a --format '{{.Names}}' | grep -q "^${CID_NAME}$"; then
|
|
docker rm "$CID_NAME" >/dev/null 2>&1 || true
|
|
fi
|
|
docker run -d \
|
|
--name "$CID_NAME" \
|
|
--restart unless-stopped \
|
|
--env APP_ENV="$ENV_NAME" \
|
|
--env-file "$ENV_FILE" \
|
|
-p "$PORT:8077" \
|
|
-v "$ROOT_DIR/storage/export:/app/storage/export" \
|
|
-v "$ROOT_DIR/log:/app/log" \
|
|
"$IMAGE:$TAG"
|
|
echo "container: $CID_NAME image: $IMAGE:$TAG port: $PORT"
|