mirror of https://github.com/jetkvm/kvm.git
				
				
				
			Add devcontainer support (#8)
This commit is contained in:
		
							parent
							
								
									6e2177e427
								
							
						
					
					
						commit
						ed93400758
					
				| 
						 | 
					@ -0,0 +1,10 @@
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						"name": "JetKVM",
 | 
				
			||||||
 | 
						"image": "mcr.microsoft.com/devcontainers/go:1-1.23-bookworm",
 | 
				
			||||||
 | 
						"features": {
 | 
				
			||||||
 | 
							"ghcr.io/devcontainers/features/node:1": {
 | 
				
			||||||
 | 
								// Should match what is defined in ui/package.json
 | 
				
			||||||
 | 
								"version": "21.1.0"
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										2
									
								
								Makefile
								
								
								
								
							
							
						
						
									
										2
									
								
								Makefile
								
								
								
								
							| 
						 | 
					@ -9,7 +9,7 @@ build_dev: hash_resource
 | 
				
			||||||
	GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=$(VERSION_DEV)" -o bin/jetkvm_app cmd/main.go
 | 
						GOOS=linux GOARCH=arm GOARM=7 go build -ldflags="-s -w -X kvm.builtAppVersion=$(VERSION_DEV)" -o bin/jetkvm_app cmd/main.go
 | 
				
			||||||
 | 
					
 | 
				
			||||||
frontend:
 | 
					frontend:
 | 
				
			||||||
	cd ui && npm run build:device
 | 
						cd ui && npm ci && npm run build:device
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dev_release: build_dev
 | 
					dev_release: build_dev
 | 
				
			||||||
	@echo "Uploading release..."
 | 
						@echo "Uploading release..."
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,35 +3,28 @@ set -e
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Function to display help message
 | 
					# Function to display help message
 | 
				
			||||||
show_help() {
 | 
					show_help() {
 | 
				
			||||||
    echo "Usage: $0 [options] -h <host_ip> -r <remote_ip>"
 | 
					    echo "Usage: $0 [options] -r <remote_ip>"
 | 
				
			||||||
    echo
 | 
					    echo
 | 
				
			||||||
    echo "Required:"
 | 
					    echo "Required:"
 | 
				
			||||||
    echo "  -h, --host <host_ip>      Local host IP address"
 | 
					 | 
				
			||||||
    echo "  -r, --remote <remote_ip>   Remote host IP address"
 | 
					    echo "  -r, --remote <remote_ip>   Remote host IP address"
 | 
				
			||||||
    echo
 | 
					    echo
 | 
				
			||||||
    echo "Optional:"
 | 
					    echo "Optional:"
 | 
				
			||||||
    echo "  -u, --user <remote_user>   Remote username (default: root)"
 | 
					    echo "  -u, --user <remote_user>   Remote username (default: root)"
 | 
				
			||||||
    echo "  -p, --port <port>          Python server port (default: 8000)"
 | 
					 | 
				
			||||||
    echo "      --help                 Display this help message"
 | 
					    echo "      --help                 Display this help message"
 | 
				
			||||||
    echo
 | 
					    echo
 | 
				
			||||||
    echo "Example:"
 | 
					    echo "Example:"
 | 
				
			||||||
    echo "  $0 -h 192.168.0.13 -r 192.168.0.17"
 | 
					    echo "  $0 -r 192.168.0.17"
 | 
				
			||||||
    echo "  $0 -h 192.168.0.13 -r 192.168.0.17 -u admin -p 8080"
 | 
					    echo "  $0 -r 192.168.0.17 -u admin"
 | 
				
			||||||
    exit 0
 | 
					    exit 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Default values
 | 
					# Default values
 | 
				
			||||||
PYTHON_PORT=8000
 | 
					 | 
				
			||||||
REMOTE_USER="root"
 | 
					REMOTE_USER="root"
 | 
				
			||||||
REMOTE_PATH="/userdata/jetkvm/bin"
 | 
					REMOTE_PATH="/userdata/jetkvm/bin"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Parse command line arguments
 | 
					# Parse command line arguments
 | 
				
			||||||
while [[ $# -gt 0 ]]; do
 | 
					while [[ $# -gt 0 ]]; do
 | 
				
			||||||
    case $1 in
 | 
					    case $1 in
 | 
				
			||||||
        -h|--host)
 | 
					 | 
				
			||||||
            HOST_IP="$2"
 | 
					 | 
				
			||||||
            shift 2
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        -r|--remote)
 | 
					        -r|--remote)
 | 
				
			||||||
            REMOTE_HOST="$2"
 | 
					            REMOTE_HOST="$2"
 | 
				
			||||||
            shift 2
 | 
					            shift 2
 | 
				
			||||||
| 
						 | 
					@ -40,10 +33,6 @@ while [[ $# -gt 0 ]]; do
 | 
				
			||||||
            REMOTE_USER="$2"
 | 
					            REMOTE_USER="$2"
 | 
				
			||||||
            shift 2
 | 
					            shift 2
 | 
				
			||||||
            ;;
 | 
					            ;;
 | 
				
			||||||
        -p|--port)
 | 
					 | 
				
			||||||
            PYTHON_PORT="$2"
 | 
					 | 
				
			||||||
            shift 2
 | 
					 | 
				
			||||||
            ;;
 | 
					 | 
				
			||||||
        --help)
 | 
					        --help)
 | 
				
			||||||
            show_help
 | 
					            show_help
 | 
				
			||||||
            exit 0
 | 
					            exit 0
 | 
				
			||||||
| 
						 | 
					@ -57,8 +46,8 @@ while [[ $# -gt 0 ]]; do
 | 
				
			||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Verify required parameters
 | 
					# Verify required parameters
 | 
				
			||||||
if [ -z "$HOST_IP" ] || [ -z "$REMOTE_HOST" ]; then
 | 
					if [ -z "$REMOTE_HOST" ]; then
 | 
				
			||||||
    echo "Error: Host IP and Remote IP are required parameters"
 | 
					    echo "Error: Remote IP is a required parameter"
 | 
				
			||||||
    show_help
 | 
					    show_help
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -69,12 +58,8 @@ make build_dev
 | 
				
			||||||
# Change directory to the binary output directory
 | 
					# Change directory to the binary output directory
 | 
				
			||||||
cd bin
 | 
					cd bin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Start a Python HTTP server in the background to serve files
 | 
					# Copy the binary to the remote host
 | 
				
			||||||
python3 -m http.server "$PYTHON_PORT" &
 | 
					cat jetkvm_app | ssh "${REMOTE_USER}@${REMOTE_HOST}" "cat > $REMOTE_PATH/jetkvm_app_debug"
 | 
				
			||||||
PYTHON_SERVER_PID=$!
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Ensure that the Python server is terminated if the script exits unexpectedly
 | 
					 | 
				
			||||||
trap "echo 'Terminating Python server...'; kill $PYTHON_SERVER_PID" EXIT
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Deploy and run the application on the remote host
 | 
					# Deploy and run the application on the remote host
 | 
				
			||||||
ssh "${REMOTE_USER}@${REMOTE_HOST}" ash <<EOF
 | 
					ssh "${REMOTE_USER}@${REMOTE_HOST}" ash <<EOF
 | 
				
			||||||
| 
						 | 
					@ -90,23 +75,12 @@ killall jetkvm_app_debug || true
 | 
				
			||||||
# Navigate to the directory where the binary will be stored
 | 
					# Navigate to the directory where the binary will be stored
 | 
				
			||||||
cd "$REMOTE_PATH"
 | 
					cd "$REMOTE_PATH"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Remove any old binary
 | 
					 | 
				
			||||||
rm -f jetkvm_app
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Download the new binary from the host
 | 
					 | 
				
			||||||
wget ${HOST_IP}:${PYTHON_PORT}/jetkvm_app
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Make the new binary executable
 | 
					# Make the new binary executable
 | 
				
			||||||
chmod +x jetkvm_app
 | 
					chmod +x jetkvm_app_debug
 | 
				
			||||||
 | 
					 | 
				
			||||||
# Rename the binary to jetkvm_app_debug
 | 
					 | 
				
			||||||
mv jetkvm_app jetkvm_app_debug
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Run the application in the background
 | 
					# Run the application in the background
 | 
				
			||||||
./jetkvm_app_debug
 | 
					./jetkvm_app_debug
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EOF
 | 
					EOF
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Once the SSH session finishes, shut down the Python server
 | 
					 | 
				
			||||||
kill "$PYTHON_SERVER_PID"
 | 
					 | 
				
			||||||
echo "Deployment complete."
 | 
					echo "Deployment complete."
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue