Skip to content

Commit

Permalink
chore: start vsc workspace, bug fixes in admin dash, format code
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Feb 11, 2025
1 parent b6e5e4b commit 107c08e
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 17 deletions.
1 change: 1 addition & 0 deletions apps/web/src/app/(main)/admin/workspaces/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ export async function deleteImageFromNode(workspace: SelectWorkspace, nId: strin
const connector = stardustConnector(node);
const { data, error } = await connector.workspaces.info.delete(undefined, { query: { id: workspace.dockerImage } });
if (error) throw new Error(error.value.message);
revalidatePath("/admin/workspaces");
return data;
}
17 changes: 12 additions & 5 deletions apps/web/src/app/(main)/admin/workspaces/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,18 @@ export function NodeDialog({ workspace, open, setOpen }: Props) {
<Button
variant="destructive"
onClick={() =>
toast.promise(() => deleteImageFromNode(workspace, nodeWorkspace.id), {
loading: "Removing from node",
success: "Removed from node",
error: "Failed to remove from node",
})
toast.promise(
async () => {
const promise = await deleteImageFromNode(workspace, nodeWorkspace.id);
mutate();
return promise;
},
{
loading: "Removing from node",
success: "Removed from node",
error: "Failed to remove from node",
},
)
}
>
Remove from node
Expand Down
6 changes: 6 additions & 0 deletions packages/db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ const workspaces = [
category: ["Browser"],
icon: "https://www.mozilla.org/media/protocol/img/logos/firefox/browser/logo.eb1324e44442.svg",
},
{
dockerImage: "ghcr.io/spaceness/vscode",
friendlyName: "VSCode",
category: ["Development"],
icon: "https://code.visualstudio.com/assets/apple-touch-icon.png",
},
];
const insertion = await db.insert(workspace).values(workspaces).onConflictDoNothing().returning();
console.log(`✨Stardust: Seeded ${insertion.map((i) => i.dockerImage).join(", ") || "no images"}`);
Expand Down
31 changes: 19 additions & 12 deletions workspaces/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ const flags = args.filter((value) => value.startsWith("--"));

const optionalFlag = (flag) => (flags.includes(flag) ? flag : "");

function getFlagContents (flag, replacement) {
const indexOf = flags.indexOf(flag)
const nextArg = args[indexOf + 1]
if (indexOf != -1 && nextArg) {
return nextArg
} else {
return replacement
function getFlagContents(flag, replacement) {
const indexOf = flags.indexOf(flag);
const nextArg = args[indexOf + 1];
if (indexOf !== -1 && nextArg) {
return nextArg;
}
return replacement;
}

function buildImage(image) {
Expand All @@ -34,15 +33,23 @@ function buildImage(image) {
".",
"-f",
`${image}/Dockerfile`,
optionalFlag("--quiet"),
`--progress=${argv.includes("--quiet") ? "quiet" : "plain"}`,
optionalFlag("--push"),
multiPlatformBuild ? "--platform" : "",
multiPlatformBuild ? platforms : "",
"--tag",
`ghcr.io/spaceness/${image}`,
],
{ stdio: "inherit", shell: true },
{ stdio: ["inherit", "pipe", "pipe"], shell: true },
);

process.stdout.on("data", (data) => {
globalThis.process.stdout.write(`${image}: ${data}`);
});

process.stderr.on("data", (data) => {
globalThis.process.stderr.write(`${image}: ${data}`);
});
process.on("close", (code) => {
if (code === 0) {
resolve(0);
Expand All @@ -60,12 +67,12 @@ function buildImage(image) {
}

try {
let images = getFlagContents("--images", undefined)
let images = getFlagContents("--images", undefined);

if (images) {
images = images.split(',')
images = images.split(",");
} else {
images = defaultImages
images = defaultImages;
}

await Promise.all(images.map(buildImage));
Expand Down
27 changes: 27 additions & 0 deletions workspaces/vscode/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## This is currently broken

FROM debian:bookworm
LABEL org.opencontainers.image.source=https://github.com/spaceness/stardust
WORKDIR /opt/stardust
ENV USER=stardust
ENV PNPM_HOME="/home/stardust/.local/share/pnpm"
ENV DEBIAN_FRONTEND=noninteractive

COPY ./scripts /opt/stardust/scripts
# idk if all of these are needed someone fix this - @incognitotgt
RUN apt-get update && apt-get install --no-install-recommends -y \
xfonts-75dpi xvfb passwd sudo dbus dbus-x11 libxrandr2 libxext-dev libxrender-dev libxtst-dev imagemagick x11-apps build-essential pulseaudio gstreamer1.0* fonts-noto-color-emoji \
python3 python3-pip xterm git procps python3-numpy xfwm4 xfce4-terminal xfce4-session xfconf xfce4-notifyd \
wget gpg curl inetutils-ping tigervnc-tools tigervnc-standalone-server tigervnc-common

COPY ./vscode/install.sh /opt/stardust/scripts/vscode-install.sh

RUN bash /opt/stardust/scripts/prepare.sh
USER stardust
RUN bash /opt/stardust/scripts/vscode-install.sh
COPY ./vscode/xstartup /opt/stardust/xstartup
RUN bash /opt/stardust/scripts/vnc-setup.sh

WORKDIR /home/stardust
CMD ["bash", "/opt/stardust/scripts/start.sh"]
EXPOSE 5901 4713 6080
11 changes: 11 additions & 0 deletions workspaces/vscode/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
set -euo pipefail
download_url="https://code.visualstudio.com/sha/download?build=stable&os=linux-$(dpkg-architecture -q DEB_BUILD_ARCH)"
echo "Installing VSCode..."
echo "Downloading"
echo $download_url
curl -fSL $download_url -o /tmp/vscode.tar.gz
echo "Extracting"
mkdir -p /home/stardust/.local/share/vscode
tar --strip-components=1 -xzf /tmp/vscode.tar.gz -C /home/stardust/.local/share/vscode
echo "Success!"
12 changes: 12 additions & 0 deletions workspaces/vscode/xstartup
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
xrdb $HOME/.Xresources
export DISPLAY=":1"
startxfce4 &
sleep 1
sudo service dbus start
echo "while :
do
/home/stardust/.local/share/vscode/bin/code --no-sandbox --verbose --wait
sleep 2
done
" | bash

0 comments on commit 107c08e

Please sign in to comment.