| mesaj | fbd8f49 | 2025-06-10 17:08:07 +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 | # RUN apk add --no-cache \ |
| 27 | # libgcc \ |
| 28 | # libstdc++ |
| 29 | |
| 30 | ENV PYTHONUNBUFFERED=1 \ |
| 31 | PYTHONDONTWRITEBYTECODE=1 \ |
| 32 | PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 33 | |
| 34 | |
| 35 | ######################################################################################################################################################################### |
| 36 | |
| 37 | ######################## |
| 38 | # Stage 2: Build Stage # |
| 39 | ######################## |
| 40 | |
| 41 | FROM base AS build |
| 42 | |
| 43 | # Install required system packages |
| 44 | RUN apk add --no-cache \ |
| 45 | build-base \ |
| 46 | git \ |
| 47 | patch \ |
| 48 | curl \ |
| 49 | zlib-dev \ |
| 50 | cdrkit \ |
| 51 | linux-headers \ |
| 52 | openssl \ |
| 53 | openssl-dev \ |
| 54 | libffi-dev \ |
| 55 | libmagic \ |
| 56 | cargo \ |
| 57 | rust \ |
| 58 | musl-dev \ |
| 59 | bash \ |
| 60 | openssh-client |
| 61 | |
| 62 | # Verify git installation |
| 63 | RUN git --version |
| 64 | |
| 65 | WORKDIR /app/ro |
| 66 | |
| 67 | # Isolate dependencies in a venv |
| 68 | RUN python -m venv /app/ro/.venv |
| 69 | ENV PATH="/app/ro/.venv/bin:$PATH" |
| 70 | |
| 71 | ARG COMMON_GERRIT_REFSPEC=master |
| 72 | ARG IM_GERRIT_REFSPEC=master |
| 73 | |
| 74 | # Install build tools |
| 75 | RUN pip install -U pip setuptools wheel build |
| 76 | |
| 77 | RUN test -x /app/ro/.venv/bin/python && /app/ro/.venv/bin/python -c "import sys; print(sys.prefix)" |
| 78 | |
| 79 | # Install OSM dependency modules |
| 80 | |
| 81 | RUN --mount=type=cache,target=/root/.cache/pip \ |
| 82 | git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \ |
| 83 | cd /tmp/osm-common && \ |
| 84 | git fetch origin ${COMMON_GERRIT_REFSPEC} && \ |
| 85 | git checkout FETCH_HEAD && \ |
| 86 | cd - && \ |
| 87 | pip install -r /tmp/osm-common/requirements.txt && \ |
| 88 | pip install /tmp/osm-common |
| 89 | |
| 90 | COPY requirements.txt ./ |
| 91 | |
| 92 | # Install py-radix from source with a one-line patch (no build isolation) |
| 93 | RUN --mount=type=cache,target=/root/.cache/pip \ |
| 94 | # py-radix is installed as dependency of the ipconflict package |
| 95 | # the installation is a bit special as it is not fully compatible with Alpine library versions |
| 96 | # similar issue reported here: https://github.com/mjschultz/py-radix/issues/70 |
| 97 | git clone --filter=blob:none https://github.com/mjschultz/py-radix.git /tmp/py-radix && \ |
| 98 | sed -i 's/from setuptools\.dist import Version/from packaging.version import Version/' /tmp/py-radix/setup.py && \ |
| 99 | pip install --no-build-isolation /tmp/py-radix && \ |
| 100 | pip install -r requirements.txt |
| 101 | |
| 102 | RUN --mount=type=cache,target=/root/.cache/pip \ |
| 103 | pip install git+https://github.com/mjschultz/py-radix.git && \ |
| 104 | pip install -r requirements.txt |
| 105 | |
| 106 | COPY . . |
| 107 | |
| 108 | RUN for component in common RO-plugin NG-RO RO-VIM-* RO-SDN-*; do \ |
| 109 | if [ -d "$component" ]; then \ |
| 110 | python -m build $component && \ |
| 111 | pip install $component/dist/*.whl; \ |
| 112 | fi; \ |
| 113 | done |
| 114 | |
| 115 | |
| 116 | ################################################################################################################################################################ |
| 117 | |
| 118 | ######################## |
| 119 | # Stage 3: Final Stage # |
| 120 | ######################## |
| 121 | |
| 122 | FROM base AS final |
| 123 | WORKDIR /app |
| 124 | |
| 125 | RUN apk add --no-cache \ |
| 126 | cdrkit \ |
| 127 | git \ |
| 128 | curl \ |
| 129 | libmagic \ |
| 130 | bash |
| 131 | |
| 132 | RUN addgroup -g 1000 appuser && \ |
| 133 | adduser -D -G appuser -u 1000 appuser -h /app appuser && \ |
| 134 | mkdir -p /app/storage/kafka && \ |
| 135 | mkdir -p /app/log && \ |
| 136 | chown -R appuser:appuser /app |
| 137 | |
| 138 | USER appuser:appuser |
| 139 | |
| 140 | ENV VIRTUAL_ENV=/app/.venv \ |
| 141 | PATH="/app/.venv/bin:$PATH" |
| 142 | |
| 143 | COPY --from=build --chown=appuser:appuser /app/ro/ /app/ |
| 144 | |
| 145 | EXPOSE 9090 |
| 146 | |
| 147 | # Database configuration |
| 148 | ENV RO_DB_HOST="" \ |
| 149 | RO_DB_OVIM_HOST="" \ |
| 150 | RO_DB_ROOT_PASSWORD="" \ |
| 151 | RO_DB_OVIM_ROOT_PASSWORD="" \ |
| 152 | RO_DB_USER=mano \ |
| 153 | RO_DB_OVIM_USER=mano \ |
| 154 | RO_DB_PASSWORD=manopw \ |
| 155 | RO_DB_OVIM_PASSWORD=manopw \ |
| 156 | RO_DB_PORT=3306 \ |
| 157 | RO_DB_OVIM_PORT=3306 \ |
| 158 | RO_DB_NAME=mano_db \ |
| 159 | RO_DB_OVIM_NAME=mano_vim_db \ |
| 160 | OPENMANO_TENANT=osm |
| 161 | |
| 162 | # Application configuration |
| 163 | ENV OSMRO_DATABASE_DRIVER=mongo \ |
| 164 | OSMRO_DATABASE_URI=mongodb://mongo:27017 \ |
| 165 | OSMRO_MESSAGE_DRIVER=kafka \ |
| 166 | OSMRO_MESSAGE_HOST=kafka \ |
| 167 | OSMRO_MESSAGE_PORT=9092 \ |
| 168 | OSMRO_LOG_LEVEL=INFO |
| 169 | |
| 170 | # Expose ports and volumes |
| 171 | VOLUME /var/log/osm |
| 172 | |
| 173 | # Set user and entrypoint |
| 174 | USER appuser |
| 175 | CMD ["python", "-u", "-m", "osm_ng_ro.ro_main"] |
| 176 | |