Spaces:
Build error
Build error
Create Dockerfile
Browse files- Dockerfile +86 -0
Dockerfile
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# VM Management API with Podman - Non-privileged Container
|
| 2 |
+
FROM ubuntu:22.04
|
| 3 |
+
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
ENV PYTHONUNBUFFERED=1
|
| 7 |
+
|
| 8 |
+
RUN apt-get update -qq && \
|
| 9 |
+
apt-get install -y -qq \
|
| 10 |
+
curl \
|
| 11 |
+
python3 \
|
| 12 |
+
python3-pip \
|
| 13 |
+
python3-dev \
|
| 14 |
+
build-essential \
|
| 15 |
+
ca-certificates \
|
| 16 |
+
gnupg \
|
| 17 |
+
lsb-release \
|
| 18 |
+
uidmap \
|
| 19 |
+
slirp4netns \
|
| 20 |
+
iptables \
|
| 21 |
+
&& \
|
| 22 |
+
curl -fsSL https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_$(lsb_release -rs)/Release.key | \
|
| 23 |
+
gpg --dearmor | tee /etc/apt/keyrings/devel_kubic_libcontainers_stable.gpg > /dev/null && \
|
| 24 |
+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/devel_kubic_libcontainers_stable.gpg] \
|
| 25 |
+
https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_$(lsb_release -rs)/ /" | \
|
| 26 |
+
tee /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list > /dev/null && \
|
| 27 |
+
apt-get update -qq && \
|
| 28 |
+
apt-get install -y -qq podman && \
|
| 29 |
+
# Clean up
|
| 30 |
+
apt-get clean && \
|
| 31 |
+
rm -rf /var/lib/apt/lists/*
|
| 32 |
+
|
| 33 |
+
# Create a non-root user for running podman rootlessly
|
| 34 |
+
RUN useradd -m -s /bin/bash vmuser && \
|
| 35 |
+
usermod -aG sudo vmuser && \
|
| 36 |
+
echo "vmuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
|
| 37 |
+
|
| 38 |
+
# Configure podman for rootless operation
|
| 39 |
+
USER vmuser
|
| 40 |
+
WORKDIR /home/vmuser
|
| 41 |
+
|
| 42 |
+
# Set up podman configuration
|
| 43 |
+
RUN mkdir -p ~/.config/containers && \
|
| 44 |
+
echo '[registries.search]' > ~/.config/containers/registries.conf && \
|
| 45 |
+
echo 'registries = ["docker.io", "quay.io", "registry.fedoraproject.org"]' >> ~/.config/containers/registries.conf && \
|
| 46 |
+
echo '' >> ~/.config/containers/registries.conf && \
|
| 47 |
+
echo '[registries.insecure]' >> ~/.config/containers/registries.conf && \
|
| 48 |
+
echo 'registries = []' >> ~/.config/containers/registries.conf && \
|
| 49 |
+
echo '' >> ~/.config/containers/registries.conf && \
|
| 50 |
+
echo '[registries.block]' >> ~/.config/containers/registries.conf && \
|
| 51 |
+
echo 'registries = []' >> ~/.config/containers/registries.conf
|
| 52 |
+
|
| 53 |
+
# Set up podman storage
|
| 54 |
+
RUN mkdir -p ~/.local/share/containers/storage
|
| 55 |
+
|
| 56 |
+
# Copy application files
|
| 57 |
+
USER root
|
| 58 |
+
COPY . /app
|
| 59 |
+
RUN chown -R vmuser:vmuser /app
|
| 60 |
+
|
| 61 |
+
USER vmuser
|
| 62 |
+
WORKDIR /app
|
| 63 |
+
|
| 64 |
+
# Install Python dependencies
|
| 65 |
+
RUN pip3 install --user flask flask-cors requests
|
| 66 |
+
|
| 67 |
+
# Create directory for podman volumes (if needed)
|
| 68 |
+
RUN mkdir -p /tmp/vm-data
|
| 69 |
+
|
| 70 |
+
# Expose the port (7860 as configured)
|
| 71 |
+
EXPOSE 7860
|
| 72 |
+
|
| 73 |
+
# Set environment variables for podman
|
| 74 |
+
ENV XDG_RUNTIME_DIR=/tmp/runtime-vmuser
|
| 75 |
+
ENV DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/runtime-vmuser/bus
|
| 76 |
+
|
| 77 |
+
# Create runtime directory
|
| 78 |
+
RUN mkdir -p $XDG_RUNTIME_DIR && \
|
| 79 |
+
chmod 700 $XDG_RUNTIME_DIR
|
| 80 |
+
|
| 81 |
+
# Health check
|
| 82 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 83 |
+
CMD curl -f http://localhost:7860/ || exit 1
|
| 84 |
+
|
| 85 |
+
# Run the VM server
|
| 86 |
+
CMD ["python3", "lib.py", "server"]
|