blob: 9d99ea21ae4744b660bf477018d37b22b6c6b8cd [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
60RUN --mount=type=cache,target=/root/.cache/pip \
61 git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \
62 cd /tmp/osm-im && \
63 git fetch origin ${IM_GERRIT_REFSPEC} && \
64 git checkout FETCH_HEAD && \
65 cd - && \
66 pip install --no-cache-dir -r /tmp/osm-im/requirements.txt && \
67 pip install /tmp/osm-im
68
69COPY . /tmp/osmclient/
70RUN --mount=type=cache,target=/root/.cache/pip \
71 cd /tmp/osmclient && \
72 pip install --no-cache-dir -r /tmp/osmclient/requirements.txt && \
73 pip install /tmp/osmclient && \
74 cd -
75
76#####################################################################################################################################################
77
78#######################
79# Stage 3: Final image#
80#######################
81
82FROM python:3.10-alpine AS final
83
84# Install runtime dependencies
85RUN apk add --no-cache \
86 bash \
87 libmagic
88
89ENV VIRTUAL_ENV=/app/osmclient/.venv \
90 PATH="/app/osmclient/.venv/bin:$PATH"
91
92# Copy Python packages from build stage
93COPY --from=builder --chown=appuser:appuser /app/osmclient/.venv /app/osmclient/.venv
94
95# Copy OSM binaries
96COPY --from=builder /app/osmclient/.venv/bin/osm /usr/local/bin/osm
garciadeblas64e1a8e2025-11-27 17:47:18 +010097COPY scripts/charm.sh /usr/sbin/charm
98
99# Add additional client tools
100COPY scripts/install-client-tools.sh /tmp/install-client-tools.sh
101RUN bash /tmp/install-client-tools.sh
mesajf6eb4ff2025-06-10 17:21:44 +0200102
103# Create app user
104RUN addgroup -g 1000 appuser && \
105 adduser -u 1000 -G appuser -D appuser && \
106 mkdir -p /app/osmclient && \
107 chown -R appuser:appuser /app
108
109WORKDIR /app/osmclient
110
111# Set environment variables
112ENV LC_ALL=C.UTF-8i \
113 LANG=C.UTF-8 \
114 OSM_HOSTNAME=nbi:9999 \
115 OSM_USER=admin \
116 OSM_PASSWORD=admin \
117 OSM_PROJECT=admin
118
119# Switch to non-root user
120USER appuser
121
122CMD ["/usr/local/bin/osm"]