mirror of
https://github.com/retspen/webvirtcloud
synced 2026-10-18 09:00:07 +00:00
feat(docker): modernize Dockerfile, add runit init script, and provide docker-compose setup
- Add python3-libvirt to apt and configure --system-site-packages for zero-compilation build - Introduce 10_webvirtcloud_init.sh to handle container startup, migrations, and SQLite persistence - Exclude host settings.py in .dockerignore for clean builds from settings.py.template - Add docker-compose.yml with persistent data and SSH volume mounts - Document Docker Compose deployment in README.md
This commit is contained in:
parent
56fdd07802
commit
b1a843e846
5 changed files with 117 additions and 15 deletions
42
Dockerfile
42
Dockerfile
|
|
@ -6,7 +6,6 @@ EXPOSE 6080
|
|||
# Use baseimage-docker's init system.
|
||||
CMD ["/sbin/my_init"]
|
||||
|
||||
|
||||
RUN echo 'APT::Get::Clean=always;' >> /etc/apt/apt.conf.d/99AutomaticClean
|
||||
|
||||
RUN apt-get update -qqy \
|
||||
|
|
@ -14,8 +13,10 @@ RUN apt-get update -qqy \
|
|||
--no-install-recommends \
|
||||
git \
|
||||
python3-venv \
|
||||
python3-pip \
|
||||
python3-dev \
|
||||
python3-lxml \
|
||||
python3-libvirt \
|
||||
libvirt-dev \
|
||||
zlib1g-dev \
|
||||
nginx \
|
||||
|
|
@ -30,42 +31,53 @@ RUN apt-get update -qqy \
|
|||
# Setup webvirtcloud
|
||||
WORKDIR /srv/webvirtcloud
|
||||
|
||||
# Install Python dependencies first to leverage Docker layer caching
|
||||
# Install Python dependencies first with system-site-packages to leverage prebuilt bindings
|
||||
COPY conf/requirements.txt conf/requirements.txt
|
||||
RUN python3 -m venv venv && \
|
||||
RUN python3 -m venv --system-site-packages venv && \
|
||||
. venv/bin/activate && \
|
||||
pip3 install -U pip && \
|
||||
pip3 install wheel && \
|
||||
pip3 install -U pip wheel && \
|
||||
pip3 install -r conf/requirements.txt && \
|
||||
pip3 cache purge
|
||||
|
||||
# Copy application source
|
||||
COPY . /srv/webvirtcloud
|
||||
|
||||
# Setup build-time settings, run collectstatic, and set permissions
|
||||
RUN . venv/bin/activate && \
|
||||
python3 manage.py makemigrations && \
|
||||
python3 manage.py migrate && \
|
||||
if [ ! -f webvirtcloud/settings.py ]; then \
|
||||
cp webvirtcloud/settings.py.template webvirtcloud/settings.py && \
|
||||
python3 -c 'import secrets; print(secrets.token_urlsafe(50))' > /tmp/secret_key && \
|
||||
sed -i "s|^SECRET_KEY = .*|SECRET_KEY = \"$(cat /tmp/secret_key)\"|" webvirtcloud/settings.py && \
|
||||
rm -f /tmp/secret_key; \
|
||||
fi && \
|
||||
python3 manage.py collectstatic --noinput && \
|
||||
chown -R www-data:www-data /srv/webvirtcloud
|
||||
|
||||
# Setup Nginx
|
||||
RUN printf "\n%s" "daemon off;" >> /etc/nginx/nginx.conf && \
|
||||
rm /etc/nginx/sites-enabled/default && \
|
||||
rm -f /etc/nginx/sites-enabled/default && \
|
||||
chown -R www-data:www-data /var/lib/nginx
|
||||
|
||||
COPY conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/
|
||||
|
||||
# Register services to runit
|
||||
RUN mkdir /etc/service/nginx && \
|
||||
mkdir /etc/service/nginx-log-forwarder && \
|
||||
mkdir /etc/service/webvirtcloud && \
|
||||
mkdir /etc/service/novnc
|
||||
# Register startup init script and services to runit
|
||||
RUN mkdir -p /etc/my_init.d \
|
||||
/etc/service/nginx \
|
||||
/etc/service/nginx-log-forwarder \
|
||||
/etc/service/webvirtcloud \
|
||||
/etc/service/novnc
|
||||
COPY conf/runit/10_webvirtcloud_init.sh /etc/my_init.d/10_webvirtcloud_init.sh
|
||||
COPY conf/runit/nginx /etc/service/nginx/run
|
||||
COPY conf/runit/nginx-log-forwarder /etc/service/nginx-log-forwarder/run
|
||||
COPY conf/runit/novncd.sh /etc/service/novnc/run
|
||||
COPY conf/runit/webvirtcloud.sh /etc/service/webvirtcloud/run
|
||||
RUN chmod +x /etc/my_init.d/10_webvirtcloud_init.sh \
|
||||
/etc/service/nginx/run \
|
||||
/etc/service/nginx-log-forwarder/run \
|
||||
/etc/service/novnc/run \
|
||||
/etc/service/webvirtcloud/run
|
||||
|
||||
# Define mountable directories.
|
||||
#VOLUME []
|
||||
# Declare mountable data directory for persistent SQLite and SSH keys
|
||||
VOLUME ["/srv/webvirtcloud/data", "/var/www/.ssh"]
|
||||
|
||||
WORKDIR /srv/webvirtcloud
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue