blob: 515052480e56f03e4c099ae0f8d9ef3ff4e260d9 [file] [log] [blame]
# 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 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 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
# Create app user
RUN addgroup -g 1000 appuser && \
adduser -u 1000 -G appuser -D appuser && \
mkdir -p /app/osmclient && \
chown -R appuser:appuser /app
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 scripts/charm.sh /usr/sbin/charm
# Add additional client tools
COPY scripts/install-client-tools.sh /tmp/install-client-tools.sh
RUN bash /tmp/install-client-tools.sh
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:appuser
# CMD ["/usr/local/bin/osm"]
CMD ["osm"]