From: mesaj Date: Tue, 10 Jun 2025 15:21:44 +0000 (+0200) Subject: Move Dockerfile from devops to the repo, base image Alpine Linux X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F15221%2F5;p=osm%2Fosmclient.git Move Dockerfile from devops to the repo, base image Alpine Linux Change-Id: Ic992221f402c00d176c117eb17a7a604377fe237 Signed-off-by: mesaj Signed-off-by: garciadeblas --- diff --git a/Dockerfile.production b/Dockerfile.production new file mode 100644 index 0000000..3b2bdaf --- /dev/null +++ b/Dockerfile.production @@ -0,0 +1,118 @@ +# syntax=docker/dockerfile:1 +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### + + +####################### +# Stage 1: Base stage# +####################### + +FROM python:3.10-alpine AS base + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +############################################################################################################################################## + +######################### +# Stage 2: builder stage# +######################### + +FROM base AS builder + +# Install build dependencies +RUN apk add --no-cache \ + gcc \ + musl-dev \ + libffi-dev \ + openssl-dev \ + make \ + cmake \ + build-base \ + patch \ + curl \ + git \ + bash \ + libmagic + +# Isolate dependencies in a venv +RUN python -m venv /app/osmclient/.venv +ENV PATH="/app/osmclient/.venv/bin:$PATH" + +# Install OSM packages (assuming they provide source packages or wheels) +ARG IM_GERRIT_REFSPEC=master + +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/IM.git /tmp/osm-im && \ + cd /tmp/osm-im && \ + git fetch origin ${IM_GERRIT_REFSPEC} && \ + git checkout FETCH_HEAD && \ + cd - && \ + pip install --no-cache-dir -r /tmp/osm-im/requirements.txt && \ + pip install /tmp/osm-im + +COPY . /tmp/osmclient/ +RUN --mount=type=cache,target=/root/.cache/pip \ + cd /tmp/osmclient && \ + pip install --no-cache-dir -r /tmp/osmclient/requirements.txt && \ + pip install /tmp/osmclient && \ + cd - + +##################################################################################################################################################### + +####################### +# Stage 3: Final image# +####################### + +FROM python:3.10-alpine AS final + +# Install runtime dependencies +RUN apk add --no-cache \ + bash \ + libmagic + +ENV VIRTUAL_ENV=/app/osmclient/.venv \ + PATH="/app/osmclient/.venv/bin:$PATH" + +# Copy Python packages from build stage +COPY --from=builder --chown=appuser:appuser /app/osmclient/.venv /app/osmclient/.venv + +# Copy OSM binaries +COPY --from=builder /app/osmclient/.venv/bin/osm /usr/local/bin/osm +COPY charm.sh /usr/sbin/charm + +# Create app user +RUN addgroup -g 1000 appuser && \ + adduser -u 1000 -G appuser -D appuser && \ + mkdir -p /app/osmclient && \ + chown -R appuser:appuser /app + +WORKDIR /app/osmclient + +# Set environment variables +ENV LC_ALL=C.UTF-8i \ + LANG=C.UTF-8 \ + OSM_HOSTNAME=nbi:9999 \ + OSM_USER=admin \ + OSM_PASSWORD=admin \ + OSM_PROJECT=admin + +# Switch to non-root user +USER appuser + +CMD ["/usr/local/bin/osm"] diff --git a/charm.sh b/charm.sh new file mode 100755 index 0000000..75e7a47 --- /dev/null +++ b/charm.sh @@ -0,0 +1,31 @@ +#!/bin/bash +####################################################################################### +# Copyright ETSI Contributors and Others. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. +####################################################################################### + +# Workaround for charm build + +function build() { + echo "$@" + charm-build "$@" +} + +params="$@" +delete=build + +params=("${params[@]/$delete}") + +build $params