| mesaj | 479f6fd | 2025-06-10 10:43:49 +0200 | [diff] [blame] | 1 | # 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 | |
| 24 | FROM python:3.10-alpine AS base |
| 25 | |
| 26 | ENV PYTHONUNBUFFERED=1 \ |
| 27 | PYTHONDONTWRITEBYTECODE=1 \ |
| 28 | PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 29 | |
| 30 | ########################################################################################################################################################################## |
| 31 | |
| 32 | ######################## |
| 33 | # Stage 2: Build stage # |
| 34 | ######################## |
| 35 | |
| 36 | FROM base AS build |
| 37 | |
| 38 | ARG COMMON_GERRIT_REFSPEC=master |
| 39 | ARG IM_GERRIT_REFSPEC=master |
| 40 | |
| 41 | # Install required system packages with pinned versions where possible |
| 42 | RUN 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 | |
| 53 | WORKDIR /app/osm_nbi |
| 54 | |
| 55 | # Create virtual environment |
| 56 | RUN python -m venv /app/osm_nbi/.venv |
| 57 | ENV PATH="/app/osm_nbi/.venv/bin:$PATH" |
| 58 | |
| 59 | # Install OSM dependencies with cache optimization |
| mesaj | bdf4432 | 2025-10-20 17:21:34 +0200 | [diff] [blame] | 60 | RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \ |
| mesaj | 479f6fd | 2025-06-10 10:43:49 +0200 | [diff] [blame] | 61 | 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 | |
| mesaj | bdf4432 | 2025-10-20 17:21:34 +0200 | [diff] [blame] | 68 | RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \ |
| mesaj | 479f6fd | 2025-06-10 10:43:49 +0200 | [diff] [blame] | 69 | 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 | |
| 76 | COPY requirements.txt ./ |
| mesaj | bdf4432 | 2025-10-20 17:21:34 +0200 | [diff] [blame] | 77 | RUN pip install --no-cache-dir -r requirements.txt |
| mesaj | 479f6fd | 2025-06-10 10:43:49 +0200 | [diff] [blame] | 78 | |
| 79 | COPY . . |
| mesaj | bdf4432 | 2025-10-20 17:21:34 +0200 | [diff] [blame] | 80 | RUN pip install . |
| mesaj | 479f6fd | 2025-06-10 10:43:49 +0200 | [diff] [blame] | 81 | |
| 82 | # Clean up |
| 83 | RUN find /app/osm_nbi -type d -name ".tox" -exec rm -rf {} + |
| 84 | |
| 85 | ############################################################################################################################################################################# |
| 86 | |
| 87 | ######################## |
| 88 | # Stage 3: Final stage # |
| 89 | ######################## |
| 90 | |
| 91 | FROM base AS final |
| 92 | |
| 93 | RUN apk add --no-cache \ |
| 94 | libgcc \ |
| 95 | libstdc++ |
| 96 | |
| 97 | WORKDIR /app/osm_nbi |
| 98 | |
| 99 | # Create appuser and directories with correct permissions |
| 100 | RUN 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 | |
| 105 | USER appuser:appuser |
| 106 | |
| 107 | ENV VIRTUAL_ENV=/app/.venv \ |
| 108 | PATH="/app/.venv/bin:$PATH" |
| 109 | |
| 110 | COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv /app/.venv |
| 111 | COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/html_public /app/osm_nbi/html_public |
| 112 | COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/nbi.cfg /app/osm_nbi/nbi.cfg |
| 113 | COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/http /app/osm_nbi/http |
| 114 | COPY --from=build --chown=appuser:appuser /app/osm_nbi/.venv/lib/python3.10/site-packages/osm_nbi/templates /app/osm_nbi/templates |
| 115 | |
| 116 | EXPOSE 9999 |
| 117 | |
| 118 | # Configuration environment variables |
| 119 | ENV 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 | |
| 134 | HEALTHCHECK --start-period=120s --interval=10s --timeout=5s --retries=5 \ |
| 135 | CMD curl -k -f https://localhost:9999/osm/ || exit 1 |
| 136 | |
| 137 | CMD ["python", "-m", "osm_nbi.nbi"] |