blob: 03acd6db60c76fd399c3495264d64b88642e59fa [file] [log] [blame]
mesaj123336d2025-06-10 16:53:28 +02001#######################################################################################
2# Copyright ETSI Contributors and Others.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13# implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#######################################################################################
17
18
19########################
20# Stage 1: Build stage #
21########################
22
23FROM python:3.10-alpine AS base
24
25
26ENV PYTHONUNBUFFERED=1 \
27 PYTHONDONTWRITEBYTECODE=1 \
28 PIP_DISABLE_PIP_VERSION_CHECK=1
29
30FROM python:3.10-alpine AS builder
31
32# Install build dependencies
33RUN apk add --no-cache \
34 gcc \
35 musl-dev \
36 libffi-dev \
37 openssl-dev \
38 curl \
39 git \
40 openssh-client \
41 zlib-dev \
42 jpeg-dev \
43 libxml2-dev \
44 libxslt-dev
45
46WORKDIR /app/mon
47
48# Create virtual environment
49RUN python -m venv /app/mon/.venv
50ENV PATH="/app/mon/.venv/bin:$PATH"
51
52ARG COMMON_GERRIT_REFSPEC=master
53
54# Install OSM dependency modules with no cache
55RUN --mount=type=cache,target=/root/.cache/pip \
56 git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \
57 cd /tmp/osm-common && \
58 git fetch origin "${COMMON_GERRIT_REFSPEC}" && \
59 git checkout FETCH_HEAD &&\
60 cd - && \
61 pip install --no-cache-dir -r /tmp/osm-common/requirements.txt && \
62 pip install --no-cache-dir /tmp/osm-common
63
64# Install MON
65COPY . .
66RUN --mount=type=cache,target=/root/.cache/pip \
67 pip install --no-cache-dir -r requirements.txt \
68 && pip install --no-cache-dir .
69
70
71###########################################################################################################################################################
72
73########################
74# Stage 2: Final image #
75########################
76
77FROM python:3.10-alpine AS final
78
79# Install runtime dependencies
80RUN apk add --no-cache \
81 ca-certificates \
82 openssh-client
83
84# Copy virtual environment from build stage
85COPY --from=builder /app/mon/.venv /app/mon/.venv
86ENV PATH="/app/mon/.venv/bin:$PATH"
87
88# Copy necessary binaries and libraries
89COPY --from=builder /usr/lib/ /usr/lib/
90COPY --from=builder /lib/ /lib/
91
92# Copy application scripts
93COPY scripts/ /app/mon/scripts/
94
95# Create app user and directories
96RUN addgroup -g 1000 appuser && \
97 adduser -u 1000 -G appuser -D -h /app appuser && \
98 mkdir -p /app/mon && \
99 mkdir -p /app/storage/kafka && \
100 mkdir /app/log && \
101 chown -R appuser:appuser /app
102
103WORKDIR /app/mon
104
105USER appuser
106
107# Environment variables
108ENV OSMMON_MESSAGE_DRIVER kafka \
109 OSMMON_MESSAGE_HOST kafka \
110 OSMMON_MESSAGE_PORT 9092 \
111 OSMMON_DATABASE_DRIVER mongo \
112 OSMMON_DATABASE_URI mongodb://mongo:27017 \
113 OSMMON_SQL_DATABASE_URI sqlite:///mon_sqlite.db \
114 OSMMON_OPENSTACK_DEFAULT_GRANULARITY 300 \
115 OSMMON_GLOBAL_REQUEST_TIMEOUT 10 \
116 OSMMON_GLOBAL_LOGLEVEL INFO \
117 OSMMON_VCA_HOST localhost \
118 OSMMON_VCA_SECRET secret \
119 OSMMON_VCA_USER admin \
120 OSMMON_VCA_CACERT cacert \
121 OSMMON_DATABASE_COMMONKEY changeme \
122 OSMMON_COLLECTOR_INTERVAL 30 \
123 OSMMON_EVALUATOR_INTERVAL 30 \
124 OSMMON_PROMETHEUS_URL http://prometheus:9090 \
125 OSMMON_GRAFANA_URL http://grafana:3000 \
126 OSMMON_GRAFANA_USER admin \
127 OSMMON_GRAFANA_PASSWORD admin
128
129EXPOSE 8000
130
131HEALTHCHECK --start-period=120s --interval=5s --timeout=2s --retries=12\
132 CMD osm-mon-healthcheck || exit 1
133
134# Switch to app user
135USER appuser
136
137CMD ["/bin/sh", "scripts/dashboarder-start.sh]