blob: 703e4c0599dcaaf3626a5e7c2de7612bc10dd9cd [file] [log] [blame]
mesaj479f6fd2025-06-10 10:43:49 +02001# syntax=docker/dockerfile:1
2#######################################################################################
3# Copyright ETSI Contributors and Others.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#######################################################################################
18
19
20#######################
21# Stage 1: Base stage #
22#######################
23
24FROM python:3.10-alpine AS base
25
26ENV PYTHONUNBUFFERED=1 \
27 PYTHONDONTWRITEBYTECODE=1 \
28 PIP_DISABLE_PIP_VERSION_CHECK=1
29
30##########################################################################################################################################################################
31
32########################
33# Stage 2: Build stage #
34########################
35
36FROM base AS build
37
38ARG COMMON_GERRIT_REFSPEC=master
39ARG IM_GERRIT_REFSPEC=master
40
41# Install required system packages with pinned versions where possible
42RUN apk add --no-cache \
43 build-base \
44 patch \
45 git \
46 zlib-dev \
47 rust \
48 cargo\
49 linux-headers \
50 musl-dev \
51 curl
52
53WORKDIR /app/osm_nbi
54
55# Create virtual environment
56RUN python -m venv /app/osm_nbi/.venv
57ENV PATH="/app/osm_nbi/.venv/bin:$PATH"
58
59# Install OSM dependencies with cache optimization
mesajbdf44322025-10-20 17:21:34 +020060RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \
mesaj479f6fd2025-06-10 10:43:49 +020061 cd /tmp/osm-common && \
62 git fetch origin ${COMMON_GERRIT_REFSPEC} && \
63 git checkout FETCH_HEAD && \
64 cd - && \
65 pip install --no-cache-dir -r /tmp/osm-common/requirements.txt && \
66 pip install /tmp/osm-common
67
mesajbdf44322025-10-20 17:21:34 +020068RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \
mesaj479f6fd2025-06-10 10:43:49 +020069 cd /tmp/osm-im && \
70 git fetch origin ${IM_GERRIT_REFSPEC} && \
71 git checkout FETCH_HEAD && \
72 cd - && \
73 pip install --no-cache-dir -r /tmp/osm-im/requirements.txt && \
74 pip install /tmp/osm-im
75
76COPY requirements.txt ./
mesajbdf44322025-10-20 17:21:34 +020077RUN pip install --no-cache-dir -r requirements.txt
mesaj479f6fd2025-06-10 10:43:49 +020078
79COPY . .
mesajbdf44322025-10-20 17:21:34 +020080RUN pip install .
mesaj479f6fd2025-06-10 10:43:49 +020081
82# Clean up
83RUN find /app/osm_nbi -type d -name ".tox" -exec rm -rf {} +
84
85#############################################################################################################################################################################
86
87########################
88# Stage 3: Final stage #
89########################
90
91FROM base AS final
92
93RUN apk add --no-cache \
94 libgcc \
95 libstdc++
96
97WORKDIR /app/osm_nbi
98
99# Create appuser and directories with correct permissions
100RUN addgroup -g 1000 appuser && \
101 adduser -D -G appuser -u 1000 appuser && \
102 mkdir -p /app/storage/kafka /app/log && \
103 chown -R appuser:appuser /app
104
105USER appuser:appuser
106
107ENV VIRTUAL_ENV=/app/.venv \
108 PATH="/app/.venv/bin:$PATH"
109
110COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv /app/.venv
111COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/html_public /app/osm_nbi/html_public
112COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/nbi.cfg /app/osm_nbi/nbi.cfg
113COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/http /app/osm_nbi/http
114COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/templates /app/osm_nbi/templates
115
116EXPOSE 9999
117
118# Configuration environment variables
119ENV OSMNBI_SOCKET_HOST=0.0.0.0 \
120 OSMNBI_SOCKET_PORT=9999 \
121 OSMNBI_STORAGE_PATH=/app/storage \
122 OSMNBI_DATABASE_DRIVER=mongo \
123 OSMNBI_DATABASE_URI=mongodb://mongo:27017 \
124 OSMNBI_STATIC_DIR=/app/osm_nbi/html_public \
125 OSMNBI_MESSAGE_DRIVER=kafka \
126 OSMNBI_MESSAGE_HOST=kafka \
127 OSMNBI_MESSAGE_PORT=9092 \
128 OSMNBI_LOG_FILE=/app/log/nbi.log \
129 OSMNBI_LOG_LEVEL=DEBUG \
130 OSMNBI_AUTHENTICATION_BACKEND=internal \
131 OSMNBI_PROMETHEUS_HOST=prometheus \
132 OSMNBI_PROMETHEUS_PORT=9090
133
134HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \
135 CMD curl -k -f https://localhost:9999/osm/ || exit 1
136
137CMD ["python", "-m", "osm_nbi.nbi"]