Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Build Dependency for Docker #5156

Merged
merged 12 commits into from
Jan 25, 2025
Merged
2 changes: 1 addition & 1 deletion DockerBuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -x
# the simplicity of a single Docker image and a one-time compilation
# seems better.
docker build -t bambustudio \
--build-arg USER=$USER \
--build-arg USER=${USER:-root} \
--build-arg UID=$(id -u) \
--build-arg GID=$(id -g) \
$PROJECT_ROOT
81 changes: 81 additions & 0 deletions DockerEntrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

# Entrypoint script to create an out-of-the-box experience for BambuStudio.
# Perform some initial setup if none was done previously.
# It is not necessary if you know what you are doing. Feel free to go
# to the Dockerfile and switch the entrypoint to the BambuStudio binary.

# Check if the current effective user is root

if [ "$EUID" -eq 0 ]; then
echo "No User specified at build time."
if [ -z "$RUN_USER" ] || [ -z "$RUN_UID" ] || [ -z "$RUN_GID" ] || [ "$RUN_UID" -eq 0 ]; then
echo "At least one of RUN_USER, RUN_UID, or RUN_GID is unset. Or 'root' was requested."
echo "Running as root"

if [ "$HOME" != "/root" ]; then
if [ ! -d "/root" ]; then
mkdir /root
chown root:root /root
chmod 700 /root
fi
fi

export HOME="/root"
EXEC_USER="root"
else
echo "Setting up a new user"

# Check if there is a already a valid user entry for the passed UID, if not create one
if [ -z "$(getent passwd "$RUN_UID" | cut -d: -f1)" ]; then
#GID=$(id -g)
echo "User specified at runtime. Performing setup."
groupadd -g "$RUN_GID" "$RUN_USER"
useradd -u "$RUN_UID" -g "$RUN_GID" -d "/home/$RUN_USER" "$RUN_USER"
usermod -aG sudo "$RUN_USER"
passwd -d "$RUN_USER"

#This will take forever to run, so we will just chown the build folder which contains the binaries
#chown -R "$RUN_UID":"$RUN_GID" /BambuStudio
chown "$RUN_UID":"$RUN_GID" /BambuStudio
chown -R "$RUN_UID":"$RUN_GID" /BambuStudio/build


export HOME="/home/$RUN_USER"
EXEC_USER="$RUN_USER"
fi
fi
else
echo "User specified at build time."
CURRENT_USER=$(id -un)
if [ -n "$RUN_USER" ] && [ -n "$RUN_UID" ] && [ -n "$RUN_GID" ] && [ "$RUN_UID" -ne "$EUID" ]; then
echo "New User config passed at Runtime. Setting up."
if [ -z "$(getent passwd "$RUN_UID" | cut -d: -f1)" ]; then
sudo groupadd -g "$RUN_UID" "$RUN_USER"
sudo useradd -u "$RUN_UID" -g "$RUN_GID" -d "/home/$RUN_USER" "$RUN_USER"
sudo usermod -aG sudo "$RUN_USER"
passwd -d "$RUN_USER"

#sudo chown -R "$RUN_UID":"$RUN_GID" /BambuStudio
chown "$RUN_UID":"$RUN_GID" /BambuStudio
chown -R "$RUN_UID":"$RUN_GID" /BambuStudio/build

export HOME="/home/$RUN_USER"
EXEC_USER="$RUN_USER"
fi
else
echo "Using Build time user."
EXEC_USER="$CURRENT_USER"
#It should've been set in Dockerfile, but just in case, uncomment this it there is problem
#export HOME="/home/$USER"
fi
fi

# make sure ~/.config folder exists so Bambu Studio will start
if [ ! -d "$HOME/.config" ]; then
mkdir -p "$HOME/.config"
fi

# Using su $USER -c will retain all the important ENV args when Bamboo Studio starts in a different shell
# Continue with Bambu Studio using correct user, passing all arguments
exec su "$EXEC_USER" -c "/BambuStudio/build/package/bin/bambu-studio $*"
16 changes: 12 additions & 4 deletions DockerRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,24 @@ set -x
# -h $HOSTNAME \
# If there's problems with the X display, try this
# -v /tmp/.X11-unix:/tmp/.X11-unix \
# or
# -v $HOME/.Xauthority:/root/.Xauthority \
# You also need to run "xhost +" on your host system
# Bambu Studio also require the parent directory for the configuration directory to be present to start
# to prevent your local machines's bambu studio config passed to docker container when you map your home directory, add:
# -v :SHOME/.config/BambuStudio
set -x
docker run \
`# Use the hosts networking. Printer wifi and also dbus communication` \
--net=host \
`# Some X installs will not have permissions to talk to sockets for shared memory` \
--ipc host \
`# Run as your workstations username to keep permissions the same` \
-u $USER \
`# Bind mount your home directory into the container for loading/saving files` \
-v $HOME:/home/$USER \
-v $HOME:$HOME \
`# Pass some X Auth file to allow x11 to connect to your host x instance` \
-v $HOME/.Xauthority:/tmp/.Xauthority \
-v /tmp/.X11-unix:/tmp/.X11-unix \
-e XAUTHORITY=/tmp/.Xauthority \
`# Pass the X display number to the container` \
-e DISPLAY=$DISPLAY \
`# It seems that libGL and dbus things need privileged mode` \
Expand All @@ -24,4 +33,3 @@ docker run \
--rm \
`# Pass all parameters from this script to the bambu ENTRYPOINT binary` \
bambustudio $*

