Skip to content

Commit 1dbcabf

Browse files
committed
Add VNC support and Android Studio integration to devcontainer setup
1 parent bc26514 commit 1dbcabf

File tree

3 files changed

+179
-42
lines changed

3 files changed

+179
-42
lines changed

.devcontainer/Dockerfile

Lines changed: 121 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,124 @@ RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
6464
# && sudo apt-get install -y portaudio19-dev \
6565
# && uv tool install mysc[web]
6666

67-
# Install ws-scrcpy
68-
SHELL ["/bin/bash", "-lic"]
69-
RUN fnm install --lts \
70-
&& cd $HOME && git clone https://github.com/axonasif/ws-scrcpy && cd ws-scrcpy \
71-
&& uv run npm install && npm run dist:prod
72-
# && uv run bun install && uv run bun run dist:prod
67+
# # Install ws-scrcpy
68+
# SHELL ["/bin/bash", "-lic"]
69+
# RUN fnm install --lts \
70+
# && cd $HOME && git clone https://github.com/axonasif/ws-scrcpy && cd ws-scrcpy \
71+
# && uv run npm install && uv run npm run dist:prod
72+
# # && uv run bun install && uv run bun run dist:prod
73+
74+
75+
76+
77+
# Add VNC support from https://github.com/gitpod-samples/vnc
78+
USER root
79+
80+
RUN cd /tmp \
81+
&& curl -LO https://github.com/kasmtech/KasmVNC/releases/download/v1.4.0/kasmvncserver_noble_1.4.0_amd64.deb \
82+
&& apt-get update && apt-get install -yq ./kasm*.deb && rm kasm*.deb \
83+
&& apt-get install -yq --no-install-recommends dbus dbus-x11 gnome-keyring xfce4 xfce4-terminal xdg-utils x11-xserver-utils
84+
85+
ENV DISPLAY=:1
86+
ARG USERNAME=vscode
87+
ARG HOMEPATH=/home/$USERNAME
88+
89+
RUN adduser $USERNAME ssl-cert
90+
91+
USER $USERNAME
92+
SHELL ["/bin/bash", "-ic"]
93+
94+
RUN <<SCRIPT
95+
set -eu
96+
97+
printf '%s\n' 123456 123456 | vncpasswd -u $USER -ow
98+
cat > $HOME/.xinitrc << 'EOF'
99+
#!/bin/bash
100+
101+
: "${DISPLAY:="$DISPLAY"}"
102+
export DISPLAY
103+
104+
exec dbus-launch --exit-with-session xfce4-session
105+
EOF
106+
chmod +x $HOME/.xinitrc
107+
108+
mkdir -p $HOME/.vnc
109+
ln -sf $HOME/.xinitrc $HOME/.vnc/xstartup
110+
touch $HOME/.vnc/.de-was-selected
111+
112+
cat > $HOME/.vnc/kasmvnc.yaml << 'EOF'
113+
logging:
114+
log_writer_name: all
115+
log_dest: logfile
116+
level: 100
117+
118+
network:
119+
protocol: http
120+
interface: 0.0.0.0
121+
websocket_port: 5901
122+
use_ipv4: true
123+
use_ipv6: false
124+
udp:
125+
public_ip: auto
126+
port: auto
127+
payload_size: auto
128+
stun_server: auto
129+
ssl:
130+
require_ssl: false
131+
EOF
132+
133+
sudo tee -a /usr/bin/vnc <<'BASH'
134+
#!/bin/bash
135+
set -eux
136+
sudo service dbus start
137+
cd $HOME
138+
vncserver -disableBasicAuth -alwaysshared
139+
BASH
140+
sudo chmod +x /usr/bin/vnc
141+
142+
SCRIPT
143+
144+
145+
# Optional: Install Browser (Chrome)
146+
# chrome and basic render font
147+
# misc deps for electron and puppeteer to run
148+
USER root
149+
RUN cd /tmp && glink="https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb" \
150+
&& wget -q "$glink" \
151+
&& apt-get install -yq --no-install-recommends libasound2-dev libgtk-3-dev libnss3-dev \
152+
fonts-noto fonts-noto-cjk ./"${glink##*/}" \
153+
\
154+
# OLD: && ln -srf /usr/bin/chromium /usr/bin/google-chrome
155+
# OLD: To make ungoogled_chromium discoverable by tools like flutter
156+
&& ln -srf /usr/bin/google-chrome /usr/bin/chromium \
157+
\
158+
# Extra chrome tweaks
159+
## Disables welcome screen
160+
&& t="$HOMEPATH/.config/google-chrome/First Run" && sudo -u $USERNAME mkdir -p "${t%/*}" && sudo -u $USERNAME touch "$t" \
161+
## Disables default browser prompt
162+
&& t="/etc/opt/chrome/policies/managed/managed_policies.json" && mkdir -p "${t%/*}" && printf '{ "%s": %s }\n' DefaultBrowserSettingEnabled false > "$t"
163+
164+
# For Qt WebEngine on docker
165+
ENV QTWEBENGINE_DISABLE_SANDBOX 1
166+
167+
168+
# Install android studio
169+
170+
USER $USERNAME
171+
ENV PATH="$HOMEPATH/android-studio/bin:$PATH"
172+
SHELL ["/bin/bash", "-ic"]
173+
174+
RUN <<SCRIPT
175+
set -eu
176+
177+
cd $HOME
178+
curl -L https://redirector.gvt1.com/edgedl/android/studio/ide-zips/2025.2.1.7/android-studio-2025.2.1.7-linux.tar.gz -o /tmp/android-studio.tar.gz
179+
tar -xzf /tmp/android-studio.tar.gz
180+
rm /tmp/android-studio.tar.gz
181+
cd android-studio/bin
182+
vnc
183+
./studio.sh
184+
185+
# Create desktop entry
186+
# cat > $HOME/.local/share/applications/android-studio.desktop
187+
SCRIPT

