blob: 748ec71f80e8d9d96bdf8f70ec5dc72ef0046d20 [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
garciadeblasb1a3f9f2025-12-26 11:28:20 +010046WORKDIR /app
mesaj123336d2025-06-10 16:53:28 +020047
48# Create virtual environment
garciadeblasb1a3f9f2025-12-26 11:28:20 +010049RUN python -m venv /app/.venv
50ENV PATH="/app/.venv/bin:$PATH"
mesaj123336d2025-06-10 16:53:28 +020051
52ARG COMMON_GERRIT_REFSPEC=master
53
54# Install OSM dependency modules with no cache
garciadeblasb1a3f9f2025-12-26 11:28:20 +010055RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \
mesaj123336d2025-06-10 16:53:28 +020056 cd /tmp/osm-common && \
57 git fetch origin "${COMMON_GERRIT_REFSPEC}" && \
58 git checkout FETCH_HEAD &&\
59 cd - && \
60 pip install --no-cache-dir -r /tmp/osm-common/requirements.txt && \
61 pip install --no-cache-dir /tmp/osm-common
62
63# Install MON
64COPY . .
garciadeblasb1a3f9f2025-12-26 11:28:20 +010065RUN pip install --no-cache-dir -r requirements.txt \
mesaj123336d2025-06-10 16:53:28 +020066 && pip install --no-cache-dir .
67
68
69###########################################################################################################################################################
70
71########################
72# Stage 2: Final image #
73########################
74
75FROM python:3.10-alpine AS final
76
77# Install runtime dependencies
78RUN apk add --no-cache \
79 ca-certificates \
80 openssh-client
81
82# Copy virtual environment from build stage
garciadeblasb1a3f9f2025-12-26 11:28:20 +010083COPY --from=builder /app/.venv /app/.venv
84ENV PATH="/app/.venv/bin:$PATH"
mesaj123336d2025-06-10 16:53:28 +020085
86# Copy necessary binaries and libraries
87COPY --from=builder /usr/lib/ /usr/lib/
88COPY --from=builder /lib/ /lib/
89
90# Copy application scripts
garciadeblasb1a3f9f2025-12-26 11:28:20 +010091COPY scripts/ /app/scripts/
mesaj123336d2025-06-10 16:53:28 +020092
93# Create app user and directories
94RUN addgroup -g 1000 appuser && \
95 adduser -u 1000 -G appuser -D -h /app appuser && \
mesaj123336d2025-06-10 16:53:28 +020096 mkdir -p /app/storage/kafka && \
97 mkdir /app/log && \
98 chown -R appuser:appuser /app
99
garciadeblasb1a3f9f2025-12-26 11:28:20 +0100100WORKDIR /app
mesaj123336d2025-06-10 16:53:28 +0200101
102USER appuser
103
104# Environment variables
105ENV OSMMON_MESSAGE_DRIVER kafka \
106 OSMMON_MESSAGE_HOST kafka \
107 OSMMON_MESSAGE_PORT 9092 \
108 OSMMON_DATABASE_DRIVER mongo \
109 OSMMON_DATABASE_URI mongodb://mongo:27017 \
110 OSMMON_SQL_DATABASE_URI sqlite:///mon_sqlite.db \
111 OSMMON_OPENSTACK_DEFAULT_GRANULARITY 300 \
112 OSMMON_GLOBAL_REQUEST_TIMEOUT 10 \
113 OSMMON_GLOBAL_LOGLEVEL INFO \
114 OSMMON_VCA_HOST localhost \
115 OSMMON_VCA_SECRET secret \
116 OSMMON_VCA_USER admin \
117 OSMMON_VCA_CACERT cacert \
118 OSMMON_DATABASE_COMMONKEY changeme \
119 OSMMON_COLLECTOR_INTERVAL 30 \
120 OSMMON_EVALUATOR_INTERVAL 30 \
121 OSMMON_PROMETHEUS_URL http://prometheus:9090 \
122 OSMMON_GRAFANA_URL http://grafana:3000 \
123 OSMMON_GRAFANA_USER admin \
124 OSMMON_GRAFANA_PASSWORD admin
125
126EXPOSE 8000
127
128HEALTHCHECK --start-period=120s --interval=5s --timeout=2s --retries=12\
129 CMD osm-mon-healthcheck || exit 1
130
131# Switch to app user
132USER appuser
133
134CMD ["/bin/sh", "scripts/dashboarder-start.sh]