| mesaj | f6eb4ff | 2025-06-10 17:21:44 +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: builder stage# |
| 34 | ######################### |
| 35 | |
| 36 | FROM base AS builder |
| 37 | |
| 38 | # Install build dependencies |
| 39 | RUN apk add --no-cache \ |
| 40 | gcc \ |
| 41 | musl-dev \ |
| 42 | libffi-dev \ |
| 43 | openssl-dev \ |
| 44 | make \ |
| 45 | cmake \ |
| 46 | build-base \ |
| 47 | patch \ |
| 48 | curl \ |
| 49 | git \ |
| 50 | bash \ |
| 51 | libmagic |
| 52 | |
| 53 | # Isolate dependencies in a venv |
| 54 | RUN python -m venv /app/osmclient/.venv |
| 55 | ENV PATH="/app/osmclient/.venv/bin:$PATH" |
| 56 | |
| 57 | # Install OSM packages (assuming they provide source packages or wheels) |
| 58 | ARG IM_GERRIT_REFSPEC=master |
| 59 | |
| caviedesj | a01a597 | 2026-01-09 11:36:28 +0100 | [diff] [blame] | 60 | RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \ |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 61 | cd /tmp/osm-im && \ |
| 62 | git fetch origin ${IM_GERRIT_REFSPEC} && \ |
| 63 | git checkout FETCH_HEAD && \ |
| 64 | cd - && \ |
| 65 | pip install --no-cache-dir -r /tmp/osm-im/requirements.txt && \ |
| 66 | pip install /tmp/osm-im |
| 67 | |
| 68 | COPY . /tmp/osmclient/ |
| caviedesj | a01a597 | 2026-01-09 11:36:28 +0100 | [diff] [blame] | 69 | RUN cd /tmp/osmclient && \ |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 70 | pip install --no-cache-dir -r /tmp/osmclient/requirements.txt && \ |
| 71 | pip install /tmp/osmclient && \ |
| 72 | cd - |
| 73 | |
| 74 | ##################################################################################################################################################### |
| 75 | |
| 76 | ####################### |
| 77 | # Stage 3: Final image# |
| 78 | ####################### |
| 79 | |
| 80 | FROM python:3.10-alpine AS final |
| 81 | |
| 82 | # Install runtime dependencies |
| 83 | RUN apk add --no-cache \ |
| 84 | bash \ |
| 85 | libmagic |
| 86 | |
| garciadeblas | f0aac8c | 2026-01-19 14:41:12 +0100 | [diff] [blame] | 87 | # Create app user |
| 88 | RUN addgroup -g 1000 appuser && \ |
| 89 | adduser -u 1000 -G appuser -D appuser && \ |
| 90 | mkdir -p /app/osmclient && \ |
| 91 | chown -R appuser:appuser /app |
| 92 | |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 93 | ENV VIRTUAL_ENV=/app/osmclient/.venv \ |
| 94 | PATH="/app/osmclient/.venv/bin:$PATH" |
| 95 | |
| 96 | # Copy Python packages from build stage |
| 97 | COPY --from=builder --chown=appuser:appuser /app/osmclient/.venv /app/osmclient/.venv |
| 98 | |
| 99 | # Copy OSM binaries |
| garciadeblas | f0aac8c | 2026-01-19 14:41:12 +0100 | [diff] [blame] | 100 | # COPY --from=builder /app/osmclient/.venv/bin/osm /usr/local/bin/osm |
| garciadeblas | 64e1a8e | 2025-11-27 17:47:18 +0100 | [diff] [blame] | 101 | COPY scripts/charm.sh /usr/sbin/charm |
| 102 | |
| 103 | # Add additional client tools |
| 104 | COPY scripts/install-client-tools.sh /tmp/install-client-tools.sh |
| 105 | RUN bash /tmp/install-client-tools.sh |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 106 | |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 107 | WORKDIR /app/osmclient |
| 108 | |
| 109 | # Set environment variables |
| 110 | ENV LC_ALL=C.UTF-8i \ |
| 111 | LANG=C.UTF-8 \ |
| 112 | OSM_HOSTNAME=nbi:9999 \ |
| 113 | OSM_USER=admin \ |
| 114 | OSM_PASSWORD=admin \ |
| 115 | OSM_PROJECT=admin |
| 116 | |
| 117 | # Switch to non-root user |
| garciadeblas | f0aac8c | 2026-01-19 14:41:12 +0100 | [diff] [blame] | 118 | USER appuser:appuser |
| mesaj | f6eb4ff | 2025-06-10 17:21:44 +0200 | [diff] [blame] | 119 | |
| garciadeblas | f0aac8c | 2026-01-19 14:41:12 +0100 | [diff] [blame] | 120 | # CMD ["/usr/local/bin/osm"] |
| 121 | CMD ["osm"] |