Skip to content

Commit

Permalink
Dev via Gitpod Flex
Browse files Browse the repository at this point in the history
  • Loading branch information
mustard-mh committed Jan 10, 2025
1 parent 1cdbdf7 commit ef33efa
Showing 4 changed files with 73 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion components/ide/jetbrains/toolbox/README.md
Original file line number Diff line number Diff line change
@@ -2,7 +2,14 @@

Provides a way to connect to Gitpod Classic workspaces within the JetBrains Toolbox App.

## How to Develop
## How to Develop with Gitpod Flex

- Start an environment on [Gitpod Flex](https://app.gitpod.io) with current repository
- Connect to the environment via **JetBrains Gateway** (because we want to restart Toolbox) SSH feature (user: gitpod_devcontainer)
- [optional] Copy ./flex-sync.sh locally and chmod +x, the script is written for macOS, please adjust it if you're using other OS
- Exec `./flex-sync.sh <env_host>`

## How to Develop locally

### Requires
- Java 21
18 changes: 18 additions & 0 deletions components/ide/jetbrains/toolbox/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -146,6 +146,24 @@ val restartToolbox by tasks.creating {
}
}

val buildPluginFlex by tasks.creating(Sync::class.java) {
group = "01.Gitpod"

dependsOn(tasks.named("shadowJar"))
from(tasks.named("shadowJar").get().outputs.files)

val targetDir = Path.of("./build/flex") / pluginId

from("src/main/resources") {
include("extension.json")
include("dependencies.json")
include("icon.svg")
include("icon-gray.svg")
}

into(targetDir)
}

val copyPlugin by tasks.creating(Sync::class.java) {
group = "01.Gitpod"

45 changes: 45 additions & 0 deletions components/ide/jetbrains/toolbox/flex-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
# shellcheck disable=all
#
# Sync the local Toolbox plugins folder from the build results of Gitpod Flex (`build/flex/*`) automatically
# so that you could build with a remote environment

if [ $# -eq 0 ]; then
echo "Usage: $0 <remote_host>"
echo "Example: $0 01944f84-5bc8-7d9b-916a-4fc95e25de12.gitpod.environment"
exit 1
fi

REMOTE_HOST="$1"
LOCAL_DIR="$HOME/Library/Caches/JetBrains/Toolbox/plugins"
REMOTE_DIR="/workspace/gitpod/components/ide/jetbrains/toolbox/build/flex"
DEVCONTAINER_HOST="gitpod_devcontainer@$REMOTE_HOST"

echo "Preparing..."

ssh $DEVCONTAINER_HOST "apt-get update && apt-get install -y rsync inotify-tools" > /dev/null

function sync_and_restart() {
rsync -avz --delete "$DEVCONTAINER_HOST:$REMOTE_DIR/" "$LOCAL_DIR/"
pkill -f 'JetBrains Toolbox' || true
echo debugClean > $HOME/Library/Logs/JetBrains/Toolbox/toolbox.log
code $HOME/Library/Logs/JetBrains/Toolbox/toolbox.log
# In case Toolbox refuses to start
echo "Restarting Toolbox in 3 seconds"
sleep 3
open /Applications/JetBrains\ Toolbox.app
}

echo "Initing..."

sync_and_restart

echo "Watching for changes in $DEVCONTAINER_HOST:$REMOTE_DIR"

ssh $DEVCONTAINER_HOST "inotifywait -m -r -e modify,create,delete,move $REMOTE_DIR" | \
while read path action file; do
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Change detected: $action $file"
# Make sure remote is build
sleep 3
sync_and_restart
done

0 comments on commit ef33efa

Please sign in to comment.