| mesaj | 356f494 | 2025-06-10 16:41:13 +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 | ######################## |
| 34 | # Stage 2: Build Stage # |
| 35 | ######################## |
| 36 | |
| 37 | FROM base AS build |
| 38 | |
| 39 | ENV HELM_VERSION="3.15.1" |
| 40 | |
| 41 | # Install required system packages with pinned versions |
| 42 | RUN apk add --no-cache \ |
| 43 | build-base \ |
| 44 | patch \ |
| 45 | gcc \ |
| 46 | git \ |
| 47 | zlib-dev \ |
| 48 | curl \ |
| 49 | linux-headers \ |
| 50 | openssh-client \ |
| 51 | openssh-keygen \ |
| 52 | openssl \ |
| 53 | musl-dev \ |
| 54 | bash |
| 55 | |
| 56 | # Install kubectl with version pinning |
| 57 | RUN curl -LO "https://dl.k8s.io/release/v1.30.13/bin/linux/amd64/kubectl" \ |
| 58 | && chmod +x kubectl \ |
| 59 | && mv kubectl /usr/local/bin/ |
| 60 | |
| 61 | RUN curl -sSL "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz" -o helm-v${HELM_VERSION}.tar.gz \ |
| 62 | && tar -zxvf helm-v${HELM_VERSION}.tar.gz \ |
| 63 | && mv linux-amd64/helm /usr/local/bin/helm3 \ |
| 64 | && rm -rf linux-amd64 helm-v${HELM_VERSION}.tar.gz |
| garciadeblas | 751eec6 | 2025-12-26 11:49:01 +0100 | [diff] [blame] | 65 | WORKDIR /app |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 66 | |
| 67 | # Isolate dependencies in a venv |
| garciadeblas | 751eec6 | 2025-12-26 11:49:01 +0100 | [diff] [blame] | 68 | RUN python -m venv /app/.venv |
| 69 | ENV PATH="/app/.venv/bin:$PATH" |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 70 | ARG COMMON_GERRIT_REFSPEC=master |
| 71 | |
| 72 | # Install OSM dependency modules with no cache |
| 73 | RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common \ |
| 74 | && cd /tmp/osm-common \ |
| 75 | && git fetch origin "${COMMON_GERRIT_REFSPEC}" \ |
| 76 | && git checkout FETCH_HEAD \ |
| 77 | && cd - \ |
| 78 | && pip install --no-cache-dir -r /tmp/osm-common/requirements.txt \ |
| 79 | && pip install --no-cache-dir /tmp/osm-common \ |
| 80 | && rm -rf /tmp/osm-common |
| 81 | |
| 82 | COPY requirements.txt ./ |
| 83 | RUN pip install --no-cache-dir -r requirements.txt |
| 84 | |
| 85 | COPY . . |
| 86 | RUN pip install --no-cache-dir . |
| 87 | |
| garciadeblas | 751eec6 | 2025-12-26 11:49:01 +0100 | [diff] [blame] | 88 | RUN find /app -type d -name ".tox" -exec rm -rf {} + |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 89 | |
| 90 | |
| 91 | ######################################################################################################################################################################### |
| 92 | |
| 93 | ####################### |
| 94 | # Stage 3: Final Stage# |
| 95 | ####################### |
| 96 | |
| 97 | FROM base AS final |
| 98 | WORKDIR /app |
| 99 | |
| 100 | # Install runtime dependencies with pinned versions |
| 101 | RUN apk add --no-cache \ |
| 102 | bash \ |
| 103 | curl \ |
| garciadeblas | 61a4c69 | 2025-07-17 13:04:13 +0200 | [diff] [blame] | 104 | git \ |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 105 | openssh-client \ |
| 106 | openssh-keygen \ |
| 107 | openssl |
| 108 | |
| 109 | COPY --from=build /usr/local/bin/helm3 /usr/local/bin/helm3 |
| 110 | COPY --from=build /usr/local/bin/kubectl /usr/bin/kubectl |
| 111 | |
| 112 | RUN addgroup -g 1000 appuser \ |
| 113 | && adduser -D -G appuser -u 1000 appuser -h /app appuser \ |
| 114 | && mkdir -p /app/storage/kafka \ |
| 115 | && mkdir -p /app/log \ |
| 116 | && chown -R appuser:appuser /app |
| 117 | |
| 118 | USER appuser:appuser |
| 119 | |
| 120 | ENV VIRTUAL_ENV=/app/.venv \ |
| 121 | PATH="/app/.venv/bin:$PATH" |
| 122 | |
| garciadeblas | 751eec6 | 2025-12-26 11:49:01 +0100 | [diff] [blame] | 123 | COPY --from=build --chown=appuser:appuser /app/.venv /app/.venv |
| 124 | COPY --from=build --chown=appuser:appuser /app/osm_lcm/n2vc/post-renderer-scripts/ /app/osm_lcm/n2vc/post-renderer-scripts/ |
| 125 | COPY --from=build --chown=appuser:appuser /app/scripts/ /app/scripts/ |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 126 | |
| 127 | EXPOSE 9090 |
| 128 | |
| 129 | # Environment variables |
| 130 | ENV OSMLCM_RO_HOST=ro \ |
| 131 | OSMLCM_RO_PORT=9090 \ |
| 132 | OSMLCM_RO_TENANT=osm \ |
| 133 | OSMLCM_VCA_HOST=vca \ |
| 134 | OSMLCM_VCA_PORT=17070 \ |
| 135 | OSMLCM_VCA_USER=admin \ |
| mesaj | 356f494 | 2025-06-10 16:41:13 +0200 | [diff] [blame] | 136 | OSMLCM_VCA_CLOUD=localhost \ |
| 137 | OSMLCM_VCA_HELMPATH=/usr/local/bin/helm3 \ |
| 138 | OSMLCM_VCA_KUBECTLPATH=/usr/bin/kubectl \ |
| 139 | OSMLCM_VCA_JUJUPATH=/usr/local/bin/juju \ |
| 140 | OSMLCM_DATABASE_DRIVER=mongo \ |
| 141 | OSMLCM_DATABASE_URI="mongodb://mongo:27017" \ |
| 142 | OSMLCM_STORAGE_DRIVER=local \ |
| 143 | OSMLCM_STORAGE_PATH=/app/storage \ |
| 144 | OSMLCM_MESSAGE_DRIVER=kafka \ |
| 145 | OSMLCM_MESSAGE_HOST=kafka \ |
| 146 | OSMLCM_MESSAGE_PORT=9092 \ |
| 147 | OSMLCM_GLOBAL_LOGLEVEL=DEBUG \ |
| 148 | OSMLCM_MAINPOSTRENDERERPATH=/app/osm_lcm/n2vc/post-renderer-scripts/mainPostRenderer/mainPostRenderer \ |
| 149 | OSMLCM_PODLABELSPOSTRENDERERPATH=/app/osm_lcm/n2vc/post-renderer-scripts/podLabels/podLabels \ |
| 150 | OSMLCM_NODESELECTORPOSTRENDERERPATH=/app/osm_lcm/n2vc/post-renderer-scripts/nodeSelector/nodeSelector \ |
| 151 | OSMLCM_VCA_STABLEREPOURL=https://charts.helm.sh/stable |
| 152 | |
| 153 | HEALTHCHECK --start-period=120s --interval=30s --timeout=30s --retries=3 \ |
| 154 | CMD python3 -m osm_lcm.lcm_hc || exit 1 |
| 155 | |
| 156 | # Use JSON notation for CMD |
| 157 | CMD ["python3", "-m", "osm_lcm.lcm"] |
| 158 | |