blob: fac57c4715894b9ffa34ab0904b57f67bb736bbb [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
60RUN --mount=type=cache,target=/root/.cache/pip \
61 git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \
62 cd /tmp/osm-common && \
63 git fetch origin ${COMMON_GERRIT_REFSPEC} && \
64 git checkout FETCH_HEAD && \
65 cd - && \
66 pip install --no-cache-dir -r /tmp/osm-common/requirements.txt && \
67 pip install /tmp/osm-common
68
69RUN --mount=type=cache,target=/root/.cache/pip \
70 git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \
71 cd /tmp/osm-im && \
72 git fetch origin ${IM_GERRIT_REFSPEC} && \
73 git checkout FETCH_HEAD && \
74 cd - && \
75 pip install --no-cache-dir -r /tmp/osm-im/requirements.txt && \
76 pip install /tmp/osm-im
77
78COPY requirements.txt ./
79RUN --mount=type=cache,target=/root/.cache/pip \
80 pip install --no-cache-dir -r requirements.txt
81
82COPY . .
83RUN --mount=type=cache,target=/root/.cache/pip \
84 pip install .
85
86# Clean up
87RUN find /app/osm_nbi -type d -name ".tox" -exec rm -rf {} +
88
89#############################################################################################################################################################################
90
91########################
92# Stage 3: Final stage #
93########################
94
95FROM base AS final
96
97RUN apk add --no-cache \
98 libgcc \
99 libstdc++
100
101WORKDIR /app/osm_nbi
102
103# Create appuser and directories with correct permissions
104RUN addgroup -g 1000 appuser && \
105 adduser -D -G appuser -u 1000 appuser && \
106 mkdir -p /app/storage/kafka /app/log && \
107 chown -R appuser:appuser /app
108
109USER appuser:appuser
110
111ENV VIRTUAL_ENV=/app/.venv \
112 PATH="/app/.venv/bin:$PATH"
113
114COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv /app/.venv
115COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/html_public /app/osm_nbi/html_public
116COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/nbi.cfg /app/osm_nbi/nbi.cfg
117COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/http /app/osm_nbi/http
118COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/templates /app/osm_nbi/templates
119
120EXPOSE 9999
121
122# Configuration environment variables
123ENV OSMNBI_SOCKET_HOST=0.0.0.0 \
124 OSMNBI_SOCKET_PORT=9999 \
125 OSMNBI_STORAGE_PATH=/app/storage \
126 OSMNBI_DATABASE_DRIVER=mongo \
127 OSMNBI_DATABASE_URI=mongodb://mongo:27017 \
128 OSMNBI_STATIC_DIR=/app/osm_nbi/html_public \
129 OSMNBI_MESSAGE_DRIVER=kafka \
130 OSMNBI_MESSAGE_HOST=kafka \
131 OSMNBI_MESSAGE_PORT=9092 \
132 OSMNBI_LOG_FILE=/app/log/nbi.log \
133 OSMNBI_LOG_LEVEL=DEBUG \
134 OSMNBI_AUTHENTICATION_BACKEND=internal \
135 OSMNBI_PROMETHEUS_HOST=prometheus \
136 OSMNBI_PROMETHEUS_PORT=9090
137
138HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \
139 CMD curl -k -f https://localhost:9999/osm/ || exit 1
140
141CMD ["python", "-m", "osm_nbi.nbi"]