86 lines
3.4 KiB
Docker
86 lines
3.4 KiB
Docker
FROM python:3.13-alpine
|
|
|
|
ARG TARGET=thechart
|
|
ARG ICON=chart-671.png
|
|
ARG UID=1000
|
|
ARG GUID=1000
|
|
|
|
USER root
|
|
WORKDIR /app
|
|
|
|
RUN apk add --no-cache \
|
|
build-base \
|
|
libffi-dev \
|
|
musl-dev \
|
|
libressl-dev \
|
|
tk-dev \
|
|
tcl-dev \
|
|
xorg-server \
|
|
xauth \
|
|
xvfb \
|
|
font-terminus font-inconsolata font-dejavu font-noto font-noto-cjk font-awesome font-noto-extra \
|
|
&& pip install --upgrade pip && pip install pyinstaller python-dotenv
|
|
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# RUN export uid=$UID gid=$GUID
|
|
RUN mkdir -p /home/docker_user
|
|
RUN echo "docker_user:x:${UID}:${GUID}:docker_user,,,:/home/docker_user:/bin/bash" >> /etc/passwd
|
|
RUN echo "docker_user:x:${UID}:" >> /etc/group
|
|
RUN mkdir -p /etc/sudoers.d && echo "docker_user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/docker_user
|
|
RUN chmod 0440 /etc/sudoers.d/docker_user
|
|
RUN chown -R ${UID}:${GUID} /home/docker_user
|
|
|
|
COPY --chown=${UID}:${GUID} --chmod=765 ./src/ ./src/
|
|
COPY --chown=${UID}:${GUID} --chmod=765 ./.env .
|
|
COPY --chown=${UID}:${GUID} --chmod=765 ./thechart_data.csv .
|
|
COPY --chown=${UID}:${GUID} --chmod=765 ./${ICON} .
|
|
|
|
ARG HOME=/home/docker_user
|
|
ENV HOME=/home/docker_user
|
|
|
|
# Make sure the icon file and data file are in the right location
|
|
RUN cp -f ./${ICON} ./src/ && cp -f ./thechart_data.csv ./.env ./src/
|
|
|
|
# Debug the environment
|
|
RUN echo "Icon file is: ${ICON}"
|
|
RUN ls -la ./src/
|
|
|
|
# Use a shell command with variable expansion to make sure variables are properly substituted
|
|
RUN sh -c "pyinstaller --name ${TARGET} --optimize 2 --onefile --windowed --hidden-import='PIL._tkinter_finder' --icon=./src/chart-671.png --add-data='.env:.' --add-data='./src/chart-671.png:.' --add-data='./src/thechart_data.csv:.' --distpath ${HOME}/${TARGET} ./src/main.py"
|
|
|
|
RUN chown -R ${UID}:${GUID} /home/docker_user/
|
|
RUN chmod -R 777 /home/docker_user/${TARGET}
|
|
|
|
RUN mkdir -p /app/logs && \
|
|
touch /app/logs/app.log && \
|
|
chown -R ${UID}:${GUID} /app/logs && \
|
|
chmod 666 /app/logs/app.log
|
|
|
|
# Set environment variables for X11 forwarding
|
|
ENV DISPLAY=:0
|
|
ENV XAUTHORITY=/tmp/.docker.xauth
|
|
ENV QT_X11_NO_MITSHM=1
|
|
|
|
# Create a startup script to handle X11 setup and application launch
|
|
# Create a proper entrypoint script with correct line endings
|
|
RUN echo '#!/bin/sh' > /home/docker_user/entrypoint.sh && \
|
|
echo 'set -e' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'echo "Starting entrypoint script..."' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'echo "DISPLAY=$DISPLAY"' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'echo "XAUTHORITY=$XAUTHORITY"' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'echo "HOME=$HOME"' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'mkdir -p $(dirname $XAUTHORITY)' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'touch $XAUTHORITY || echo "Warning: Could not create $XAUTHORITY file"' >> /home/docker_user/entrypoint.sh && \
|
|
echo 'xauth nlist $DISPLAY | sed -e "s/^..../ffff/" | xauth -f $XAUTHORITY nmerge - || echo "Warning: X auth setup failed"' >> /home/docker_user/entrypoint.sh && \
|
|
echo "echo \"Starting application: \$HOME/${TARGET}/${TARGET}\"" >> /home/docker_user/entrypoint.sh && \
|
|
echo "exec \$HOME/${TARGET}/${TARGET}" >> /home/docker_user/entrypoint.sh && \
|
|
chmod +x /home/docker_user/entrypoint.sh
|
|
|
|
USER docker_user
|
|
|
|
# Set the entrypoint to our startup script through shell
|
|
ENTRYPOINT ["/bin/sh"]
|
|
CMD ["-c", "/home/docker_user/entrypoint.sh"]
|