Skip to content

Commit

Permalink
refactor: move to a shared base image
Browse files Browse the repository at this point in the history
  • Loading branch information
IncognitoTGT committed Feb 11, 2025
1 parent 107c08e commit 374b885
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 155 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build the Docker image
run: npm run --prefix ./workspaces build -- --multi-platform --quiet --push
run: npm run --prefix ./workspaces build -- --build-base --multi-platform --push
12 changes: 6 additions & 6 deletions packages/db/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +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",
},
// {
// 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
15 changes: 1 addition & 14 deletions workspaces/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,4 @@

These are the Docker images that are used for Stardust Workspaces. They have a VNC server running, along with a PulseAudio server for audio, and a simple HTTP server for file transfers.

## Building

```bash
pnpm build
```
### Options

`--multi-platform`: Build for both arm64 and amd64. By default, the script builds for your host machine's arch.

`--push`: Push the images to docker registry. This only exists for the GitHub workflow and for devs and serves no purpose to others.

`--quiet`: Suppress logs in the console.

`--images`: Comma separated list of images to build with no spaces e.g. `--images chromium,firefox,zen`
More info in the [Stardust Workspaces Documentation](https://stardust.spaceness.team/docs/development/workspaces)
16 changes: 7 additions & 9 deletions workspaces/template/Dockerfile → workspaces/base.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@ 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
COPY ./shared /opt/stardust/shared

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 curl inetutils-ping vim tigervnc-tools tigervnc-standalone-server tigervnc-common \
{{APPLICATION_PACKAGE}}
python3 python3-pip xterm git procps python3-numpy xfwm4 xfce4-terminal xfce4-session xfconf xfce4-notifyd wget curl inetutils-ping vim tigervnc-tools tigervnc-standalone-server tigervnc-common \
gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

RUN bash /opt/stardust/scripts/prepare.sh
RUN bash /opt/stardust/shared/prepare.sh
USER stardust
COPY ./{{NAME}}/xstartup /opt/stardust/xstartup
RUN bash /opt/stardust/scripts/vnc-setup.sh
RUN bash /opt/stardust/shared/vnc-setup.sh

WORKDIR /home/stardust
CMD ["bash", "/opt/stardust/scripts/start.sh"]
EXPOSE 5901 4713 6080
CMD ["bash", "/opt/stardust/shared/start.sh"]
39 changes: 39 additions & 0 deletions workspaces/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,42 @@ function getFlagContents(flag, replacement) {
return replacement;
}

function buildBase() {
console.log("✨ Stardust: Building debian base...");
const multiPlatformBuild = flags.includes("--multi-platform");
return new Promise((resolve, reject) => {
const baseProcess = spawn(
"docker",
[
"buildx",
"build",
".",
"-f",
"base.Dockerfile",
`--progress=${argv.includes("--quiet") ? "quiet" : "plain"}`,
optionalFlag("--push"),
multiPlatformBuild ? "--platform" : "",
multiPlatformBuild ? "linux/amd64,linux/arm64" : "",
"--tag",
"ghcr.io/spaceness/debian-base",
],
{ stdio: "inherit", shell: true },
);
baseProcess.on("close", (code) => {
if (code === 0) {
resolve(0);
} else {
console.error(`✨ Stardust: Failed to build debian base with code ${code}`);
reject(new Error("Build failed for debian base"));
}
});
baseProcess.on("error", (err) => {
console.error(`✨ Stardust: Error while building debian base: ${err.message}`);
reject(err);
});
});
}

function buildImage(image) {
return new Promise((resolve, reject) => {
console.log(`✨ Stardust: Building ${image}...`);
Expand Down Expand Up @@ -74,6 +110,9 @@ try {
} else {
images = defaultImages;
}
if (argv.includes("--build-base")) {
await buildBase();
}

await Promise.all(images.map(buildImage));
console.log("✨ Stardust: All images built successfully!");
Expand Down
30 changes: 8 additions & 22 deletions workspaces/chromium/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
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

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 x11vnc xfce4-terminal xfce4-session xfconf xfce4-notifyd \
wget curl inetutils-ping vim tigervnc-tools tigervnc-standalone-server tigervnc-common wmctrl \
chromium gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly

RUN bash /opt/stardust/scripts/prepare.sh
FROM ghcr.io/spaceness/debian-base as base
RUN sudo apt-get update \
&& sudo apt-get install --no-install-recommends -y \
x11vnc \
wmctrl \
chromium
USER stardust
COPY ./chromium/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
COPY ./chromium/xstartup /home/stardust/.vnc/xstartup
RUN sudo chmod +x /home/stardust/.vnc/xstartup
32 changes: 11 additions & 21 deletions workspaces/debian/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
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

FROM ghcr.io/spaceness/debian-base as base
USER root
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 neofetch \
xfce4 wget curl xfce4-goodies inetutils-ping firefox-esr chromium gimp remmina remmina-plugin-vnc remmina-plugin-rdp flatpak vim \
tigervnc-tools tigervnc-standalone-server tigervnc-common gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly wmctrl

RUN bash /opt/stardust/scripts/prepare.sh
neofetch \
xfce4 xfce4-goodies \
firefox-esr chromium gimp \
remmina remmina-plugin-vnc remmina-plugin-rdp \
flatpak \
wmctrl \
&& rm -rf /var/lib/apt/lists/*
COPY ./debian/xstartup /home/stardust/.vnc/xstartup
RUN chmod +x /home/stardust/.vnc/xstartup
USER stardust
COPY ./debian/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
27 changes: 5 additions & 22 deletions workspaces/firefox/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,6 @@
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 procps python3-numpy xfwm4 xfce4-terminal xfce4-session xfconf xfce4-notifyd \
wget curl inetutils-ping vim tigervnc-tools tigervnc-standalone-server tigervnc-common \
firefox-esr

RUN bash /opt/stardust/scripts/prepare.sh
FROM ghcr.io/spaceness/debian-base as base
RUN sudo apt-get update \
&& sudo apt-get install --no-install-recommends -y firefox-esr
USER stardust
COPY ./firefox/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
COPY ./firefox/xstartup /home/stardust/.vnc/xstartup
RUN sudo chmod +x /home/stardust/.vnc/xstartup
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ chmod 777 /home/stardust
chmod 777 /opt/stardust
echo "stardust ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
usermod -aG sudo stardust
gcc -o /opt/stardust/tcpulse /opt/stardust/scripts/tcpulse.c
gcc -o /opt/stardust/tcpulse /opt/stardust/shared/tcpulse.c
2 changes: 1 addition & 1 deletion workspaces/scripts/start.sh → workspaces/shared/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sleep 1
# files
echo "while :
do
node /opt/stardust/scripts/files.mjs --pass $PASS
node /opt/stardust/shared/files.mjs --pass $PASS
sleep 5
done
" | bash &
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/bin/bash
mkdir -p /home/stardust/.vnc
touch /home/stardust/.Xresources /home/stardust/.Xauthority
cp /opt/stardust/xstartup /home/stardust/.vnc/xstartup
sudo chmod +x /home/stardust/.vnc/xstartup
11 changes: 0 additions & 11 deletions workspaces/template/xstartup

This file was deleted.

29 changes: 5 additions & 24 deletions workspaces/vscode/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
## 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

# broken currently
FROM ghcr.io/spaceness/debian-base as base
USER root
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
COPY ./vscode/xstartup /home/stardust/.vnc/xstartup
RUN sudo chmod +x /home/stardust/.vnc/xstartup
24 changes: 3 additions & 21 deletions workspaces/zen/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
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
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 procps python3-numpy xfwm4 xfce4-terminal xfce4-session xfconf xfce4-notifyd \
curl inetutils-ping tigervnc-tools tigervnc-standalone-server tigervnc-common

FROM ghcr.io/spaceness/debian-base as base
COPY ./zen/install.sh /opt/stardust/scripts/zen-install.sh

RUN bash /opt/stardust/scripts/prepare.sh
USER stardust
RUN bash /opt/stardust/scripts/zen-install.sh
COPY ./zen/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
COPY ./zen/xstartup /home/stardust/.vnc/xstartup
RUN sudo chmod +x /home/stardust/.vnc/xstartup

0 comments on commit 374b885

Please sign in to comment.