File size: 3,234 Bytes
d721bf1
 
 
 
 
 
 
 
 
 
 
 
2a2521b
9e1edfd
2b68a06
08c36f0
c9732a0
d721bf1
 
 
 
 
 
 
 
4a68c15
339b6cd
4a68c15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bd4abe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4a68c15
d721bf1
 
 
2a2521b
 
 
 
d721bf1
 
 
 
2a2521b
 
 
55a805d
 
7af74d7
2a2521b
 
 
 
d721bf1
7af74d7
d721bf1
 
 
 
 
 
 
 
7af74d7
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
FROM python:3.10-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_NO_CACHE_DIR=off \
    PIP_DISABLE_PIP_VERSION_CHECK=on \
    PIP_DEFAULT_TIMEOUT=100

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    dos2unix \
    nginx \
    procps \
    curl \
    prometheus \
    && rm -rf /var/lib/apt/lists/*

# Create a non-root user
RUN useradd -m -u 1000 user

# Set working directory
WORKDIR /app

# Grafana
RUN apt-get update && apt-get install -y wget apt-transport-https && \
    wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key && \
    echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | tee /etc/apt/sources.list.d/grafana.list && \
    apt-get update && \
    apt-get install -y grafana && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Prometheus
RUN wget https://github.com/prometheus/prometheus/releases/download/v2.45.0/prometheus-2.45.0.linux-amd64.tar.gz && \
    tar xvfz prometheus-*.tar.gz && \
    mv prometheus-*/prometheus /usr/local/bin/ && \
    mv prometheus-*/promtool /usr/local/bin/ && \
    mkdir -p /etc/prometheus /var/lib/prometheus && \
    rm -rf prometheus-*

# Alertmanager
RUN wget https://github.com/prometheus/alertmanager/releases/download/v0.25.0/alertmanager-0.25.0.linux-amd64.tar.gz && \
    tar xvfz alertmanager-*.tar.gz && \
    mv alertmanager-*/alertmanager /usr/local/bin/ && \
    mv alertmanager-*/amtool /usr/local/bin/ && \
    mkdir -p /etc/alertmanager /var/lib/alertmanager && \
    rm -rf alertmanager-*

# Pushgateway
RUN wget https://github.com/prometheus/pushgateway/releases/download/v1.6.0/pushgateway-1.6.0.linux-amd64.tar.gz && \
    tar xvfz pushgateway-*.tar.gz && \
    mv pushgateway-*/pushgateway /usr/local/bin/ && \
    rm -rf pushgateway-*

COPY --chown=user monitoring/grafana/provisioning /etc/grafana/provisioning
COPY --chown=user monitoring/grafana/dashboards /var/lib/grafana/dashboards
COPY --chown=user monitoring/prometheus/prometheus.yml /etc/prometheus/prometheus.yml
COPY --chown=user monitoring/prometheus/alert_rules.yml /etc/prometheus/alert_rules.yml
COPY --chown=user monitoring/alertmanager/config.yml /etc/alertmanager/config.yml


# Copy requirements first for caching
COPY requirements.txt .

# Remove -e . from requirements.txt to avoid installing the project before copying it
# and install dependencies
RUN sed -i '/-e \./d' requirements.txt && \
    pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY --chown=user:user . .

# Ensure the user has permissions on the app directory (needed for dvc init if .dvc is missing)
RUN chown -R user:user /app

# Fix line endings and permissions for the start script and configs
RUN find . -name "*.sh" -o -name "*.yml" -o -name "*.ini" -o -name "*.json" | xargs dos2unix && \
    chmod +x docker/scripts/start_space.sh

# Install the project itself
RUN pip install --no-cache-dir .

# Make start script executable
RUN chmod +x docker/scripts/start_space.sh

# Switch to non-root user
USER user

# Expose the port
EXPOSE 7860

# Command to run the application
CMD ["./docker/scripts/start_space.sh"]