| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 1 | ####################################################################################### |
| 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 | |
| 23 | FROM python:3.10-alpine AS base |
| 24 | |
| 25 | |
| 26 | ENV PYTHONUNBUFFERED=1 \ |
| 27 | PYTHONDONTWRITEBYTECODE=1 \ |
| 28 | PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 29 | |
| 30 | FROM python:3.10-alpine AS builder |
| 31 | |
| 32 | # Install build dependencies |
| 33 | RUN 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 | |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 46 | WORKDIR /app |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 47 | |
| 48 | # Create virtual environment |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 49 | RUN python -m venv /app/.venv |
| 50 | ENV PATH="/app/.venv/bin:$PATH" |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 51 | |
| 52 | ARG COMMON_GERRIT_REFSPEC=master |
| 53 | |
| 54 | # Install OSM dependency modules with no cache |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 55 | RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \ |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 56 | 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 |
| 64 | COPY . . |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 65 | RUN pip install --no-cache-dir -r requirements.txt \ |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 66 | && pip install --no-cache-dir . |
| 67 | |
| 68 | |
| 69 | ########################################################################################################################################################### |
| 70 | |
| 71 | ######################## |
| 72 | # Stage 2: Final image # |
| 73 | ######################## |
| 74 | |
| 75 | FROM python:3.10-alpine AS final |
| 76 | |
| 77 | # Install runtime dependencies |
| 78 | RUN apk add --no-cache \ |
| 79 | ca-certificates \ |
| 80 | openssh-client |
| 81 | |
| 82 | # Copy virtual environment from build stage |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 83 | COPY --from=builder /app/.venv /app/.venv |
| 84 | ENV PATH="/app/.venv/bin:$PATH" |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 85 | |
| 86 | # Copy necessary binaries and libraries |
| 87 | COPY --from=builder /usr/lib/ /usr/lib/ |
| 88 | COPY --from=builder /lib/ /lib/ |
| 89 | |
| 90 | # Copy application scripts |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 91 | COPY scripts/ /app/scripts/ |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 92 | |
| 93 | # Create app user and directories |
| 94 | RUN addgroup -g 1000 appuser && \ |
| 95 | adduser -u 1000 -G appuser -D -h /app appuser && \ |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 96 | mkdir -p /app/storage/kafka && \ |
| 97 | mkdir /app/log && \ |
| 98 | chown -R appuser:appuser /app |
| 99 | |
| garciadeblas | b1a3f9f | 2025-12-26 11:28:20 +0100 | [diff] [blame] | 100 | WORKDIR /app |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 101 | |
| 102 | USER appuser |
| 103 | |
| 104 | # Environment variables |
| garciadeblas | 17f7d9b | 2026-01-27 18:00:00 +0100 | [diff] [blame] | 105 | ENV 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 |
| mesaj | 123336d | 2025-06-10 16:53:28 +0200 | [diff] [blame] | 125 | |
| 126 | EXPOSE 8000 |
| 127 | |
| 128 | HEALTHCHECK --start-period=120s --interval=5s --timeout=2s --retries=12\ |
| 129 | CMD osm-mon-healthcheck || exit 1 |
| 130 | |
| 131 | # Switch to app user |
| 132 | USER appuser |
| 133 | |
| caviedesj | 649adbd | 2026-01-08 18:41:46 +0100 | [diff] [blame] | 134 | CMD ["/bin/sh", "scripts/dashboarder-start.sh"] |