Skip to content

Commit 595157a

Browse files
committed
Standardized Dockerfiles for better memory handling
1 parent 66edd9f commit 595157a

File tree

4 files changed

+60
-60
lines changed

4 files changed

+60
-60
lines changed

.github/workflows/docker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- name: Build and Push VNC Image
3636
uses: docker/build-push-action@v6
3737
with:
38-
platforms: linux/amd64,linux/arm64
38+
platforms: linux/amd64
3939
context: ./Docker
4040
push: true
4141
file: ./Docker/Dockerfile.vnc
@@ -44,7 +44,7 @@ jobs:
4444
- name: Build and Push Standard Image
4545
uses: docker/build-push-action@v6
4646
with:
47-
platforms: linux/amd64,linux/arm64
47+
platforms: linux/amd64
4848
context: ./Docker
4949
push: true
5050
file: ./Docker/Dockerfile

Docker/Dockerfile.gitpod

+29-25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LABEL maintainer "Lukas Rustler <[email protected]>"
55

66
# Non-interactive installation mode
77
ENV DEBIAN_FRONTEND=noninteractive
8+
ARG TARGETPLATFORM
89
#Change for other python; 3.11 may be too much right now
910
ARG PYTHON_VER=3.11
1011

@@ -24,12 +25,14 @@ RUN locale-gen en_US.UTF-8
2425
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python$PYTHON_VER && \
2526
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.8
2627

27-
#Add gitpod user with correct UID and GID; and add him to sudoers
28-
RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash gitpod && \
29-
echo 'gitpod:gitpod' | chpasswd && usermod -aG sudo gitpod && \
30-
sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers && \
31-
echo "gitpod ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && mkdir -p /home/gitpod/Desktop
32-
RUN wget -O code.deb https://go.microsoft.com/fwlink/?LinkID=760868 && gdebi -n code.deb && rm code.deb
28+
# VSCode
29+
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
30+
wget -O code.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-arm64"; \
31+
else \
32+
wget -O code.deb https://go.microsoft.com/fwlink/?LinkID=760868; \
33+
fi
34+
35+
RUN gdebi -n code.deb && rm code.deb
3336

3437
# Install graphics
3538
RUN apt install -y xfce4 xfce4-goodies xserver-xorg-video-dummy xserver-xorg-legacy x11vnc firefox && \
@@ -54,10 +57,6 @@ RUN git clone https://github.com/novnc/noVNC.git /opt/novnc && \
5457
git clone https://github.com/novnc/websockify /opt/novnc/utils/websockify && \
5558
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; url=vnc.html?autoconnect=true&reconnect=true&reconnect_delay=1000&resize=scale&quality=9\"></head></html>" > /opt/novnc/index.html
5659

57-
# Set environmental variables
58-
ENV DISPLAY=:1
59-
ENV VNC_DISPLAY=:1
60-
6160
# Install informative git for bash
6261
RUN git clone https://github.com/magicmonty/bash-git-prompt.git /home/gitpod/.bash-git-prompt --depth=1
6362

@@ -66,39 +65,44 @@ COPY additional_files/start-vnc-session.sh /usr/bin/start-vnc-session.sh
6665
RUN chmod +x /usr/bin/start-vnc-session.sh && \
6766
dos2unix /usr/bin/start-vnc-session.sh
6867

69-
# Set up VSCode launcher
70-
COPY ["additional_files/Visual Studio Code.desktop", "/home/gitpod/Desktop/Visual Studio Code.desktop"]
71-
RUN chown gitpod:gitpod "/home/gitpod/Desktop/Visual Studio Code.desktop" && chmod +x "/home/gitpod/Desktop/Visual Studio Code.desktop" && \
72-
dos2unix "/home/gitpod/Desktop/Visual Studio Code.desktop"
73-
7468
# PyCharm
7569
ARG PYCHARM_VER=2024.3.4
7670
RUN cd /opt && wget https://download.jetbrains.com/python/pycharm-community-$PYCHARM_VER.tar.gz && \
7771
tar -xvf pycharm-community-$PYCHARM_VER.tar.gz && rm pycharm-community-$PYCHARM_VER.tar.gz && \
7872
mv pycharm-community-$PYCHARM_VER pycharm && ln -s /opt/pycharm/bin/pycharm.sh /usr/bin/pycharm && chmod +x /usr/bin/pycharm
7973

