forked from kaaass/fava-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
59 lines (45 loc) · 1.57 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Stage 1: Build stage
FROM python:3.12.4-alpine as builder
# Set environment variables
ENV BEANCOUNT_FILE /bean/main.bean
ENV APP_MODULE management.wsgi
# Install build dependencies
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories & \
apk update && \
apk add --no-cache --virtual .build-deps \
gcc \
libc-dev \
libxml2-dev \
libxslt-dev
# Set work directory
WORKDIR /app
# Copy requirements and install dependencies in a virtual environment
COPY requirements.txt .
RUN python3 -m venv venv && \
. venv/bin/activate && \
pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# Stage 2: Final stage
FROM python:3.12.4-alpine
# Set environment variables
ENV BEANCOUNT_FILE /bean/main.bean
ENV APP_MODULE management.wsgi
ENV USERNAME admin
ENV PASSWORD 123456
ENV CSRF_TRUSTED_ORIGINS 'http://localhost,http://127.0.0.1'
# Set work directory
WORKDIR /app
# Copy virtual environment from builder image
COPY --from=builder /app/venv ./venv
# Copy application files
COPY . .
# Copy prestart script
COPY docker/prestart.sh ./prestart.sh
# Ensure scripts are executable
RUN chmod +x ./prestart.sh
# Collect static files and update settings
RUN . venv/bin/activate && yes | python manage.py collectstatic && \
sed -i 's/DEBUG = True/DEBUG = False/g' management/settings.py
# Expose the port (if needed)
EXPOSE 8000
# Define the default command
CMD ["sh", "-c", "source /app/venv/bin/activate && ./prestart.sh && /app/venv/bin/python manage.py runserver 0.0.0.0:8000"]