blob: 515052480e56f03e4c099ae0f8d9ef3ff4e260d9 [file] [log] [blame]
mesajf6eb4ff2025-06-10 17:21:44 +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: builder stage#
34#########################
35
36FROM base AS builder
37
38# Install build dependencies
39RUN 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
54RUN python -m venv /app/osmclient/.venv
55ENV PATH="/app/osmclient/.venv/bin:$PATH"
56
57# Install OSM packages (assuming they provide source packages or wheels)
58ARG IM_GERRIT_REFSPEC=master
59
caviedesja01a5972026-01-09 11:36:28 +010060RUN git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \
mesajf6eb4ff2025-06-10 17:21:44 +020061 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
68COPY . /tmp/osmclient/
caviedesja01a5972026-01-09 11:36:28 +010069RUN cd /tmp/osmclient && \
mesajf6eb4ff2025-06-10 17:21:44 +020070 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
80FROM python:3.10-alpine AS final
81
82# Install runtime dependencies
83RUN apk add --no-cache \
84 bash \
85 libmagic
86
garciadeblasf0aac8c2026-01-19 14:41:12 +010087# Create app user
88RUN addgroup -g 1000 appuser && \
89 adduser -u 1000 -G appuser -D appuser && \
90 mkdir -p /app/osmclient && \
91 chown -R appuser:appuser /app
92
mesajf6eb4ff2025-06-10 17:21:44 +020093ENV VIRTUAL_ENV=/app/osmclient/.venv \
94 PATH="/app/osmclient/.venv/bin:$PATH"
95
96# Copy Python packages from build stage
97COPY --from=builder --chown=appuser:appuser /app/osmclient/.venv /app/osmclient/.venv
98
99# Copy OSM binaries
garciadeblasf0aac8c2026-01-19 14:41:12 +0100100# COPY --from=builder /app/osmclient/.venv/bin/osm /usr/local/bin/osm
garciadeblas64e1a8e2025-11-27 17:47:18 +0100101COPY scripts/charm.sh /usr/sbin/charm
102
103# Add additional client tools
104COPY scripts/install-client-tools.sh /tmp/install-client-tools.sh
105RUN bash /tmp/install-client-tools.sh
mesajf6eb4ff2025-06-10 17:21:44 +0200106
mesajf6eb4ff2025-06-10 17:21:44 +0200107WORKDIR /app/osmclient
108
109# Set environment variables
110ENV 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
garciadeblasf0aac8c2026-01-19 14:41:12 +0100118USER appuser:appuser
mesajf6eb4ff2025-06-10 17:21:44 +0200119
garciadeblasf0aac8c2026-01-19 14:41:12 +0100120# CMD ["/usr/local/bin/osm"]
121CMD ["osm"]