79 changes: 59 additions & 20 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
FROM docker.io/ubuntu:22.04
LABEL maintainer "DeftDawg <[email protected]>"
FROM docker.io/ubuntu:24.10

# Disable interactive package configuration
RUN apt-get update && \
Expand All @@ -14,6 +13,7 @@ RUN apt-get update && apt-get install -y \
build-essential \
cmake \
curl \
xvfb \
eglexternalplatform-dev \
extra-cmake-modules \
file \
Expand All @@ -39,14 +39,14 @@ RUN apt-get update && apt-get install -y \
libssl-dev \
libudev-dev \
libwayland-dev \
libwebkit2gtk-4.0-dev \
libxkbcommon-dev \
MackBambu marked this conversation as resolved.
Show resolved Hide resolved
locales \
locales-all \
m4 \
pkgconf \
sudo \
wayland-protocols \
libwebkit2gtk-4.1-dev \
wget

# Change your locale here if you want. See the output
Expand All @@ -58,37 +58,76 @@ RUN locale-gen $LC_ALL
# the CA cert path on every startup
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt

COPY ./ BambuStudio
COPY ./ /BambuStudio

WORKDIR BambuStudio
RUN chmod +x /BambuStudio/DockerEntrypoint.sh

# These can run together, but we run them seperate for podman caching
# Update System dependencies
WORKDIR /BambuStudio

# Ubuntu 24 Docker Image now come with default standard user "ubuntu"
# It might conflict with your mapped user, remove if user ubuntu exist
RUN if id "ubuntu" >/dev/null 2>&1; then userdel -r ubuntu; fi

# It's easier to run Bambu Studio as the same username,
# UID and GID as your workstation. Since we bind mount
# your home directory into the container, it's handy
# to keep permissions the same. Just in case, defaults
# are root.

# Set ARG values
# If user was passed from build it will create a user same
# as your workstation. Else it will use /root

# Setting ARG at build time is convienient for testing purposes
# otherwise the same commands will be executed at runtime

ARG USER=root
ARG UID=0
ARG GID=0
RUN if [ "$UID" != "0" ]; then \
groupadd -g $GID $USER && \
useradd -u $UID -g $GID -m -d /home/$USER $USER && \
mkdir -p /home/$USER && \
chown -R $UID:$GID /BambuStudio && \
usermod -aG sudo $USER && \
passwd -d "$USER"; \
else \
mkdir -p /root/.config; \
fi

# Allow password-less sudo for ALL users
RUN echo "ALL ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/999-passwordless
RUN chmod 440 /etc/sudoers.d/999-passwordless

# Update System dependencies(Run before user switch)
RUN ./BuildLinux.sh -u

# Run as the mapped user (or root by default)
USER $USER


# These can run together, but we run them seperate for podman caching
# Build dependencies in ./deps
RUN ./BuildLinux.sh -d

# Build slic3r
RUN ./BuildLinux.sh -s

# Build AppImage
ENV container podman
ENV container=podman
RUN ./BuildLinux.sh -i

# It's easier to run Bambu Studio as the same username,
# UID and GID as your workstation. Since we bind mount
# your home directory into the container, it's handy
# to keep permissions the same. Just in case, defaults
# are root.

# Use bash as the shell
SHELL ["/bin/bash", "-l", "-c"]
ARG USER=root
ARG UID=0
ARG GID=0
RUN [[ "$UID" != "0" ]] \
&& groupadd -f -g $GID $USER \
&& useradd -u $UID -g $GID $USER

# Point FFMPEG Library search to the binary built upon BambuStudio build time
ENV LD_LIBRARY_PATH=/BambuStudio/build/package/bin

# Using an entrypoint instead of CMD because the binary
# accepts several command line arguments.
ENTRYPOINT ["/BambuStudio/build/package/bin/bambu-studio"]
# entrypoint script will pass all arguments to bambu-studio
# after the script finishes

#ENTRYPOINT ["/BambuStudio/build/package/bin/bambu-studio"]
ENTRYPOINT ["/BambuStudio/DockerEntrypoint.sh"]
Loading