80-
81-
COPY ["additional_files/PyCharm.desktop", "/home/gitpod/Desktop/PyCharm.desktop"]
82-
83-
RUN chown gitpod:gitpod "/home/gitpod/Desktop/PyCharm.desktop" && chmod +x "/home/gitpod/Desktop/PyCharm.desktop" && \
84-
dos2unix "/home/gitpod/Desktop/PyCharm.desktop"
85-
8674
# Manage ports
8775
EXPOSE 5901 6080 8888 10000/tcp 10000/udp
8876

77+
RUN python$PYTHON_VER -m pip install --upgrade pip && python$PYTHON_VER -m pip install "numpy<2" cython open3d pybullet roboticstoolbox-python --ignore-installed
78+
RUN python$PYTHON_VER -m pip install psutil --force-reinstall
79+
80+
#Add gitpod user with correct UID and GID; and add him to sudoers
81+
RUN useradd -l -u 33333 -G sudo -md /home/gitpod -s /bin/bash gitpod && \
82+
echo 'gitpod:gitpod' | chpasswd && usermod -aG sudo gitpod && \
83+
sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers && \
84+
echo "gitpod ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && mkdir -p /home/gitpod/Desktop \
85+
8986
RUN echo "alias vnc='export DISPLAY=\$VNC_DISPLAY'" >> /home/gitpod/.bashrc
9087
RUN echo "export PORT=5901" >> /home/gitpod/.bashrc
88+
USER gitpod
89+
# Set up VSCode launcher
90+
COPY ["additional_files/Visual Studio Code.desktop", "/home/gitpod/Desktop/Visual Studio Code.desktop"]
91+
RUN chown gitpod:gitpod "/home/gitpod/Desktop/Visual Studio Code.desktop" && chmod +x "/home/gitpod/Desktop/Visual Studio Code.desktop" && \
92+
dos2unix "/home/gitpod/Desktop/Visual Studio Code.desktop"
93+
COPY ["additional_files/PyCharm.desktop", "/home/gitpod/Desktop/PyCharm.desktop"]
9194

92-
RUN python$PYTHON_VER -m pip install --user --upgrade pip && python$PYTHON_VER -m pip install "numpy<2" cython open3d pybullet roboticstoolbox-python --ignore-installed
95+
RUN chown gitpod:gitpod "/home/gitpod/Desktop/PyCharm.desktop" && chmod +x "/home/gitpod/Desktop/PyCharm.desktop" && \
96+
dos2unix "/home/gitpod/Desktop/PyCharm.desktop" \
9397

94-
USER gitpod
9598
RUN cd /home/gitpod && git clone https://github.com/rustlluk/pyCub.git && cd pyCub && git checkout dev && python$PYTHON_VER setup.py install --user
96-
RUN python$PYTHON_VER -m pip install psutil --force-reinstall
99+
97100

