From 4cac61e285086499452107ff9b1bd2e1794a4e7d Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 11:56:34 +0530 Subject: [PATCH 01/16] added swarm stack in selfhost --- deploy/selfhost/swarm-compose.yml | 277 +++++++++++++++++ deploy/selfhost/swarm.sh | 502 ++++++++++++++++++++++++++++++ 2 files changed, 779 insertions(+) create mode 100644 deploy/selfhost/swarm-compose.yml create mode 100644 deploy/selfhost/swarm.sh diff --git a/deploy/selfhost/swarm-compose.yml b/deploy/selfhost/swarm-compose.yml new file mode 100644 index 00000000000..2633f7c34a8 --- /dev/null +++ b/deploy/selfhost/swarm-compose.yml @@ -0,0 +1,277 @@ +x-db-env: &db-env + PGHOST: ${PGHOST:-plane-db} + PGDATABASE: ${PGDATABASE:-plane} + POSTGRES_USER: ${POSTGRES_USER:-plane} + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-plane} + POSTGRES_DB: ${POSTGRES_DB:-plane} + POSTGRES_PORT: ${POSTGRES_PORT:-5432} + PGDATA: ${PGDATA:-/var/lib/postgresql/data} + +x-redis-env: &redis-env + REDIS_HOST: ${REDIS_HOST:-plane-redis} + REDIS_PORT: ${REDIS_PORT:-6379} + REDIS_URL: ${REDIS_URL:-redis://plane-redis:6379/} + +x-minio-env: &minio-env + MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID:-access-key} + MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY:-secret-key} + +x-aws-s3-env: &aws-s3-env + AWS_REGION: ${AWS_REGION:-} + AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-access-key} + AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-secret-key} + AWS_S3_ENDPOINT_URL: ${AWS_S3_ENDPOINT_URL:-http://plane-minio:9000} + AWS_S3_BUCKET_NAME: ${AWS_S3_BUCKET_NAME:-uploads} + +x-proxy-env: &proxy-env + NGINX_PORT: ${NGINX_PORT:-80} + BUCKET_NAME: ${AWS_S3_BUCKET_NAME:-uploads} + FILE_SIZE_LIMIT: ${FILE_SIZE_LIMIT:-5242880} + +x-mq-env: &mq-env + # RabbitMQ Settings + RABBITMQ_HOST: ${RABBITMQ_HOST:-plane-mq} + RABBITMQ_PORT: ${RABBITMQ_PORT:-5672} + RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER:-plane} + RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD:-plane} + RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_VHOST:-plane} + RABBITMQ_VHOST: ${RABBITMQ_VHOST:-plane} + +x-live-env: &live-env + API_BASE_URL: ${API_BASE_URL:-http://api:8000} + +x-app-env: &app-env + WEB_URL: ${WEB_URL:-http://localhost} + DEBUG: ${DEBUG:-0} + SENTRY_DSN: ${SENTRY_DSN} + SENTRY_ENVIRONMENT: ${SENTRY_ENVIRONMENT:-production} + CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS} + GUNICORN_WORKERS: 1 + USE_MINIO: ${USE_MINIO:-1} + DATABASE_URL: ${DATABASE_URL:-postgresql://plane:plane@plane-db/plane} + SECRET_KEY: ${SECRET_KEY:-60gp0byfz2dvffa45cxl20p1scy9xbpf6d8c5y0geejgkyp1b5} + ADMIN_BASE_URL: ${ADMIN_BASE_URL} + SPACE_BASE_URL: ${SPACE_BASE_URL} + APP_BASE_URL: ${APP_BASE_URL} + AMQP_URL: ${AMQP_URL:-amqp://plane:plane@plane-mq:5672/plane} + + +services: + web: + image: ${DOCKERHUB_USER:-makeplane}/plane-frontend:${APP_RELEASE:-stable} + restart: unless-stopped + command: node web/server.js web + deploy: + replicas: ${WEB_REPLICAS:-1} + depends_on: + - api + - worker + networks: + - plane-network + + space: + image: ${DOCKERHUB_USER:-makeplane}/plane-space:${APP_RELEASE:-stable} + restart: unless-stopped + command: node space/server.js space + deploy: + replicas: ${SPACE_REPLICAS:-1} + depends_on: + - api + - worker + - web + networks: + - plane-network + + admin: + image: ${DOCKERHUB_USER:-makeplane}/plane-admin:${APP_RELEASE:-stable} + restart: unless-stopped + command: node admin/server.js admin + deploy: + replicas: ${ADMIN_REPLICAS:-1} + depends_on: + - api + - web + networks: + - plane-network + + live: + image: ${DOCKERHUB_USER:-makeplane}/plane-live:${APP_RELEASE:-stable} + restart: unless-stopped + command: node live/dist/server.js live + environment: + <<: [ *live-env ] + deploy: + replicas: ${LIVE_REPLICAS:-1} + depends_on: + - api + - web + networks: + - plane-network + + api: + image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} + restart: unless-stopped + command: ./bin/docker-entrypoint-api.sh + deploy: + replicas: ${API_REPLICAS:-1} + volumes: + - logs_api:/code/plane/logs + environment: + <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] + depends_on: + - plane-db + - plane-redis + - plane-mq + networks: + - plane-network + + worker: + image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} + restart: unless-stopped + command: ./bin/docker-entrypoint-worker.sh + deploy: + replicas: ${WORKER_REPLICAS:-1} + volumes: + - logs_worker:/code/plane/logs + environment: + <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] + depends_on: + - api + - plane-db + - plane-redis + - plane-mq + networks: + - plane-network + + beat-worker: + image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} + restart: unless-stopped + command: ./bin/docker-entrypoint-beat.sh + deploy: + replicas: ${BEAT_WORKER_REPLICAS:-1} + volumes: + - logs_beat-worker:/code/plane/logs + environment: + <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] + depends_on: + - api + - plane-db + - plane-redis + - plane-mq + networks: + - plane-network + + migrator: + image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} + command: ./bin/docker-entrypoint-migrator.sh + deploy: + replicas: 1 + restart_policy: + condition: on-failure + volumes: + - logs_migrator:/code/plane/logs + environment: + <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] + depends_on: + - plane-db + - plane-redis + networks: + - plane-network + + plane-db: + image: postgres:15.7-alpine + restart: unless-stopped + command: postgres -c 'max_connections=1000' + deploy: + replicas: 1 + environment: + <<: *db-env + volumes: + - pgdata:/var/lib/postgresql/data + networks: + - plane-network + + plane-redis: + image: valkey/valkey:7.2.5-alpine + restart: unless-stopped + deploy: + replicas: 1 + volumes: + - redisdata:/data + networks: + - plane-network + + plane-mq: + image: rabbitmq:3.13.6-management-alpine + restart: always + deploy: + replicas: 1 + environment: + <<: *mq-env + volumes: + - rabbitmq_data:/var/lib/rabbitmq + networks: + - plane-network + + plane-minio: + image: minio/minio:latest + restart: unless-stopped + ports: + - target: 9090 + published: 9090 + protocol: tcp + mode: host + command: server /export --console-address ":9090" + deploy: + replicas: 1 + environment: + <<: *minio-env + volumes: + - uploads:/export + networks: + - plane-network + + # Comment this if you already have a reverse proxy running + proxy: + image: ${DOCKERHUB_USER:-makeplane}/plane-proxy:${APP_RELEASE:-stable} + restart: unless-stopped + ports: + - target: 80 + published: 80 + protocol: tcp + mode: host + environment: + <<: *proxy-env + deploy: + replicas: 1 + depends_on: + - web + - api + - space + networks: + - plane-network + +volumes: + pgdata: + driver: local + redisdata: + driver: local + uploads: + driver: local + logs_api: + driver: local + logs_worker: + driver: local + logs_beat-worker: + driver: local + logs_migrator: + driver: local + rabbitmq_data: + driver: local + +networks: + plane-network: + name: plane-network + driver: overlay + attachable: true + \ No newline at end of file diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh new file mode 100644 index 00000000000..155d6f85569 --- /dev/null +++ b/deploy/selfhost/swarm.sh @@ -0,0 +1,502 @@ +#!/bin/bash + +BRANCH=preview +SERVICE_FOLDER=plane-app +PLANE_INSTALL_DIR=$PWD/$SERVICE_FOLDER +export APP_RELEASE="stable" +export DOCKERHUB_USER=makeplane + +export GH_REPO=makeplane/plane +export RELEASE_DOWNLOAD_URL="https://github.com/$GH_REPO/releases/download" +export FALLBACK_DOWNLOAD_URL="https://raw.githubusercontent.com/$GH_REPO/$BRANCH/deploy/selfhost" + +OS_NAME=$(uname) + +# Create necessary directories +mkdir -p $PLANE_INSTALL_DIR/archive + +DOCKER_FILE_PATH=$PLANE_INSTALL_DIR/swarm-compose.yml +DOCKER_ENV_PATH=$PLANE_INSTALL_DIR/plane.env + +function print_header() { +clear + +cat <<"EOF" +-------------------------------------------- + ____ _ ///////// +| _ \| | __ _ _ __ ___ ///////// +| |_) | |/ _` | '_ \ / _ \ ///// ///// +| __/| | (_| | | | | __/ ///// ///// +|_| |_|\__,_|_| |_|\___| //// + //// +-------------------------------------------- +Project management tool from the future +-------------------------------------------- +EOF +} + +function checkLatestRelease(){ + echo "Checking for the latest release..." >&2 + local latest_release=$(curl -s https://api.github.com/repos/$GH_REPO/releases/latest | grep -o '"tag_name": "[^"]*"' | sed 's/"tag_name": "//;s/"//g') + if [ -z "$latest_release" ]; then + echo "Failed to check for the latest release. Exiting..." >&2 + exit 1 + fi + + echo $latest_release +} + + +# Function to read stack name from env file +function readStackName() { + if [ -f "$DOCKER_ENV_PATH" ]; then + local saved_stack_name=$(grep "^STACK_NAME=" "$DOCKER_ENV_PATH" | cut -d'=' -f2) + if [ -n "$saved_stack_name" ]; then + stack_name=$saved_stack_name + return 1 + fi + fi + return 0 +} + +# Function to get stack name (either from env or user input) +function getStackName() { + read -p "Enter stack name [plane]: " input_stack_name + if [ -z "$input_stack_name" ]; then + input_stack_name="plane" + fi + stack_name=$input_stack_name + updateEnvFile "STACK_NAME" "$stack_name" "$DOCKER_ENV_PATH" + echo "Using stack name: $stack_name" +} + +function syncEnvFile(){ + echo "Syncing environment variables..." >&2 + if [ -f "$PLANE_INSTALL_DIR/plane.env.bak" ]; then + # READ keys of plane.env and update the values from plane.env.bak + while IFS= read -r line + do + # ignore if the line is empty or starts with # + if [ -z "$line" ] || [[ $line == \#* ]]; then + continue + fi + key=$(echo "$line" | cut -d'=' -f1) + value=$(getEnvValue "$key" "$PLANE_INSTALL_DIR/plane.env.bak") + if [ -n "$value" ]; then + updateEnvFile "$key" "$value" "$DOCKER_ENV_PATH" + fi + done < "$DOCKER_ENV_PATH" + + value=$(getEnvValue "STACK_NAME" "$PLANE_INSTALL_DIR/plane.env.bak") + if [ -n "$value" ]; then + updateEnvFile "STACK_NAME" "$value" "$DOCKER_ENV_PATH" + fi + fi + echo "Environment variables synced successfully" >&2 + rm -f $PLANE_INSTALL_DIR/plane.env.bak +} + +function getEnvValue() { + local key=$1 + local file=$2 + + if [ -z "$key" ] || [ -z "$file" ]; then + echo "Invalid arguments supplied" + exit 1 + fi + + if [ -f "$file" ]; then + grep -q "^$key=" "$file" + if [ $? -eq 0 ]; then + local value + value=$(grep "^$key=" "$file" | cut -d'=' -f2) + echo "$value" + else + echo "" + fi + fi +} + +function updateEnvFile() { + local key=$1 + local value=$2 + local file=$3 + + if [ -z "$key" ] || [ -z "$value" ] || [ -z "$file" ]; then + echo "Invalid arguments supplied" + exit 1 + fi + + if [ -f "$file" ]; then + # check if key exists in the file + grep -q "^$key=" "$file" + if [ $? -ne 0 ]; then + echo "$key=$value" >> "$file" + return + else + if [ "$OS_NAME" == "Darwin" ]; then + value=$(echo "$value" | sed 's/|/\\|/g') + sed -i '' "s|^$key=.*|$key=$value|g" "$file" + else + sed -i "s/^$key=.*/$key=$value/g" "$file" + fi + fi + else + echo "File not found: $file" + exit 1 + fi +} + +function download() { + + if [ ! -f "$DOCKER_FILE_PATH" ]; then + echo "Downloading configuration files..." + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/docker-compose.yml -o $DOCKER_FILE_PATH + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH + echo "Configuration files downloaded successfully" + echo "" + # Get stack name before updating variables + getStackName + else + readStackName + fi +} + + +function deployStack() { + # Check if docker compose file and env file exist + if [ ! -f "$DOCKER_FILE_PATH" ] || [ ! -f "$DOCKER_ENV_PATH" ]; then + echo "Configuration files not found" + echo "Downloading it now......" + download + fi + if [ -z "$stack_name" ]; then + getStackName + fi + echo "Starting ${stack_name} stack..." + + # Pull envs + set -o allexport; source $DOCKER_ENV_PATH; set +o allexport; + + # Deploy the stack + docker stack deploy -c $DOCKER_FILE_PATH $stack_name + + echo "Waiting for services to be deployed..." + sleep 10 + + # Check migrator service + local migrator_service=$(docker service ls --filter name=${stack_name}_migrator -q) + if [ -n "$migrator_service" ]; then + echo ">> Waiting for Data Migration to finish" + while docker service ls --filter name=${stack_name}_migrator | grep -q "running"; do + echo -n "." + sleep 1 + done + echo "" + + # Get the most recent container for the migrator service + local migrator_container=$(docker ps -a --filter name=${stack_name}_migrator --latest -q) + + if [ -n "$migrator_container" ]; then + # Get the exit code of the container + local exit_code=$(docker inspect --format='{{.State.ExitCode}}' $migrator_container) + + if [ "$exit_code" != "0" ]; then + echo "Server failed to start ❌" + echo "Migration failed with exit code: $exit_code" + echo "Please check the logs for the 'migrator' service and resolve the issue(s)." + echo "Stop the services by running the command: ./swarm.sh stop" + exit 1 + else + echo " Data Migration completed successfully ✅" + fi + else + echo "Warning: Could not find migrator container to check exit status" + fi + fi + + # Check API service + local api_service=$(docker service ls --filter name=${stack_name}_api -q) + while docker service ls --filter name=${stack_name}_api | grep -q "running"; do + local running_container=$(docker ps --filter "name=${stack_name}_api" --filter "status=running" -q) + if [ -n "$running_container" ]; then + if docker container logs $running_container 2>/dev/null | grep -q "Application Startup Complete"; then + break + fi + fi + sleep 2 + done + + if [ -z "$api_service" ]; then + echo "Plane Server failed to start ❌" + echo "Please check the logs for the 'api' service and resolve the issue(s)." + echo "Stop the services by running the command: ./swarm.sh stop" + exit 1 + fi + echo " Plane Server started successfully ✅" + echo "" + echo " You can access the application at $WEB_URL" + echo "" +} + +# Update other functions to use $stack_name +function removeStack() { + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi + echo "Removing ${stack_name} stack..." + docker stack rm "$stack_name" + echo "Waiting for services to be removed..." + while docker stack ls | grep -q "$stack_name"; do + sleep 1 + done + echo "Services stopped successfully ✅" +} + +function viewSpecificLogs() { + local service=$1 + + # Input validation + if [ -z "$service" ]; then + echo "Error: Please specify a service name" + return 1 + fi + + # Main loop for service logs + while true; do + # Get all running containers for the service + local running_containers=$(docker ps --filter "name=${stack_name}_${service}" --filter "status=running" -q) + + # If no running containers found, try service logs + if [ -z "$running_containers" ]; then + echo "No running containers found for ${stack_name}_${service}, checking service logs..." + if docker service inspect ${stack_name}_${service} >/dev/null 2>&1; then + echo "Press Ctrl+C or 'q' to exit logs" + docker service logs ${stack_name}_${service} -f + break + else + echo "Error: No running containers or services found for ${stack_name}_${service}" + return 1 + fi + return + fi + + # If multiple containers are running, let user choose + if [ $(echo "$running_containers" | grep -v '^$' | wc -l) -gt 1 ]; then + clear + echo "Multiple containers found for ${stack_name}_${service}:" + local i=1 + # Use regular arrays instead of associative arrays + container_ids=() + container_names=() + + while read -r container_id; do + if [ -n "$container_id" ]; then + local container_name=$(docker inspect --format '{{.Name}}' "$container_id" | sed 's/\///') + container_ids[$i]=$container_id + container_names[$i]=$container_name + echo "[$i] ${container_names[$i]} (${container_ids[$i]})" + i=$((i+1)) + fi + done <<< "$running_containers" + + echo -e "\nPlease select a container number:" + read -r selection + + if [[ "$selection" =~ ^[0-9]+$ ]] && [ -n "${container_ids[$selection]}" ]; then + local selected_container=${container_ids[$selection]} + clear + echo "Showing logs for container: ${container_names[$selection]}" + echo "Press Ctrl+C or 'q' to return to container selection" + + # Start watching logs in the background + docker container logs -f "$selected_container" & + local log_pid=$! + + while true; do + read -r -n 1 input + if [[ $input == "q" ]]; then + kill $log_pid 2>/dev/null + wait $log_pid 2>/dev/null + break + fi + done + clear + else + echo "Error: Invalid selection" + sleep 2 + fi + else + # Single container case + local container_name=$(docker inspect --format '{{.Name}}' "$running_containers" | sed 's/\///') + echo "Showing logs for container: $container_name" + echo "Press Ctrl+C or 'q' to exit logs" + docker container logs -f "$running_containers" & + local log_pid=$! + + while true; do + read -r -n 1 input + if [[ $input == "q" ]]; then + kill $log_pid 2>/dev/null + wait $log_pid 2>/dev/null + break + fi + done + break + fi + done +} + +function viewLogs() { + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi + echo "Select a service to view logs:" + echo " 1) API" + echo " 2) Worker" + echo " 3) Beat" + echo " 4) Web" + echo " 5) Proxy" + echo " 6) Space" + echo " 7) Back to Menu" + echo + read -p "Service [1]: " SERVICE + + until [[ -z "$SERVICE" || "$SERVICE" =~ ^[1-7]$ ]]; do + echo "$SERVICE: invalid selection." + read -p "Service [1]: " SERVICE + done + + if [ -z "$SERVICE" ]; then + SERVICE=1 + fi + + if [ "$SERVICE" == "1" ]; then + viewSpecificLogs "api" + elif [ "$SERVICE" == "2" ]; then + viewSpecificLogs "worker" + elif [ "$SERVICE" == "3" ]; then + viewSpecificLogs "beat" + elif [ "$SERVICE" == "4" ]; then + viewSpecificLogs "web" + elif [ "$SERVICE" == "5" ]; then + viewSpecificLogs "proxy" + elif [ "$SERVICE" == "6" ]; then + viewSpecificLogs "space" + elif [ "$SERVICE" == "7" ]; then + askForAction + fi +} + +function viewStatus() { + echo "Checking status of ${stack_name} stack..." + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi + docker stack ps "$stack_name" +} + +function upgrade() { + + local latest_release="stable" + + echo "" + echo "Current release: $APP_RELEASE" + + if [ "$latest_release" == "$APP_RELEASE" ]; then + echo "" + echo "You are already using the latest release" + exit 0 + fi + + echo "Latest release: $latest_release" + echo "" + + # Check for confirmation to upgrade + echo "Do you want to upgrade to the latest release ($latest_release)?" + read -p "Continue? [y/N]: " confirm + + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + echo "Exiting..." + exit 0 + fi + + echo "Upgrading ${stack_name} stack..." + + # check env file and take backup + if [ -f "$DOCKER_ENV_PATH" ]; then + cp "$DOCKER_ENV_PATH" "${DOCKER_ENV_PATH}.bak" + fi + + # fetch new env file + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/docker-compose.yml -o $DOCKER_FILE_PATH + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH + echo "Configuration files downloaded successfully" + echo "" + + NEW_VERSION_NAME=$(getEnvValue "APP_RELEASE" "$DOCKER_ENV_PATH") + syncEnvFile + updateEnvFile "APP_RELEASE" "$NEW_VERSION_NAME" "$DOCKER_ENV_PATH" + if [ -z "$stack_name" ]; then + readStackName + fi + removeStack + deployStack +} + +function askForAction() { + # Rest of askForAction remains the same but use $stack_name instead of $STACK_NAME + local DEFAULT_ACTION=$1 + + if [ -z "$DEFAULT_ACTION" ]; then + echo + echo "Select an Action you want to perform:" + echo " 1) Deploy Stack" + echo " 2) Remove Stack" + echo " 3) View Stack Status" + echo " 4) View Logs" + echo " 5) Upgrade" + echo " 6) Exit" + echo + read -p "Action [3]: " ACTION + until [[ -z "$ACTION" || "$ACTION" =~ ^[1-6]$ ]]; do + echo "$ACTION: invalid selection." + read -p "Action [3]: " ACTION + done + + if [ -z "$ACTION" ]; then + ACTION=3 + fi + echo + fi + + if [ "$ACTION" == "1" ] || [ "$DEFAULT_ACTION" == "deploy" ]; then + deployStack + elif [ "$ACTION" == "2" ] || [ "$DEFAULT_ACTION" == "remove" ]; then + removeStack + elif [ "$ACTION" == "3" ] || [ "$DEFAULT_ACTION" == "status" ]; then + viewStatus + elif [ "$ACTION" == "4" ] || [ "$DEFAULT_ACTION" == "logs" ]; then + viewLogs + elif [ "$ACTION" == "5" ] || [ "$DEFAULT_ACTION" == "upgrade" ]; then + upgrade + elif [ "$ACTION" == "6" ] || [ "$DEFAULT_ACTION" == "exit" ]; then + exit 0 + else + echo "INVALID ACTION SUPPLIED" + fi +} + +# Initialize stack name at script start + +if [ -z "$stack_name" ]; then + readStackName +fi + + +# Main execution +print_header +askForAction "$@" From a847f711eaa856ae3d3a1270429747b87b65e4c5 Mon Sep 17 00:00:00 2001 From: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:16:43 +0530 Subject: [PATCH 02/16] synced docker-compose and swarm-compose --- deploy/selfhost/docker-compose.yml | 78 +++++++++++++++++++++--------- deploy/selfhost/swarm-compose.yml | 16 +----- 2 files changed, 55 insertions(+), 39 deletions(-) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 13cfafa2237..051dbf5b872 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -59,8 +59,6 @@ x-app-env: &app-env services: web: image: ${DOCKERHUB_USER:-makeplane}/plane-frontend:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: node web/server.js web deploy: @@ -68,11 +66,11 @@ services: depends_on: - api - worker + networks: + - plane-network space: image: ${DOCKERHUB_USER:-makeplane}/plane-space:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: node space/server.js space deploy: @@ -81,11 +79,11 @@ services: - api - worker - web + networks: + - plane-network admin: image: ${DOCKERHUB_USER:-makeplane}/plane-admin:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: node admin/server.js admin deploy: @@ -93,11 +91,11 @@ services: depends_on: - api - web + networks: + - plane-network live: image: ${DOCKERHUB_USER:-makeplane}/plane-live:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: node live/dist/server.js live environment: @@ -107,11 +105,11 @@ services: depends_on: - api - web + networks: + - plane-network api: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: ./bin/docker-entrypoint-api.sh deploy: @@ -124,13 +122,15 @@ services: - plane-db - plane-redis - plane-mq + networks: + - plane-network worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: ./bin/docker-entrypoint-worker.sh + deploy: + replicas: ${WORKER_REPLICAS:-1} volumes: - logs_worker:/code/plane/logs environment: @@ -140,13 +140,15 @@ services: - plane-db - plane-redis - plane-mq + networks: + - plane-network beat-worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped command: ./bin/docker-entrypoint-beat.sh + deploy: + replicas: ${BEAT_WORKER_REPLICAS:-1} volumes: - logs_beat-worker:/code/plane/logs environment: @@ -156,13 +158,16 @@ services: - plane-db - plane-redis - plane-mq + networks: + - plane-network migrator: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present - restart: "no" command: ./bin/docker-entrypoint-migrator.sh + deploy: + replicas: 1 + restart_policy: + condition: on-failure volumes: - logs_migrator:/code/plane/logs environment: @@ -170,64 +175,89 @@ services: depends_on: - plane-db - plane-redis + networks: + - plane-network plane-db: image: postgres:15.7-alpine - pull_policy: if_not_present restart: unless-stopped command: postgres -c 'max_connections=1000' + deploy: + replicas: 1 environment: <<: *db-env volumes: - pgdata:/var/lib/postgresql/data + networks: + - plane-network plane-redis: image: valkey/valkey:7.2.5-alpine - pull_policy: if_not_present restart: unless-stopped + deploy: + replicas: 1 volumes: - redisdata:/data + networks: + - plane-network plane-mq: image: rabbitmq:3.13.6-management-alpine restart: always + deploy: + replicas: 1 environment: <<: *mq-env volumes: - rabbitmq_data:/var/lib/rabbitmq + networks: + - plane-network plane-minio: image: minio/minio:latest - pull_policy: if_not_present restart: unless-stopped command: server /export --console-address ":9090" + deploy: + replicas: 1 environment: <<: *minio-env volumes: - uploads:/export + networks: + - plane-network # Comment this if you already have a reverse proxy running proxy: image: ${DOCKERHUB_USER:-makeplane}/plane-proxy:${APP_RELEASE:-stable} - platform: ${DOCKER_PLATFORM:-} - pull_policy: if_not_present restart: unless-stopped ports: - - ${NGINX_PORT}:80 + - target: 80 + published: ${NGINX_PORT:-80} + protocol: tcp + mode: host environment: <<: *proxy-env + deploy: + replicas: 1 depends_on: - web - api - space + networks: + - plane-network volumes: pgdata: redisdata: - uploads: logs_api: logs_worker: logs_beat-worker: logs_migrator: rabbitmq_data: + +networks: + plane-network: + name: plane-network + driver: bridge + attachable: true diff --git a/deploy/selfhost/swarm-compose.yml b/deploy/selfhost/swarm-compose.yml index 2633f7c34a8..14a4f2ee42c 100644 --- a/deploy/selfhost/swarm-compose.yml +++ b/deploy/selfhost/swarm-compose.yml @@ -216,11 +216,6 @@ services: plane-minio: image: minio/minio:latest restart: unless-stopped - ports: - - target: 9090 - published: 9090 - protocol: tcp - mode: host command: server /export --console-address ":9090" deploy: replicas: 1 @@ -237,7 +232,7 @@ services: restart: unless-stopped ports: - target: 80 - published: 80 + published: ${NGINX_PORT:-80} protocol: tcp mode: host environment: @@ -253,25 +248,16 @@ services: volumes: pgdata: - driver: local redisdata: - driver: local uploads: - driver: local logs_api: - driver: local logs_worker: - driver: local logs_beat-worker: - driver: local logs_migrator: - driver: local rabbitmq_data: - driver: local networks: plane-network: name: plane-network driver: overlay attachable: true - \ No newline at end of file From e09c2cd08d98aafbc6023c3b386376f17cfadad8 Mon Sep 17 00:00:00 2001 From: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:19:26 +0530 Subject: [PATCH 03/16] updated the BRANCH variable --- deploy/selfhost/swarm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index 155d6f85569..21218c88126 100644 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -1,6 +1,6 @@ #!/bin/bash -BRANCH=preview +BRANCH=${BRANCH:-master} SERVICE_FOLDER=plane-app PLANE_INSTALL_DIR=$PWD/$SERVICE_FOLDER export APP_RELEASE="stable" From f6bf3676a2be69bab394aaf5e64931ca7d7b3df9 Mon Sep 17 00:00:00 2001 From: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:37:08 +0530 Subject: [PATCH 04/16] fixes --- deploy/selfhost/swarm.sh | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index 21218c88126..4f03c5d381c 100644 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -46,7 +46,6 @@ function checkLatestRelease(){ echo $latest_release } - # Function to read stack name from env file function readStackName() { if [ -f "$DOCKER_ENV_PATH" ]; then @@ -149,17 +148,12 @@ function updateEnvFile() { function download() { - if [ ! -f "$DOCKER_FILE_PATH" ]; then - echo "Downloading configuration files..." - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/docker-compose.yml -o $DOCKER_FILE_PATH - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH - echo "Configuration files downloaded successfully" - echo "" - # Get stack name before updating variables - getStackName - else - readStackName - fi + echo "Downloading configuration files..." + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/swarm-compose.yml -o $DOCKER_FILE_PATH + curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH + echo "Configuration files downloaded successfully" + echo "" + } @@ -400,6 +394,12 @@ function viewStatus() { } function upgrade() { + + echo "Checking status of ${stack_name} stack..." + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi local latest_release="stable" @@ -431,19 +431,12 @@ function upgrade() { cp "$DOCKER_ENV_PATH" "${DOCKER_ENV_PATH}.bak" fi - # fetch new env file - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/docker-compose.yml -o $DOCKER_FILE_PATH - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH - echo "Configuration files downloaded successfully" - echo "" - + download NEW_VERSION_NAME=$(getEnvValue "APP_RELEASE" "$DOCKER_ENV_PATH") syncEnvFile updateEnvFile "APP_RELEASE" "$NEW_VERSION_NAME" "$DOCKER_ENV_PATH" - if [ -z "$stack_name" ]; then - readStackName - fi - removeStack + + removeStack deployStack } From e328efbb29871d374387b23ae538e9e1d4164435 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 15:08:21 +0530 Subject: [PATCH 05/16] fix: swarm script upgrade function and `APP_RELEASE` variable --- deploy/selfhost/docker-compose.yml | 2 +- deploy/selfhost/swarm.sh | 99 +++++++++++++++++++++++++++--- 2 files changed, 90 insertions(+), 11 deletions(-) mode change 100644 => 100755 deploy/selfhost/swarm.sh diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 051dbf5b872..14a4f2ee42c 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -259,5 +259,5 @@ volumes: networks: plane-network: name: plane-network - driver: bridge + driver: overlay attachable: true diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh old mode 100644 new mode 100755 index 4f03c5d381c..a210eaff2d9 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -2,6 +2,7 @@ BRANCH=${BRANCH:-master} SERVICE_FOLDER=plane-app +SCRIPT_DIR=$PWD PLANE_INSTALL_DIR=$PWD/$SERVICE_FOLDER export APP_RELEASE="stable" export DOCKERHUB_USER=makeplane @@ -146,22 +147,83 @@ function updateEnvFile() { fi } + + function download() { + cd $SCRIPT_DIR + TS=$(date +%s) + if [ -f "$PLANE_INSTALL_DIR/docker-compose.yaml" ] + then + mv $PLANE_INSTALL_DIR/docker-compose.yaml $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml + fi - echo "Downloading configuration files..." - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/swarm-compose.yml -o $DOCKER_FILE_PATH - curl -L https://raw.githubusercontent.com/${GH_REPO}/refs/heads/${BRANCH}/deploy/selfhost/variables.env -o $DOCKER_ENV_PATH - echo "Configuration files downloaded successfully" - echo "" + echo $RELEASE_DOWNLOAD_URL + echo $FALLBACK_DOWNLOAD_URL + echo $APP_RELEASE -} + RESPONSE=$(curl -H 'Cache-Control: no-cache, no-store' -s -w "HTTPSTATUS:%{http_code}" "$RELEASE_DOWNLOAD_URL/$APP_RELEASE/docker-compose.yml?$(date +%s)") + BODY=$(echo "$RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + if [ "$STATUS" -eq 200 ]; then + echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yaml + else + # Fallback to download from the raw github url + RESPONSE=$(curl -H 'Cache-Control: no-cache, no-store' -s -w "HTTPSTATUS:%{http_code}" "$FALLBACK_DOWNLOAD_URL/docker-compose.yml?$(date +%s)") + BODY=$(echo "$RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + + if [ "$STATUS" -eq 200 ]; then + echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yaml + else + echo "Failed to download docker-compose.yml. HTTP Status: $STATUS" + echo "URL: $RELEASE_DOWNLOAD_URL/$APP_RELEASE/docker-compose.yml" + mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml $PLANE_INSTALL_DIR/docker-compose.yaml + exit 1 + fi + fi + + RESPONSE=$(curl -H 'Cache-Control: no-cache, no-store' -s -w "HTTPSTATUS:%{http_code}" "$RELEASE_DOWNLOAD_URL/$APP_RELEASE/variables.env?$(date +%s)") + BODY=$(echo "$RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + + if [ "$STATUS" -eq 200 ]; then + echo "$BODY" > $PLANE_INSTALL_DIR/variables-upgrade.env + else + # Fallback to download from the raw github url + RESPONSE=$(curl -H 'Cache-Control: no-cache, no-store' -s -w "HTTPSTATUS:%{http_code}" "$FALLBACK_DOWNLOAD_URL/variables.env?$(date +%s)") + BODY=$(echo "$RESPONSE" | sed -e 's/HTTPSTATUS\:.*//g') + STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') + + if [ "$STATUS" -eq 200 ]; then + echo "$BODY" > $PLANE_INSTALL_DIR/variables-upgrade.env + else + echo "Failed to download variables.env. HTTP Status: $STATUS" + echo "URL: $RELEASE_DOWNLOAD_URL/$APP_RELEASE/variables.env" + mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml $PLANE_INSTALL_DIR/docker-compose.yaml + exit 1 + fi + fi + if [ -f "$DOCKER_ENV_PATH" ]; + then + cp "$DOCKER_ENV_PATH" "$PLANE_INSTALL_DIR/archive/$TS.env" + cp "$DOCKER_ENV_PATH" "$PLANE_INSTALL_DIR/plane.env.bak" + fi + + mv $PLANE_INSTALL_DIR/variables-upgrade.env $DOCKER_ENV_PATH + + syncEnvFile + + updateEnvFile "APP_RELEASE" "$APP_RELEASE" "$DOCKER_ENV_PATH" + +} function deployStack() { # Check if docker compose file and env file exist if [ ! -f "$DOCKER_FILE_PATH" ] || [ ! -f "$DOCKER_ENV_PATH" ]; then echo "Configuration files not found" echo "Downloading it now......" + APP_RELEASE=$(checkLatestRelease) download fi if [ -z "$stack_name" ]; then @@ -401,7 +463,7 @@ function upgrade() { exit 1 fi - local latest_release="stable" + local latest_release=$(checkLatestRelease) echo "" echo "Current release: $APP_RELEASE" @@ -424,6 +486,9 @@ function upgrade() { exit 0 fi + export APP_RELEASE=$latest_release + + # check if stack exists echo "Upgrading ${stack_name} stack..." # check env file and take backup @@ -432,9 +497,7 @@ function upgrade() { fi download - NEW_VERSION_NAME=$(getEnvValue "APP_RELEASE" "$DOCKER_ENV_PATH") - syncEnvFile - updateEnvFile "APP_RELEASE" "$NEW_VERSION_NAME" "$DOCKER_ENV_PATH" + removeStack deployStack @@ -489,6 +552,22 @@ if [ -z "$stack_name" ]; then readStackName fi +# Sync environment variables +if [ -f "$DOCKER_ENV_PATH" ]; then + DOCKERHUB_USER=$(getEnvValue "DOCKERHUB_USER" "$DOCKER_ENV_PATH") + APP_RELEASE=$(getEnvValue "APP_RELEASE" "$DOCKER_ENV_PATH") + + if [ -z "$DOCKERHUB_USER" ]; then + DOCKERHUB_USER=makeplane + updateEnvFile "DOCKERHUB_USER" "$DOCKERHUB_USER" "$DOCKER_ENV_PATH" + fi + + if [ -z "$APP_RELEASE" ]; then + APP_RELEASE=stable + updateEnvFile "APP_RELEASE" "$APP_RELEASE" "$DOCKER_ENV_PATH" + fi +fi + # Main execution print_header From 0f02bfae26f4700174ca8208bc42e6d697a337cb Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 16:13:12 +0530 Subject: [PATCH 06/16] fix: remove network from compose file and fix swarm script --- deploy/selfhost/docker-compose.yml | 32 ---- deploy/selfhost/swarm-compose.yml | 263 ----------------------------- deploy/selfhost/swarm.sh | 16 +- 3 files changed, 7 insertions(+), 304 deletions(-) delete mode 100644 deploy/selfhost/swarm-compose.yml diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 14a4f2ee42c..6f843b8baae 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -66,8 +66,6 @@ services: depends_on: - api - worker - networks: - - plane-network space: image: ${DOCKERHUB_USER:-makeplane}/plane-space:${APP_RELEASE:-stable} @@ -79,8 +77,6 @@ services: - api - worker - web - networks: - - plane-network admin: image: ${DOCKERHUB_USER:-makeplane}/plane-admin:${APP_RELEASE:-stable} @@ -91,8 +87,6 @@ services: depends_on: - api - web - networks: - - plane-network live: image: ${DOCKERHUB_USER:-makeplane}/plane-live:${APP_RELEASE:-stable} @@ -105,8 +99,6 @@ services: depends_on: - api - web - networks: - - plane-network api: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} @@ -122,8 +114,6 @@ services: - plane-db - plane-redis - plane-mq - networks: - - plane-network worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} @@ -140,8 +130,6 @@ services: - plane-db - plane-redis - plane-mq - networks: - - plane-network beat-worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} @@ -158,8 +146,6 @@ services: - plane-db - plane-redis - plane-mq - networks: - - plane-network migrator: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} @@ -175,8 +161,6 @@ services: depends_on: - plane-db - plane-redis - networks: - - plane-network plane-db: image: postgres:15.7-alpine @@ -188,8 +172,6 @@ services: <<: *db-env volumes: - pgdata:/var/lib/postgresql/data - networks: - - plane-network plane-redis: image: valkey/valkey:7.2.5-alpine @@ -198,8 +180,6 @@ services: replicas: 1 volumes: - redisdata:/data - networks: - - plane-network plane-mq: image: rabbitmq:3.13.6-management-alpine @@ -210,8 +190,6 @@ services: <<: *mq-env volumes: - rabbitmq_data:/var/lib/rabbitmq - networks: - - plane-network plane-minio: image: minio/minio:latest @@ -223,8 +201,6 @@ services: <<: *minio-env volumes: - uploads:/export - networks: - - plane-network # Comment this if you already have a reverse proxy running proxy: @@ -243,8 +219,6 @@ services: - web - api - space - networks: - - plane-network volumes: pgdata: @@ -255,9 +229,3 @@ volumes: logs_beat-worker: logs_migrator: rabbitmq_data: - -networks: - plane-network: - name: plane-network - driver: overlay - attachable: true diff --git a/deploy/selfhost/swarm-compose.yml b/deploy/selfhost/swarm-compose.yml deleted file mode 100644 index 14a4f2ee42c..00000000000 --- a/deploy/selfhost/swarm-compose.yml +++ /dev/null @@ -1,263 +0,0 @@ -x-db-env: &db-env - PGHOST: ${PGHOST:-plane-db} - PGDATABASE: ${PGDATABASE:-plane} - POSTGRES_USER: ${POSTGRES_USER:-plane} - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-plane} - POSTGRES_DB: ${POSTGRES_DB:-plane} - POSTGRES_PORT: ${POSTGRES_PORT:-5432} - PGDATA: ${PGDATA:-/var/lib/postgresql/data} - -x-redis-env: &redis-env - REDIS_HOST: ${REDIS_HOST:-plane-redis} - REDIS_PORT: ${REDIS_PORT:-6379} - REDIS_URL: ${REDIS_URL:-redis://plane-redis:6379/} - -x-minio-env: &minio-env - MINIO_ROOT_USER: ${AWS_ACCESS_KEY_ID:-access-key} - MINIO_ROOT_PASSWORD: ${AWS_SECRET_ACCESS_KEY:-secret-key} - -x-aws-s3-env: &aws-s3-env - AWS_REGION: ${AWS_REGION:-} - AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID:-access-key} - AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY:-secret-key} - AWS_S3_ENDPOINT_URL: ${AWS_S3_ENDPOINT_URL:-http://plane-minio:9000} - AWS_S3_BUCKET_NAME: ${AWS_S3_BUCKET_NAME:-uploads} - -x-proxy-env: &proxy-env - NGINX_PORT: ${NGINX_PORT:-80} - BUCKET_NAME: ${AWS_S3_BUCKET_NAME:-uploads} - FILE_SIZE_LIMIT: ${FILE_SIZE_LIMIT:-5242880} - -x-mq-env: &mq-env - # RabbitMQ Settings - RABBITMQ_HOST: ${RABBITMQ_HOST:-plane-mq} - RABBITMQ_PORT: ${RABBITMQ_PORT:-5672} - RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER:-plane} - RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD:-plane} - RABBITMQ_DEFAULT_VHOST: ${RABBITMQ_VHOST:-plane} - RABBITMQ_VHOST: ${RABBITMQ_VHOST:-plane} - -x-live-env: &live-env - API_BASE_URL: ${API_BASE_URL:-http://api:8000} - -x-app-env: &app-env - WEB_URL: ${WEB_URL:-http://localhost} - DEBUG: ${DEBUG:-0} - SENTRY_DSN: ${SENTRY_DSN} - SENTRY_ENVIRONMENT: ${SENTRY_ENVIRONMENT:-production} - CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS} - GUNICORN_WORKERS: 1 - USE_MINIO: ${USE_MINIO:-1} - DATABASE_URL: ${DATABASE_URL:-postgresql://plane:plane@plane-db/plane} - SECRET_KEY: ${SECRET_KEY:-60gp0byfz2dvffa45cxl20p1scy9xbpf6d8c5y0geejgkyp1b5} - ADMIN_BASE_URL: ${ADMIN_BASE_URL} - SPACE_BASE_URL: ${SPACE_BASE_URL} - APP_BASE_URL: ${APP_BASE_URL} - AMQP_URL: ${AMQP_URL:-amqp://plane:plane@plane-mq:5672/plane} - - -services: - web: - image: ${DOCKERHUB_USER:-makeplane}/plane-frontend:${APP_RELEASE:-stable} - restart: unless-stopped - command: node web/server.js web - deploy: - replicas: ${WEB_REPLICAS:-1} - depends_on: - - api - - worker - networks: - - plane-network - - space: - image: ${DOCKERHUB_USER:-makeplane}/plane-space:${APP_RELEASE:-stable} - restart: unless-stopped - command: node space/server.js space - deploy: - replicas: ${SPACE_REPLICAS:-1} - depends_on: - - api - - worker - - web - networks: - - plane-network - - admin: - image: ${DOCKERHUB_USER:-makeplane}/plane-admin:${APP_RELEASE:-stable} - restart: unless-stopped - command: node admin/server.js admin - deploy: - replicas: ${ADMIN_REPLICAS:-1} - depends_on: - - api - - web - networks: - - plane-network - - live: - image: ${DOCKERHUB_USER:-makeplane}/plane-live:${APP_RELEASE:-stable} - restart: unless-stopped - command: node live/dist/server.js live - environment: - <<: [ *live-env ] - deploy: - replicas: ${LIVE_REPLICAS:-1} - depends_on: - - api - - web - networks: - - plane-network - - api: - image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped - command: ./bin/docker-entrypoint-api.sh - deploy: - replicas: ${API_REPLICAS:-1} - volumes: - - logs_api:/code/plane/logs - environment: - <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] - depends_on: - - plane-db - - plane-redis - - plane-mq - networks: - - plane-network - - worker: - image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped - command: ./bin/docker-entrypoint-worker.sh - deploy: - replicas: ${WORKER_REPLICAS:-1} - volumes: - - logs_worker:/code/plane/logs - environment: - <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] - depends_on: - - api - - plane-db - - plane-redis - - plane-mq - networks: - - plane-network - - beat-worker: - image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped - command: ./bin/docker-entrypoint-beat.sh - deploy: - replicas: ${BEAT_WORKER_REPLICAS:-1} - volumes: - - logs_beat-worker:/code/plane/logs - environment: - <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] - depends_on: - - api - - plane-db - - plane-redis - - plane-mq - networks: - - plane-network - - migrator: - image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - command: ./bin/docker-entrypoint-migrator.sh - deploy: - replicas: 1 - restart_policy: - condition: on-failure - volumes: - - logs_migrator:/code/plane/logs - environment: - <<: [ *app-env, *db-env, *redis-env, *minio-env, *aws-s3-env, *proxy-env ] - depends_on: - - plane-db - - plane-redis - networks: - - plane-network - - plane-db: - image: postgres:15.7-alpine - restart: unless-stopped - command: postgres -c 'max_connections=1000' - deploy: - replicas: 1 - environment: - <<: *db-env - volumes: - - pgdata:/var/lib/postgresql/data - networks: - - plane-network - - plane-redis: - image: valkey/valkey:7.2.5-alpine - restart: unless-stopped - deploy: - replicas: 1 - volumes: - - redisdata:/data - networks: - - plane-network - - plane-mq: - image: rabbitmq:3.13.6-management-alpine - restart: always - deploy: - replicas: 1 - environment: - <<: *mq-env - volumes: - - rabbitmq_data:/var/lib/rabbitmq - networks: - - plane-network - - plane-minio: - image: minio/minio:latest - restart: unless-stopped - command: server /export --console-address ":9090" - deploy: - replicas: 1 - environment: - <<: *minio-env - volumes: - - uploads:/export - networks: - - plane-network - - # Comment this if you already have a reverse proxy running - proxy: - image: ${DOCKERHUB_USER:-makeplane}/plane-proxy:${APP_RELEASE:-stable} - restart: unless-stopped - ports: - - target: 80 - published: ${NGINX_PORT:-80} - protocol: tcp - mode: host - environment: - <<: *proxy-env - deploy: - replicas: 1 - depends_on: - - web - - api - - space - networks: - - plane-network - -volumes: - pgdata: - redisdata: - uploads: - logs_api: - logs_worker: - logs_beat-worker: - logs_migrator: - rabbitmq_data: - -networks: - plane-network: - name: plane-network - driver: overlay - attachable: true diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index a210eaff2d9..748709146cf 100755 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -16,7 +16,7 @@ OS_NAME=$(uname) # Create necessary directories mkdir -p $PLANE_INSTALL_DIR/archive -DOCKER_FILE_PATH=$PLANE_INSTALL_DIR/swarm-compose.yml +DOCKER_FILE_PATH=$PLANE_INSTALL_DIR/docker-compose.yml DOCKER_ENV_PATH=$PLANE_INSTALL_DIR/plane.env function print_header() { @@ -147,14 +147,12 @@ function updateEnvFile() { fi } - - function download() { cd $SCRIPT_DIR TS=$(date +%s) - if [ -f "$PLANE_INSTALL_DIR/docker-compose.yaml" ] + if [ -f "$PLANE_INSTALL_DIR/docker-compose.yml" ] then - mv $PLANE_INSTALL_DIR/docker-compose.yaml $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml + mv $PLANE_INSTALL_DIR/docker-compose.yml $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yml fi echo $RELEASE_DOWNLOAD_URL @@ -166,7 +164,7 @@ function download() { STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') if [ "$STATUS" -eq 200 ]; then - echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yaml + echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yml else # Fallback to download from the raw github url RESPONSE=$(curl -H 'Cache-Control: no-cache, no-store' -s -w "HTTPSTATUS:%{http_code}" "$FALLBACK_DOWNLOAD_URL/docker-compose.yml?$(date +%s)") @@ -174,11 +172,11 @@ function download() { STATUS=$(echo "$RESPONSE" | tr -d '\n' | sed -e 's/.*HTTPSTATUS://') if [ "$STATUS" -eq 200 ]; then - echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yaml + echo "$BODY" > $PLANE_INSTALL_DIR/docker-compose.yml else echo "Failed to download docker-compose.yml. HTTP Status: $STATUS" echo "URL: $RELEASE_DOWNLOAD_URL/$APP_RELEASE/docker-compose.yml" - mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml $PLANE_INSTALL_DIR/docker-compose.yaml + mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yml $PLANE_INSTALL_DIR/docker-compose.yml exit 1 fi fi @@ -200,7 +198,7 @@ function download() { else echo "Failed to download variables.env. HTTP Status: $STATUS" echo "URL: $RELEASE_DOWNLOAD_URL/$APP_RELEASE/variables.env" - mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yaml $PLANE_INSTALL_DIR/docker-compose.yaml + mv $PLANE_INSTALL_DIR/archive/$TS.docker-compose.yml $PLANE_INSTALL_DIR/docker-compose.yml exit 1 fi fi From 880b9ebc1490fe42023200dddcb16190ac027ee7 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 16:22:34 +0530 Subject: [PATCH 07/16] removed property restart from docker compose file --- deploy/selfhost/docker-compose.yml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 6f843b8baae..db6f6994ac3 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -59,7 +59,6 @@ x-app-env: &app-env services: web: image: ${DOCKERHUB_USER:-makeplane}/plane-frontend:${APP_RELEASE:-stable} - restart: unless-stopped command: node web/server.js web deploy: replicas: ${WEB_REPLICAS:-1} @@ -69,7 +68,6 @@ services: space: image: ${DOCKERHUB_USER:-makeplane}/plane-space:${APP_RELEASE:-stable} - restart: unless-stopped command: node space/server.js space deploy: replicas: ${SPACE_REPLICAS:-1} @@ -80,7 +78,6 @@ services: admin: image: ${DOCKERHUB_USER:-makeplane}/plane-admin:${APP_RELEASE:-stable} - restart: unless-stopped command: node admin/server.js admin deploy: replicas: ${ADMIN_REPLICAS:-1} @@ -90,7 +87,6 @@ services: live: image: ${DOCKERHUB_USER:-makeplane}/plane-live:${APP_RELEASE:-stable} - restart: unless-stopped command: node live/dist/server.js live environment: <<: [ *live-env ] @@ -102,7 +98,6 @@ services: api: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped command: ./bin/docker-entrypoint-api.sh deploy: replicas: ${API_REPLICAS:-1} @@ -117,7 +112,6 @@ services: worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped command: ./bin/docker-entrypoint-worker.sh deploy: replicas: ${WORKER_REPLICAS:-1} @@ -133,7 +127,6 @@ services: beat-worker: image: ${DOCKERHUB_USER:-makeplane}/plane-backend:${APP_RELEASE:-stable} - restart: unless-stopped command: ./bin/docker-entrypoint-beat.sh deploy: replicas: ${BEAT_WORKER_REPLICAS:-1} @@ -164,7 +157,6 @@ services: plane-db: image: postgres:15.7-alpine - restart: unless-stopped command: postgres -c 'max_connections=1000' deploy: replicas: 1 @@ -175,7 +167,6 @@ services: plane-redis: image: valkey/valkey:7.2.5-alpine - restart: unless-stopped deploy: replicas: 1 volumes: @@ -193,7 +184,6 @@ services: plane-minio: image: minio/minio:latest - restart: unless-stopped command: server /export --console-address ":9090" deploy: replicas: 1 @@ -205,7 +195,6 @@ services: # Comment this if you already have a reverse proxy running proxy: image: ${DOCKERHUB_USER:-makeplane}/plane-proxy:${APP_RELEASE:-stable} - restart: unless-stopped ports: - target: 80 published: ${NGINX_PORT:-80} From 0ab651450613521c3cce372ed60bf95181deb6f7 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 16:32:28 +0530 Subject: [PATCH 08/16] added restart_policy condition in docker compose --- deploy/selfhost/docker-compose.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index db6f6994ac3..f1b984fa9c0 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -62,6 +62,8 @@ services: command: node web/server.js web deploy: replicas: ${WEB_REPLICAS:-1} + restart_policy: + condition: unless-stopped depends_on: - api - worker @@ -71,6 +73,8 @@ services: command: node space/server.js space deploy: replicas: ${SPACE_REPLICAS:-1} + restart_policy: + condition: unless-stopped depends_on: - api - worker @@ -81,6 +85,8 @@ services: command: node admin/server.js admin deploy: replicas: ${ADMIN_REPLICAS:-1} + restart_policy: + condition: unless-stopped depends_on: - api - web @@ -92,6 +98,8 @@ services: <<: [ *live-env ] deploy: replicas: ${LIVE_REPLICAS:-1} + restart_policy: + condition: unless-stopped depends_on: - api - web @@ -101,6 +109,8 @@ services: command: ./bin/docker-entrypoint-api.sh deploy: replicas: ${API_REPLICAS:-1} + restart_policy: + condition: unless-stopped volumes: - logs_api:/code/plane/logs environment: @@ -115,6 +125,8 @@ services: command: ./bin/docker-entrypoint-worker.sh deploy: replicas: ${WORKER_REPLICAS:-1} + restart_policy: + condition: unless-stopped volumes: - logs_worker:/code/plane/logs environment: @@ -130,6 +142,8 @@ services: command: ./bin/docker-entrypoint-beat.sh deploy: replicas: ${BEAT_WORKER_REPLICAS:-1} + restart_policy: + condition: unless-stopped volumes: - logs_beat-worker:/code/plane/logs environment: @@ -160,6 +174,8 @@ services: command: postgres -c 'max_connections=1000' deploy: replicas: 1 + restart_policy: + condition: unless-stopped environment: <<: *db-env volumes: @@ -169,6 +185,8 @@ services: image: valkey/valkey:7.2.5-alpine deploy: replicas: 1 + restart_policy: + condition: unless-stopped volumes: - redisdata:/data @@ -177,6 +195,8 @@ services: restart: always deploy: replicas: 1 + restart_policy: + condition: unless-stopped environment: <<: *mq-env volumes: @@ -187,6 +207,8 @@ services: command: server /export --console-address ":9090" deploy: replicas: 1 + restart_policy: + condition: unless-stopped environment: <<: *minio-env volumes: @@ -204,6 +226,8 @@ services: <<: *proxy-env deploy: replicas: 1 + restart_policy: + condition: unless-stopped depends_on: - web - api From 83e81e234a6dd2cca31feae2aaebbc1cc6c2cb53 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 16:40:34 +0530 Subject: [PATCH 09/16] fix: changed restart policy to `any` --- deploy/selfhost/docker-compose.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index f1b984fa9c0..467194f7784 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -63,7 +63,7 @@ services: deploy: replicas: ${WEB_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any depends_on: - api - worker @@ -74,7 +74,7 @@ services: deploy: replicas: ${SPACE_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any depends_on: - api - worker @@ -86,7 +86,7 @@ services: deploy: replicas: ${ADMIN_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any depends_on: - api - web @@ -99,7 +99,7 @@ services: deploy: replicas: ${LIVE_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any depends_on: - api - web @@ -110,7 +110,7 @@ services: deploy: replicas: ${API_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any volumes: - logs_api:/code/plane/logs environment: @@ -126,7 +126,7 @@ services: deploy: replicas: ${WORKER_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any volumes: - logs_worker:/code/plane/logs environment: @@ -143,7 +143,7 @@ services: deploy: replicas: ${BEAT_WORKER_REPLICAS:-1} restart_policy: - condition: unless-stopped + condition: any volumes: - logs_beat-worker:/code/plane/logs environment: @@ -175,7 +175,7 @@ services: deploy: replicas: 1 restart_policy: - condition: unless-stopped + condition: any environment: <<: *db-env volumes: @@ -186,7 +186,7 @@ services: deploy: replicas: 1 restart_policy: - condition: unless-stopped + condition: any volumes: - redisdata:/data @@ -196,7 +196,7 @@ services: deploy: replicas: 1 restart_policy: - condition: unless-stopped + condition: any environment: <<: *mq-env volumes: @@ -208,7 +208,7 @@ services: deploy: replicas: 1 restart_policy: - condition: unless-stopped + condition: any environment: <<: *minio-env volumes: @@ -227,7 +227,7 @@ services: deploy: replicas: 1 restart_policy: - condition: unless-stopped + condition: any depends_on: - web - api From 0be8b9fc7c5de03c3959b0365063def6061d5d01 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 17:37:17 +0530 Subject: [PATCH 10/16] changed `restart_policy` from `any` to `on-failure` --- deploy/selfhost/docker-compose.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index 467194f7784..b0d0957f31d 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -63,7 +63,7 @@ services: deploy: replicas: ${WEB_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure depends_on: - api - worker @@ -74,7 +74,7 @@ services: deploy: replicas: ${SPACE_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure depends_on: - api - worker @@ -86,7 +86,7 @@ services: deploy: replicas: ${ADMIN_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure depends_on: - api - web @@ -99,7 +99,7 @@ services: deploy: replicas: ${LIVE_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure depends_on: - api - web @@ -110,7 +110,7 @@ services: deploy: replicas: ${API_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure volumes: - logs_api:/code/plane/logs environment: @@ -126,7 +126,7 @@ services: deploy: replicas: ${WORKER_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure volumes: - logs_worker:/code/plane/logs environment: @@ -143,7 +143,7 @@ services: deploy: replicas: ${BEAT_WORKER_REPLICAS:-1} restart_policy: - condition: any + condition: on-failure volumes: - logs_beat-worker:/code/plane/logs environment: @@ -175,7 +175,7 @@ services: deploy: replicas: 1 restart_policy: - condition: any + condition: on-failure environment: <<: *db-env volumes: @@ -186,7 +186,7 @@ services: deploy: replicas: 1 restart_policy: - condition: any + condition: on-failure volumes: - redisdata:/data @@ -196,7 +196,7 @@ services: deploy: replicas: 1 restart_policy: - condition: any + condition: on-failure environment: <<: *mq-env volumes: @@ -208,7 +208,7 @@ services: deploy: replicas: 1 restart_policy: - condition: any + condition: on-failure environment: <<: *minio-env volumes: @@ -227,7 +227,7 @@ services: deploy: replicas: 1 restart_policy: - condition: any + condition: on-failure depends_on: - web - api From 1d838ed8342f37444d61b01915919cf98875d353 Mon Sep 17 00:00:00 2001 From: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Date: Wed, 15 Jan 2025 18:24:39 +0530 Subject: [PATCH 11/16] updated selfhost readme --- .github/workflows/build-branch.yml | 2 + deploy/selfhost/README.md | 147 ++++++++++++++++++++++++++--- 2 files changed, 136 insertions(+), 13 deletions(-) diff --git a/.github/workflows/build-branch.yml b/.github/workflows/build-branch.yml index 7d32b73c4e1..8b7e1d5e291 100644 --- a/.github/workflows/build-branch.yml +++ b/.github/workflows/build-branch.yml @@ -316,6 +316,7 @@ jobs: retention-days: 2 path: | ${{ github.workspace }}/deploy/selfhost/setup.sh + ${{ github.workspace }}/deploy/selfhost/swarm.sh ${{ github.workspace }}/deploy/selfhost/restore.sh ${{ github.workspace }}/deploy/selfhost/docker-compose.yml ${{ github.workspace }}/deploy/selfhost/variables.env @@ -358,6 +359,7 @@ jobs: generate_release_notes: true files: | ${{ github.workspace }}/deploy/selfhost/setup.sh + ${{ github.workspace }}/deploy/selfhost/swarm.sh ${{ github.workspace }}/deploy/selfhost/restore.sh ${{ github.workspace }}/deploy/selfhost/docker-compose.yml ${{ github.workspace }}/deploy/selfhost/variables.env diff --git a/deploy/selfhost/README.md b/deploy/selfhost/README.md index ccd8bf328ce..4fad496afa3 100644 --- a/deploy/selfhost/README.md +++ b/deploy/selfhost/README.md @@ -55,18 +55,30 @@ Installing plane is a very easy and minimal step process. - User context used must have access to docker services. In most cases, use sudo su to switch as root user - Use the terminal (or gitbash) window to run all the future steps -### Downloading Latest Stable Release +### Downloading Latest Release ``` mkdir plane-selfhost cd plane-selfhost +``` + +#### For *Docker Compose* based setup +``` curl -fsSL -o setup.sh https://github.com/makeplane/plane/releases/latest/download/setup.sh chmod +x setup.sh ``` +#### For *Docker Swarm* based setup + +``` +curl -fsSL -o setup.sh https://github.com/makeplane/plane/releases/latest/download/swarm.sh + +chmod +x setup.sh +``` + --- ### Proceed with setup @@ -77,8 +89,9 @@ Lets get started by running the `./setup.sh` command. This will prompt you with the below options. +#### Docker Compose ```bash -Select a Action you want to perform: +Select an Action you want to perform: 1) Install (x86_64) 2) Start 3) Stop @@ -87,18 +100,43 @@ Select a Action you want to perform: 6) View Logs 7) Backup Data 8) Exit + Action [2]: 1 ``` For the 1st time setup, type "1" as action input. -This will create a create a folder `plane-app` or `plane-app-preview` (in case of preview deployment) and will download 2 files inside that +This will create a create a folder `plane-app` and will download 2 files inside that - `docker-compose.yaml` - `plane.env` Again the `options [1-8]` will be popped up and this time hit `8` to exit. +#### Docker Swarm + +```bash +Select an Action you want to perform: + 1) Deploy Stack + 2) Remove Stack + 3) View Stack Status + 4) Redeploy Stack + 5) Upgrade + 6) View Logs + 7) Exit + +Action [3]: 1 +``` + +For the 1st time setup, type "1" as action input. + +This will create a create a folder `plane-app` and will download 2 files inside that + +- `docker-compose.yaml` +- `plane.env` + +Again the `options [1-7]` will be popped up and this time hit `7` to exit. + --- ### Continue with setup - Environment Settings @@ -116,7 +154,7 @@ There are many other settings you can play with, but we suggest you configure `E --- -### Continue with setup - Start Server +### Continue with setup - Start Server (Docker Compose) Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `2` to start the sevices @@ -147,9 +185,11 @@ You have successfully self hosted `Plane` instance. Access the application by go --- -### Stopping the Server +### Stopping the Server / Remove Stack + +In case you want to make changes to `plane.env` variables, we suggest you to stop the services before doing that. -In case you want to make changes to `.env` variables, we suggest you to stop the services before doing that. +#### Docker Compose Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `3` to stop the sevices @@ -171,14 +211,34 @@ If all goes well, you must see something like this ![Stop Services](images/stopped.png) +#### Docker Swarm + +Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `2` to stop the sevices + +```bash +Select an Action you want to perform: + 1) Deploy Stack + 2) Remove Stack + 3) View Stack Status + 4) Redeploy Stack + 5) Upgrade + 6) View Logs + 7) Exit + +Action [3]: 2 +``` + +If all goes well, you will see the confirmation from docker cli + --- -### Restarting the Server +### Restarting the Server / Redeploy Stack -In case you want to make changes to `.env` variables, without stopping the server or you noticed some abnormalies in services, you can restart the services with RESTART option. +In case you want to make changes to `plane.env` variables, without stopping the server or you noticed some abnormalies in services, you can restart the services with `RESTART` / `REDEPLOY` option. Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `4` to restart the sevices +#### Docker Compose ```bash Select a Action you want to perform: 1) Install (x86_64) @@ -197,14 +257,32 @@ If all goes well, you must see something like this ![Restart Services](images/restart.png) +#### Docker Swarm + +```bash + 1) Deploy Stack + 2) Remove Stack + 3) View Stack Status + 4) Redeploy Stack + 5) Upgrade + 6) View Logs + 7) Exit + +Action [3]: 4 +``` + +If all goes well, you will see the confirmation from docker cli + --- -### Upgrading Plane Version +### Upgrading Plane Version It is always advised to keep Plane up to date with the latest release. Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `5` to upgrade the release. +#### Docker Compose + ```bash Select a Action you want to perform: 1) Install (x86_64) @@ -231,13 +309,41 @@ Once done, choose `8` to exit from prompt. Once done with making changes in `plane.env` file, jump on to `Start Server` +#### Docker Swarm + +Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `5` to upgrade the release. + +```bash + 1) Deploy Stack + 2) Remove Stack + 3) View Stack Status + 4) Redeploy Stack + 5) Upgrade + 6) View Logs + 7) Exit + +Action [3]: 5 +``` + +By choosing this, it will stop the services and then will download the latest `docker-compose.yaml` and `plane.env`. + +Once done, choose `7` to exit from prompt. + +> It is very important for you to validate the `plane.env` for the new changes. + +Once done with making changes in `plane.env` file, jump on to `Redeploy Stack` + --- ### View Logs There would a time when you might want to check what is happening inside the API, Worker or any other container. -Lets again run the `./setup.sh` command. You will again be prompted with the below options. This time select `6` to view logs. +Lets again run the `./setup.sh` command. You will again be prompted with the below options. + +This time select `6` to view logs. + +#### Docker Compose ```bash Select a Action you want to perform: @@ -253,7 +359,22 @@ Select a Action you want to perform: Action [2]: 6 ``` +#### Docker Swarm + + +```bash + 1) Deploy Stack + 2) Remove Stack + 3) View Stack Status + 4) Redeploy Stack + 5) Upgrade + 6) View Logs + 7) Exit + +Action [3]: 6 +``` +#### Service Menu Options for Logs This will further open sub-menu with list of services ```bash Select a Service you want to view the logs for: @@ -269,7 +390,7 @@ Select a Service you want to view the logs for: 10) Minio 0) Back to Main Menu -Service: +Service: 3 ``` Select any of the service to view the logs e.g. `3`. Expect something similar to this @@ -323,7 +444,7 @@ Similarly, you can view the logs of other services. --- -### Backup Data +### Backup Data (Docker Compose) There would a time when you might want to backup your data from docker volumes to external storage like S3 or drives. @@ -355,7 +476,7 @@ Backup completed successfully. Backup files are stored in /....../plane-app/back --- -### Restore Data +### Restore Data (Docker Compose) When you want to restore the previously backed-up data, follow the instructions below. From 6b86fc0c2fb54e4f73dd32641cc5846b8c290498 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 18:50:11 +0530 Subject: [PATCH 12/16] chore: added migrator, redis, minio, db and mq service logs and also added redeployStack in script file --- deploy/selfhost/README.md | 1 + deploy/selfhost/install.sh | 5 +- deploy/selfhost/swarm.sh | 216 +++++++++++++++++++++---------------- 3 files changed, 128 insertions(+), 94 deletions(-) diff --git a/deploy/selfhost/README.md b/deploy/selfhost/README.md index 4fad496afa3..a46e440fdd7 100644 --- a/deploy/selfhost/README.md +++ b/deploy/selfhost/README.md @@ -388,6 +388,7 @@ Select a Service you want to view the logs for: 8) Redis 9) Postgres 10) Minio + 11) RabbitMQ 0) Back to Main Menu Service: 3 diff --git a/deploy/selfhost/install.sh b/deploy/selfhost/install.sh index 1c2208cab7c..01b28cd730a 100755 --- a/deploy/selfhost/install.sh +++ b/deploy/selfhost/install.sh @@ -457,11 +457,12 @@ function viewLogs(){ echo " 8) Redis" echo " 9) Postgres" echo " 10) Minio" + echo " 11) RabbitMQ" echo " 0) Back to Main Menu" echo read -p "Service: " DOCKER_SERVICE_NAME - until (( DOCKER_SERVICE_NAME >= 0 && DOCKER_SERVICE_NAME <= 10 )); do + until (( DOCKER_SERVICE_NAME >= 0 && DOCKER_SERVICE_NAME <= 11 )); do echo "Invalid selection. Please enter a number between 1 and 11." read -p "Service: " DOCKER_SERVICE_NAME done @@ -481,6 +482,7 @@ function viewLogs(){ 8) viewSpecificLogs "plane-redis";; 9) viewSpecificLogs "plane-db";; 10) viewSpecificLogs "plane-minio";; + 11) viewSpecificLogs "plane-mq";; 0) askForAction;; *) echo "INVALID SERVICE NAME SUPPLIED";; esac @@ -499,6 +501,7 @@ function viewLogs(){ redis) viewSpecificLogs "plane-redis";; postgres) viewSpecificLogs "plane-db";; minio) viewSpecificLogs "plane-minio";; + rabbitmq) viewSpecificLogs "plane-mq";; *) echo "INVALID SERVICE NAME SUPPLIED";; esac else diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index 748709146cf..f4c9832fa09 100755 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -293,7 +293,6 @@ function deployStack() { echo "" } -# Update other functions to use $stack_name function removeStack() { if [ -z "$stack_name" ]; then echo "Stack name not found" @@ -308,6 +307,65 @@ function removeStack() { echo "Services stopped successfully ✅" } +function viewStatus() { + echo "Checking status of ${stack_name} stack..." + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi + docker stack ps "$stack_name" +} + +function redeployStack() { + removeStack + deployStack +} + +function upgrade() { + + echo "Checking status of ${stack_name} stack..." + if [ -z "$stack_name" ]; then + echo "Stack name not found" + exit 1 + fi + + local latest_release=$(checkLatestRelease) + + echo "" + echo "Current release: $APP_RELEASE" + + if [ "$latest_release" == "$APP_RELEASE" ]; then + echo "" + echo "You are already using the latest release" + exit 0 + fi + + echo "Latest release: $latest_release" + echo "" + + # Check for confirmation to upgrade + echo "Do you want to upgrade to the latest release ($latest_release)?" + read -p "Continue? [y/N]: " confirm + + if [[ ! "$confirm" =~ ^[Yy]$ ]]; then + echo "Exiting..." + exit 0 + fi + + export APP_RELEASE=$latest_release + + # check if stack exists + echo "Upgrading ${stack_name} stack..." + + # check env file and take backup + if [ -f "$DOCKER_ENV_PATH" ]; then + cp "$DOCKER_ENV_PATH" "${DOCKER_ENV_PATH}.bak" + fi + + download + redeployStack +} + function viewSpecificLogs() { local service=$1 @@ -402,104 +460,76 @@ function viewSpecificLogs() { done } -function viewLogs() { - if [ -z "$stack_name" ]; then - echo "Stack name not found" - exit 1 - fi - echo "Select a service to view logs:" - echo " 1) API" - echo " 2) Worker" - echo " 3) Beat" - echo " 4) Web" - echo " 5) Proxy" - echo " 6) Space" - echo " 7) Back to Menu" - echo - read -p "Service [1]: " SERVICE - - until [[ -z "$SERVICE" || "$SERVICE" =~ ^[1-7]$ ]]; do - echo "$SERVICE: invalid selection." - read -p "Service [1]: " SERVICE - done +function viewLogs(){ - if [ -z "$SERVICE" ]; then - SERVICE=1 - fi + ARG_SERVICE_NAME=$2 + if [ -z "$ARG_SERVICE_NAME" ]; + then + echo + echo "Select a Service you want to view the logs for:" + echo " 1) Web" + echo " 2) Space" + echo " 3) API" + echo " 4) Worker" + echo " 5) Beat-Worker" + echo " 6) Migrator" + echo " 7) Proxy" + echo " 8) Redis" + echo " 9) Postgres" + echo " 10) Minio" + echo " 11) RabbitMQ" + echo " 0) Back to Main Menu" + echo + read -p "Service: " DOCKER_SERVICE_NAME - if [ "$SERVICE" == "1" ]; then - viewSpecificLogs "api" - elif [ "$SERVICE" == "2" ]; then - viewSpecificLogs "worker" - elif [ "$SERVICE" == "3" ]; then - viewSpecificLogs "beat" - elif [ "$SERVICE" == "4" ]; then - viewSpecificLogs "web" - elif [ "$SERVICE" == "5" ]; then - viewSpecificLogs "proxy" - elif [ "$SERVICE" == "6" ]; then - viewSpecificLogs "space" - elif [ "$SERVICE" == "7" ]; then - askForAction - fi -} + until (( DOCKER_SERVICE_NAME >= 0 && DOCKER_SERVICE_NAME <= 11 )); do + echo "Invalid selection. Please enter a number between 1 and 11." + read -p "Service: " DOCKER_SERVICE_NAME + done -function viewStatus() { - echo "Checking status of ${stack_name} stack..." - if [ -z "$stack_name" ]; then - echo "Stack name not found" - exit 1 + if [ -z "$DOCKER_SERVICE_NAME" ]; + then + echo "INVALID SERVICE NAME SUPPLIED" + else + case $DOCKER_SERVICE_NAME in + 1) viewSpecificLogs "web";; + 2) viewSpecificLogs "space";; + 3) viewSpecificLogs "api";; + 4) viewSpecificLogs "worker";; + 5) viewSpecificLogs "beat-worker";; + 6) viewSpecificLogs "migrator";; + 7) viewSpecificLogs "proxy";; + 8) viewSpecificLogs "plane-redis";; + 9) viewSpecificLogs "plane-db";; + 10) viewSpecificLogs "plane-minio";; + 11) viewSpecificLogs "plane-mq";; + 0) askForAction;; + *) echo "INVALID SERVICE NAME SUPPLIED";; + esac + fi + elif [ -n "$ARG_SERVICE_NAME" ]; + then + ARG_SERVICE_NAME=$(echo "$ARG_SERVICE_NAME" | tr '[:upper:]' '[:lower:]') + case $ARG_SERVICE_NAME in + web) viewSpecificLogs "web";; + space) viewSpecificLogs "space";; + api) viewSpecificLogs "api";; + worker) viewSpecificLogs "worker";; + beat-worker) viewSpecificLogs "beat-worker";; + migrator) viewSpecificLogs "migrator";; + proxy) viewSpecificLogs "proxy";; + redis) viewSpecificLogs "plane-redis";; + postgres) viewSpecificLogs "plane-db";; + minio) viewSpecificLogs "plane-minio";; + rabbitmq) viewSpecificLogs "plane-mq";; + *) echo "INVALID SERVICE NAME SUPPLIED";; + esac + else + echo "INVALID SERVICE NAME SUPPLIED" fi - docker stack ps "$stack_name" } -function upgrade() { - echo "Checking status of ${stack_name} stack..." - if [ -z "$stack_name" ]; then - echo "Stack name not found" - exit 1 - fi - - local latest_release=$(checkLatestRelease) - - echo "" - echo "Current release: $APP_RELEASE" - - if [ "$latest_release" == "$APP_RELEASE" ]; then - echo "" - echo "You are already using the latest release" - exit 0 - fi - - echo "Latest release: $latest_release" - echo "" - - # Check for confirmation to upgrade - echo "Do you want to upgrade to the latest release ($latest_release)?" - read -p "Continue? [y/N]: " confirm - - if [[ ! "$confirm" =~ ^[Yy]$ ]]; then - echo "Exiting..." - exit 0 - fi - - export APP_RELEASE=$latest_release - - # check if stack exists - echo "Upgrading ${stack_name} stack..." - - # check env file and take backup - if [ -f "$DOCKER_ENV_PATH" ]; then - cp "$DOCKER_ENV_PATH" "${DOCKER_ENV_PATH}.bak" - fi - - download - - - removeStack - deployStack -} function askForAction() { # Rest of askForAction remains the same but use $stack_name instead of $STACK_NAME @@ -534,7 +564,7 @@ function askForAction() { elif [ "$ACTION" == "3" ] || [ "$DEFAULT_ACTION" == "status" ]; then viewStatus elif [ "$ACTION" == "4" ] || [ "$DEFAULT_ACTION" == "logs" ]; then - viewLogs + viewLogs "$@" elif [ "$ACTION" == "5" ] || [ "$DEFAULT_ACTION" == "upgrade" ]; then upgrade elif [ "$ACTION" == "6" ] || [ "$DEFAULT_ACTION" == "exit" ]; then From 80c6f66fc1689a48fec5914d73d866f706cb3029 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Wed, 15 Jan 2025 19:14:13 +0530 Subject: [PATCH 13/16] add sleep in redeployStack service --- deploy/selfhost/docker-compose.yml | 1 - deploy/selfhost/swarm.sh | 15 ++++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index b0d0957f31d..bc31536de66 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -192,7 +192,6 @@ services: plane-mq: image: rabbitmq:3.13.6-management-alpine - restart: always deploy: replicas: 1 restart_policy: diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index f4c9832fa09..1840137764c 100755 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -304,6 +304,7 @@ function removeStack() { while docker stack ls | grep -q "$stack_name"; do sleep 1 done + sleep 20 echo "Services stopped successfully ✅" } @@ -318,6 +319,7 @@ function viewStatus() { function redeployStack() { removeStack + echo "ReDeploying ${stack_name} stack..." deployStack } @@ -541,9 +543,10 @@ function askForAction() { echo " 1) Deploy Stack" echo " 2) Remove Stack" echo " 3) View Stack Status" - echo " 4) View Logs" + echo " 4) Redeploy Stack" echo " 5) Upgrade" - echo " 6) Exit" + echo " 6) View Logs" + echo " 7) Exit" echo read -p "Action [3]: " ACTION until [[ -z "$ACTION" || "$ACTION" =~ ^[1-6]$ ]]; do @@ -563,11 +566,13 @@ function askForAction() { removeStack elif [ "$ACTION" == "3" ] || [ "$DEFAULT_ACTION" == "status" ]; then viewStatus - elif [ "$ACTION" == "4" ] || [ "$DEFAULT_ACTION" == "logs" ]; then - viewLogs "$@" + elif [ "$ACTION" == "4" ] || [ "$DEFAULT_ACTION" == "redeploy" ]; then + redeployStack elif [ "$ACTION" == "5" ] || [ "$DEFAULT_ACTION" == "upgrade" ]; then upgrade - elif [ "$ACTION" == "6" ] || [ "$DEFAULT_ACTION" == "exit" ]; then + elif [ "$ACTION" == "6" ] || [ "$DEFAULT_ACTION" == "logs" ]; then + viewLogs "$@" + elif [ "$ACTION" == "7" ] || [ "$DEFAULT_ACTION" == "exit" ]; then exit 0 else echo "INVALID ACTION SUPPLIED" From 67baf559c63312478d0fabf5c310d3beeeb51205 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Thu, 16 Jan 2025 11:14:33 +0530 Subject: [PATCH 14/16] fixed typo in swarm and install script --- deploy/selfhost/install.sh | 2 +- deploy/selfhost/swarm.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deploy/selfhost/install.sh b/deploy/selfhost/install.sh index 01b28cd730a..1ee0d6f352f 100755 --- a/deploy/selfhost/install.sh +++ b/deploy/selfhost/install.sh @@ -463,7 +463,7 @@ function viewLogs(){ read -p "Service: " DOCKER_SERVICE_NAME until (( DOCKER_SERVICE_NAME >= 0 && DOCKER_SERVICE_NAME <= 11 )); do - echo "Invalid selection. Please enter a number between 1 and 11." + echo "Invalid selection. Please enter a number between 0 and 11." read -p "Service: " DOCKER_SERVICE_NAME done diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index 1840137764c..4e774582e98 100755 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -485,7 +485,7 @@ function viewLogs(){ read -p "Service: " DOCKER_SERVICE_NAME until (( DOCKER_SERVICE_NAME >= 0 && DOCKER_SERVICE_NAME <= 11 )); do - echo "Invalid selection. Please enter a number between 1 and 11." + echo "Invalid selection. Please enter a number between 0 and 11." read -p "Service: " DOCKER_SERVICE_NAME done From 0b329835dfce7fe2666d458342f46e308ed9c692 Mon Sep 17 00:00:00 2001 From: Manish Gupta <59428681+mguptahub@users.noreply.github.com> Date: Thu, 16 Jan 2025 11:51:36 +0530 Subject: [PATCH 15/16] updated coderabbit suggestions --- deploy/selfhost/README.md | 6 +++--- deploy/selfhost/swarm.sh | 9 +++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/deploy/selfhost/README.md b/deploy/selfhost/README.md index a46e440fdd7..e5a8089e646 100644 --- a/deploy/selfhost/README.md +++ b/deploy/selfhost/README.md @@ -106,12 +106,12 @@ Action [2]: 1 For the 1st time setup, type "1" as action input. -This will create a create a folder `plane-app` and will download 2 files inside that +This will create a folder `plane-app` and will download 2 files inside that - `docker-compose.yaml` - `plane.env` -Again the `options [1-8]` will be popped up and this time hit `8` to exit. +Again the `options [1-8]` will be popped up, and this time hit `8` to exit. #### Docker Swarm @@ -135,7 +135,7 @@ This will create a create a folder `plane-app` and will download 2 files inside - `docker-compose.yaml` - `plane.env` -Again the `options [1-7]` will be popped up and this time hit `7` to exit. +Again the `options [1-7]` will be popped up, and this time hit `7` to exit. --- diff --git a/deploy/selfhost/swarm.sh b/deploy/selfhost/swarm.sh index 4e774582e98..49fe775766b 100755 --- a/deploy/selfhost/swarm.sh +++ b/deploy/selfhost/swarm.sh @@ -148,7 +148,7 @@ function updateEnvFile() { } function download() { - cd $SCRIPT_DIR + cd $SCRIPT_DIR || exit 1 TS=$(date +%s) if [ -f "$PLANE_INSTALL_DIR/docker-compose.yml" ] then @@ -230,7 +230,12 @@ function deployStack() { echo "Starting ${stack_name} stack..." # Pull envs - set -o allexport; source $DOCKER_ENV_PATH; set +o allexport; + if [ -f "$DOCKER_ENV_PATH" ]; then + set -o allexport; source $DOCKER_ENV_PATH; set +o allexport; + else + echo "Environment file not found: $DOCKER_ENV_PATH" + exit 1 + fi # Deploy the stack docker stack deploy -c $DOCKER_FILE_PATH $stack_name From 62d2acee70b6d8d20c9d3a2e50f4e7452ef2cf67 Mon Sep 17 00:00:00 2001 From: akshat5302 Date: Thu, 16 Jan 2025 12:11:54 +0530 Subject: [PATCH 16/16] added Replica Envs for services --- deploy/selfhost/docker-compose.yml | 9 +++++++++ deploy/selfhost/variables.env | 3 +++ 2 files changed, 12 insertions(+) diff --git a/deploy/selfhost/docker-compose.yml b/deploy/selfhost/docker-compose.yml index bc31536de66..1c540c7f57f 100644 --- a/deploy/selfhost/docker-compose.yml +++ b/deploy/selfhost/docker-compose.yml @@ -55,6 +55,15 @@ x-app-env: &app-env APP_BASE_URL: ${APP_BASE_URL} AMQP_URL: ${AMQP_URL:-amqp://plane:plane@plane-mq:5672/plane} + #Replicas Environment Variables + WEB_REPLICAS: ${WEB_REPLICAS:-1} + SPACE_REPLICAS: ${SPACE_REPLICAS:-1} + ADMIN_REPLICAS: ${ADMIN_REPLICAS:-1} + API_REPLICAS: ${API_REPLICAS:-1} + WORKER_REPLICAS: ${WORKER_REPLICAS:-1} + BEAT_WORKER_REPLICAS: ${BEAT_WORKER_REPLICAS:-1} + LIVE_REPLICAS: ${LIVE_REPLICAS:-1} + services: web: diff --git a/deploy/selfhost/variables.env b/deploy/selfhost/variables.env index 78914c3afd7..b10cf11d0de 100644 --- a/deploy/selfhost/variables.env +++ b/deploy/selfhost/variables.env @@ -5,6 +5,9 @@ WEB_REPLICAS=1 SPACE_REPLICAS=1 ADMIN_REPLICAS=1 API_REPLICAS=1 +WORKER_REPLICAS=1 +BEAT_WORKER_REPLICAS=1 +LIVE_REPLICAS=1 NGINX_PORT=80 WEB_URL=http://${APP_DOMAIN}