1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/bin/sh
- # Default values
- CONTAINER_NAME="vs-code-def-container"
- CONTAINER_IMAGE="vscode"
- PORT="3000"
- SHARED_NETWORK="main_netwok"
- TOKEN="dt"
- LOG_DIR="/rdata/logs"
- VOLUMES=""
- # Parse command-line arguments
- while [ $# -gt 0 ]; do
- case "$1" in
- --name) CONTAINER_NAME="$2"; shift; shift ;;
- --image) CONTAINER_IMAGE="$2"; shift; shift ;;
- --port) PORT="$2"; shift; shift ;;
- --network) SHARED_NETWORK="$2"; shift; shift ;;
- --token) TOKEN="$2"; shift; shift ;;
- --log-dir) LOG_DIR="$2"; shift; shift ;;
- -v) VOLUMES="$VOLUMES -v \"$2\""; shift; shift ;;
- *) echo "Unknown parameter passed: $1"; exit 1 ;;
- esac
- done
- # Remove existing container if it exists
- docker ps -a --filter "name=$CONTAINER_NAME" --format "{{.ID}}" | xargs -r docker rm -f
- # Check if network exists, create if not
- if ! docker network inspect "$SHARED_NETWORK" > /dev/null 2>&1; then
- echo "Creating network: $SHARED_NETWORK"
- docker network create "$SHARED_NETWORK"
- fi
- # Construct the docker run command
- docker_run_command="docker run -d \
- -p \"$PORT:3000\" \
- --name=\"$CONTAINER_NAME\" \
- --network \"$SHARED_NETWORK\" \
- -e CONNECTION_TOKEN="$TOKEN" \
- -v \"$LOG_DIR/containers/$CONTAINER_NAME:/vs_logs\" \
- $VOLUMES \"$CONTAINER_IMAGE\""
- # if [ -n "$TOKEN" ]; then
- # docker_run_command="$docker_run_command $CONTAINER_IMAGE --connection-token $TOKEN"
- # else
- # docker_run_command="$docker_run_command $CONTAINER_IMAGE"
- # fi
- # Print the command
- echo "Running command: $docker_run_command"
- # Execute the docker run command
- eval "$docker_run_command"
- # Redirect container logs to a file
- mkdir -p "$LOG_DIR/containers/$CONTAINER_NAME"
- # docker exec -it "$CONTAINER_NAME" sh -c 'echo "alias gg=\"tail -n 1000 -f /app/main-logs/log.log | ccze -A\"" >> ~/.profile'
- # docker exec -it "$CONTAINER_NAME" sh -c 'echo "alias gg=\"tail -n 1000 -f /app/main-logs/log.log | ccze -A\"" >> ~/.shrc'
- # docker exec -it "$CONTAINER_NAME" sh -c 'source ~/.profile'
- # docker exec -it "$CONTAINER_NAME" sh -c 'source ~/.shrc'
- # 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'
- # docker exec -it "$CONTAINER_NAME" chmod +x /usr/local/bin/gg
- # docker exec -it "$CONTAINER_NAME" sh -c 'echo "export PATH=\$PATH:/usr/local/bin" >> /etc/profile'
- # docker exec -it "$CONTAINER_NAME" sh -c 'echo "export PATH=\$PATH:/usr/local/bin" >> /root/.profile'
- # docker exec -it "$CONTAINER_NAME" sh -c 'echo "[ -f ~/.profile ] && source ~/.profile" >> ~/.bashrc'
- docker logs -f "$CONTAINER_NAME" | tee -a "$LOG_DIR/containers/$CONTAINER_NAME/log.log" 2>&1 &
|