98101
RUN sudo ln -sf /usr/bin/python$PYTHON_VER /usr/local/bin/python && sudo ln -sf /usr/bin/python$PYTHON_VER /usr/local/bin/python3
99102
RUN echo "export PATH=/usr/local/bin:$PATH" >> /home/gitpod/.bashrc
100103
RUN echo "export BROWSER=/usr/bin/firefox" >> /home/gitpod/.bashrc
101-
104+
ENV VNC_DISPLAY=:99
105+
ENV DISPLAY=:99
102106
# Clean up unnecessary installation products
103107
RUN sudo rm -Rf /var/lib/apt/lists/*
104108

Docker/Dockerfile.vnc

+20-22
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ RUN locale-gen en_US.UTF-8
2525
RUN curl -sS https://bootstrap.pypa.io/get-pip.py | python$PYTHON_VER && \
2626
curl -sS https://bootstrap.pypa.io/get-pip.py | python3.8
2727

28-
#Add docker user with correct UID and GID; and add him to sudoers
29-
RUN useradd -l -u 33333 -G sudo -md /home/docker -s /bin/bash docker && \
30-
echo 'docker:docker' | chpasswd && usermod -aG sudo docker && \
31-
sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers && \
32-
echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && mkdir -p /home/docker/Desktop
33-
3428
# VSCode
3529
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then \
3630
wget -O code.deb "https://code.visualstudio.com/sha/download?build=stable&os=linux-deb-arm64"; \
@@ -63,9 +57,6 @@ RUN git clone https://github.com/novnc/noVNC.git /opt/novnc && \
6357
git clone https://github.com/novnc/websockify /opt/novnc/utils/websockify && \
6458
echo "<html><head><meta http-equiv=\"Refresh\" content=\"0; url=vnc.html?autoconnect=true&reconnect=true&reconnect_delay=1000&resize=scale&quality=9\"></head></html>" > /opt/novnc/index.html
6559

66-
# Set environmental variables
67-
RUN echo "export DISPLAY=:99" >> /home/docker/.bashrc
68-
6960
# Install informative git for bash
7061
RUN git clone https://github.com/magicmonty/bash-git-prompt.git /home/docker/.bash-git-prompt --depth=1
7162

@@ -74,37 +65,44 @@ COPY additional_files/start-vnc-session.sh /usr/bin/start-vnc-session.sh
7465
RUN chmod +x /usr/bin/start-vnc-session.sh && \
7566
dos2unix /usr/bin/start-vnc-session.sh
7667

77-
# Set up VSCode launcher
78-
COPY ["additional_files/Visual Studio Code.desktop", "/home/docker/Desktop/Visual Studio Code.desktop"]
79-
RUN chown docker:docker "/home/docker/Desktop/Visual Studio Code.desktop" && chmod +x "/home/docker/Desktop/Visual Studio Code.desktop" && \
80-
dos2unix "/home/docker/Desktop/Visual Studio Code.desktop"
81-
8268
# PyCharm
8369
ARG PYCHARM_VER=2024.3.4
8470
RUN cd /opt && wget https://download.jetbrains.com/python/pycharm-community-$PYCHARM_VER.tar.gz && \
8571
tar -xvf pycharm-community-$PYCHARM_VER.tar.gz && rm pycharm-community-$PYCHARM_VER.tar.gz && \
8672
mv pycharm-community-$PYCHARM_VER pycharm && ln -s /opt/pycharm/bin/pycharm.sh /usr/bin/pycharm && chmod +x /usr/bin/pycharm
8773

88-
89-
COPY ["additional_files/PyCharm.desktop", "/home/docker/Desktop/PyCharm.desktop"]
90-
RUN chown docker:docker "/home/docker/Desktop/PyCharm.desktop" && chmod +x "/home/docker/Desktop/PyCharm.desktop" && \
91-
dos2unix "/home/docker/Desktop/PyCharm.desktop"
92-
9374
# Manage ports
9475
EXPOSE 5901 6080 8888 10000/tcp 10000/udp
9576

77+
RUN python$PYTHON_VER -m pip install --user --upgrade pip && python$PYTHON_VER -m pip install "numpy<2" cython open3d pybullet roboticstoolbox-python --ignore-installed
78+
RUN python$PYTHON_VER -m pip install psutil --force-reinstall
79+
80+
81+
#Add docker user with correct UID and GID; and add him to sudoers
82+
RUN useradd -l -u 33333 -G sudo -md /home/docker -s /bin/bash docker && \
83+
echo 'docker:docker' | chpasswd && usermod -aG sudo docker && \
84+
sed -i.bkp -e 's/%sudo\s\+ALL=(ALL\(:ALL\)\?)\s\+ALL/%sudo ALL=NOPASSWD:ALL/g' /etc/sudoers && \
85+
echo "docker ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers && mkdir -p /home/docker/Desktop \
86+
9687
RUN echo "alias vnc='export DISPLAY=:99'" >> /home/docker/.bashrc
9788
RUN echo "export PORT=5999" >> /home/docker/.bashrc
89+
USER docker
90+
# Set up VSCode launcher
91+
COPY ["additional_files/Visual Studio Code.desktop", "/home/docker/Desktop/Visual Studio Code.desktop"]
92+
RUN chown docker:docker "/home/docker/Desktop/Visual Studio Code.desktop" && chmod +x "/home/docker/Desktop/Visual Studio Code.desktop" && \
93+
dos2unix "/home/docker/Desktop/Visual Studio Code.desktop"
9894

99-
RUN python$PYTHON_VER -m pip install --user --upgrade pip && python$PYTHON_VER -m pip install "numpy<2" cython open3d pybullet roboticstoolbox-python --ignore-installed
95+
COPY ["additional_files/PyCharm.desktop", "/home/docker/Desktop/PyCharm.desktop"]
96+
RUN chown docker:docker "/home/docker/Desktop/PyCharm.desktop" && chmod +x "/home/docker/Desktop/PyCharm.desktop" && \
97+
dos2unix "/home/docker/Desktop/PyCharm.desktop"
10098

101-
USER docker
10299
RUN cd /home/docker && git clone https://github.com/rustlluk/pyCub.git && cd pyCub && git checkout dev && python$PYTHON_VER setup.py install --user
103-
RUN python$PYTHON_VER -m pip install psutil --force-reinstall
104100

105101
RUN sudo ln -sf /usr/bin/python$PYTHON_VER /usr/local/bin/python && sudo ln -sf /usr/bin/python$PYTHON_VER /usr/local/bin/python3
106102
RUN echo "export PATH=/usr/local/bin:$PATH" >> /home/docker/.bashrc
107103
RUN echo "export BROWSER=/usr/bin/firefox" >> /home/docker/.bashrc
104+
# Set environmental variables
105+
RUN echo "export DISPLAY=:99" >> /home/docker/.bashrc
108106

109107
# Clean up unnecessary installation products
110108
RUN sudo rm -Rf /var/lib/apt/lists/*

Docker/deploy.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ def main():
163163
if inp.lower() not in ["y", "yes"]:
164164
return 0
165165

166-
# create correct xauth file for usage with graphics and over SSH
167-
print("Creating xauth")
168-
create_xauth.main()
166+
if not vnc:
167+
# create correct xauth file for usage with graphics and over SSH
168+
print("Creating xauth")
169+
create_xauth.main()
169170

170171
if pull:
171172
if not vnc:
@@ -192,15 +193,12 @@ def main():
192193
cmd = "docker stop " + container + " && docker rm " + container
193194
call(cmd, shell=True, stderr=PIPE, stdout=PIPE)
194195

195-
# command to run a new container with all necessary arguments
196-
if vnc:
197-
display = "-e DISPLAY=:99"
196+
if not vnc:
197+
cmd = (f'docker run -it "-u $(id -u):$(id -g) -e DISPLAY -e "QT_X11_NO_MITSHM=1" -e "XAUTHORITY=/tmp/.docker.xauth" '
198+
f'-v /tmp/.docker.xauth:/tmp/.docker.xauth:rw -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" -v /dev:/dev '
199+
f'-v /etc/hosts:/etc/hosts --network host --privileged --name {container} -v {path}:/home/docker/pycub_ws {image}')
198200
else:
199-
display = "-e DISPLAY"
200-
201-
cmd = (f'docker run -it {"" if vnc else "-u $(id -u):$(id -g) "}{display} -e "QT_X11_NO_MITSHM=1" -e "XAUTHORITY=/tmp/.docker.xauth" '
202-
f'-v /tmp/.docker.xauth:/tmp/.docker.xauth:rw -v "/tmp/.X11-unix:/tmp/.X11-unix:rw" -v /dev:/dev '
203-
f'-v /etc/hosts:/etc/hosts --network host --privileged --name {container} -v {path}:/home/docker/pycub_ws {image}')
201+
cmd = f"docker run -it -e DISPLAY=:99 --name {container} -p 6080:680 -p 8888:8888 -v {path}:/home/docker/pycub_ws {image}"
204202

205203
# add nvidia runtime if needed
206204
if nvidia:

0 commit comments

Comments
 (0)