start.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/sh
  2. # Default values
  3. CONTAINER_NAME="vs-code-def-container"
  4. CONTAINER_IMAGE="vscode"
  5. PORT="3000"
  6. SHARED_NETWORK="main_netwok"
  7. TOKEN="dt"
  8. LOG_DIR="/rdata/logs"
  9. VOLUMES=""
  10. # Parse command-line arguments
  11. while [ $# -gt 0 ]; do
  12. case "$1" in
  13. --name) CONTAINER_NAME="$2"; shift; shift ;;
  14. --image) CONTAINER_IMAGE="$2"; shift; shift ;;
  15. --port) PORT="$2"; shift; shift ;;
  16. --network) SHARED_NETWORK="$2"; shift; shift ;;
  17. --token) TOKEN="$2"; shift; shift ;;
  18. --log-dir) LOG_DIR="$2"; shift; shift ;;
  19. -v) VOLUMES="$VOLUMES -v \"$2\""; shift; shift ;;
  20. *) echo "Unknown parameter passed: $1"; exit 1 ;;
  21. esac
  22. done
  23. # Remove existing container if it exists
  24. docker ps -a --filter "name=$CONTAINER_NAME" --format "{{.ID}}" | xargs -r docker rm -f
  25. # Check if network exists, create if not
  26. if ! docker network inspect "$SHARED_NETWORK" > /dev/null 2>&1; then
  27. echo "Creating network: $SHARED_NETWORK"
  28. docker network create "$SHARED_NETWORK"
  29. fi
  30. # Construct the docker run command
  31. docker_run_command="docker run -d \
  32. -p \"$PORT:3000\" \
  33. --name=\"$CONTAINER_NAME\" \
  34. --network \"$SHARED_NETWORK\" \
  35. -e CONNECTION_TOKEN="$TOKEN" \
  36. -v \"$LOG_DIR/containers/$CONTAINER_NAME:/vs_logs\" \
  37. $VOLUMES \"$CONTAINER_IMAGE\""
  38. # if [ -n "$TOKEN" ]; then
  39. # docker_run_command="$docker_run_command $CONTAINER_IMAGE --connection-token $TOKEN"
  40. # else
  41. # docker_run_command="$docker_run_command $CONTAINER_IMAGE"
  42. # fi
  43. # Print the command
  44. echo "Running command: $docker_run_command"
  45. # Execute the docker run command
  46. eval "$docker_run_command"
  47. # Redirect container logs to a file
  48. mkdir -p "$LOG_DIR/containers/$CONTAINER_NAME"
  49. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "alias gg=\"tail -n 1000 -f /app/main-logs/log.log | ccze -A\"" >> ~/.profile'
  50. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "alias gg=\"tail -n 1000 -f /app/main-logs/log.log | ccze -A\"" >> ~/.shrc'
  51. # docker exec -it "$CONTAINER_NAME" sh -c 'source ~/.profile'
  52. # docker exec -it "$CONTAINER_NAME" sh -c 'source ~/.shrc'
  53. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "#!/bin/sh\ntail -n 1000 -f /app/main-logs/log.log | ccze -A" > /usr/local/bin/custom_logs_cmd'
  54. # docker exec -it "$CONTAINER_NAME" chmod +x /usr/local/bin/gg
  55. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "export PATH=\$PATH:/usr/local/bin" >> /etc/profile'
  56. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "export PATH=\$PATH:/usr/local/bin" >> /root/.profile'
  57. # docker exec -it "$CONTAINER_NAME" sh -c 'echo "[ -f ~/.profile ] && source ~/.profile" >> ~/.bashrc'
  58. docker logs -f "$CONTAINER_NAME" | tee -a "$LOG_DIR/containers/$CONTAINER_NAME/log.log" 2>&1 &