.devcontainer/devcontainer.json

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,65 @@
33
//
44
// See https://aka.ms/devcontainer.json for more information.
55
{
6-
"name": "Gitpod",
6+
"name": "Ona Android Dev with Android Studio",
77
"remoteUser": "vscode",
8-
// Use "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
9-
// instead of the build to use a pre-built image.
10-
"build": {
8+
// Use "image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
9+
// instead of the build to use a pre-built image.
10+
"build": {
1111
"context": ".",
1212
"dockerfile": "Dockerfile"
1313
},
14-
// Features add additional features to your environment. See https://containers.dev/features
15-
// Beware: features are not supported on all platforms and may have unintended side-effects.
16-
// "features": {
17-
// "ghcr.io/devcontainers/features/docker-in-docker:2": {}
18-
// },
19-
"initializeCommand": "modprobe kvm && modprobe kvm_intel && chmod 777 /dev/kvm",
14+
// Features add additional features to your environment. See https://containers.dev/features
15+
// Beware: features are not supported on all platforms and may have unintended side-effects.
16+
"features": {
17+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
18+
},
19+
"initializeCommand": "modprobe kvm && modprobe kvm_intel && chmod 777 /dev/kvm || true",
20+
"postStartCommand": {
21+
"vnc": "vnc"
22+
},
2023
"privileged": true,
2124
"runArgs": [
25+
"--shm-size=2gb", // for VNC/GUI apps
2226
"--cap-add=ALL",
2327
"--device=/dev/fuse",
2428
"--device=/dev/kvm",
25-
"--device=/dev/snd",
29+
"--device=/dev/snd",
2630
"--device=/dev/video0",
2731
"--security-opt=apparmor:unconfined"
28-
],
29-
"mounts": [
32+
],
33+
"mounts": [
34+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
3035
"source=/boot,target=/boot,type=bind",
3136
"source=/lib/modules,target=/lib/modules,type=bind"
32-
],
33-
37+
],
38+
"forwardPorts": [
39+
5901
40+
],
3441
"portsAttributes": {
35-
"8000": {
36-
"label": "Emulator Control Web",
37-
"onAutoForward": "openPreview"
42+
"5901": {
43+
"label": "KasmVNC",
44+
"onAutoForward": "openPreview"
45+
},
46+
"8000": {
47+
"label": "Emulator Control Web",
48+
"onAutoForward": "openPreview"
49+
}
50+
},
51+
"customizations": {
52+
"vscode": {
53+
"extensions": [
54+
"esafirm.kotlin-formatter",
55+
"fwcd.kotlin",
56+
"vscjava.vscode-gradle",
57+
"vscjava.vscode-java-dependency",
58+
"vscjava.vscode-java-test",
59+
"vscjava.vscode-maven",
60+
"vscjava.vscode-java-debug",
61+
"redhat.java",
62+
"VisualStudioExptTeam.vscodeintellicode",
63+
"nisargjhaveri.android-debug"
64+
]
65+
}
3866
}
39-
},
40-
"customizations": {
41-
"vscode": {
42-
"extensions": [
43-
"esafirm.kotlin-formatter",
44-
"fwcd.kotlin",
45-
"vscjava.vscode-gradle",
46-
"vscjava.vscode-java-dependency",
47-
"vscjava.vscode-java-test",
48-
"vscjava.vscode-maven",
49-
"vscjava.vscode-java-debug",
50-
"redhat.java",
51-
"VisualStudioExptTeam.vscodeintellicode",
52-
"nisargjhaveri.android-debug"
53-
]
54-
}
55-
}
56-
}
67+
}

.gitpod/automations.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ services:
3232
until adb shell getprop sys.boot_completed 2>/dev/null | grep -q 1; do sleep 1; done
3333
cd ~/ws-scrcpy/dist
3434
node ./index.js
35+
triggeredBy:
36+
- manual
37+
38+
KasmVNCAndroidStudio:
39+
name: Android Studio VNC
40+
commands:
41+
ready: pgrep xfdesktop 1>/dev/null
42+
start: |
43+
vnc
44+
~/android-studio/bin/studio
45+
stop: vncserver -kill :1
3546
triggeredBy:
3647
- postEnvironmentStart
3748

0 commit comments

Comments
 (0)