From 123336d9b93d225278bbb771ea2d9812898e57a6 Mon Sep 17 00:00:00 2001 From: mesaj Date: Tue, 10 Jun 2025 16:53:28 +0200 Subject: [PATCH] Move Dockerfile from devops to the repo, base image Alpine Linux Change-Id: Id85bd6a8fddaced4a2b3cc50c9ae185945aac1f9 Signed-off-by: mesaj Signed-off-by: garciadeblas --- Dockerfile.production | 137 +++++++++++++++++++++++++++++++++++ scripts/dashboarder-start.sh | 18 +++++ 2 files changed, 155 insertions(+) create mode 100644 Dockerfile.production create mode 100644 scripts/dashboarder-start.sh diff --git a/Dockerfile.production b/Dockerfile.production new file mode 100644 index 0000000..03acd6d --- /dev/null +++ b/Dockerfile.production @@ -0,0 +1,137 @@ +####################################################################################### +# 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: Build stage # +######################## + +FROM python:3.10-alpine AS base + + +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 + +FROM python:3.10-alpine AS builder + +# Install build dependencies +RUN apk add --no-cache \ + gcc \ + musl-dev \ + libffi-dev \ + openssl-dev \ + curl \ + git \ + openssh-client \ + zlib-dev \ + jpeg-dev \ + libxml2-dev \ + libxslt-dev + +WORKDIR /app/mon + +# Create virtual environment +RUN python -m venv /app/mon/.venv +ENV PATH="/app/mon/.venv/bin:$PATH" + +ARG COMMON_GERRIT_REFSPEC=master + +# Install OSM dependency modules with no cache +RUN --mount=type=cache,target=/root/.cache/pip \ + git clone --filter=blob:none --tags https://osm.etsi.org/gerrit/osm/common.git /tmp/osm-common && \ + cd /tmp/osm-common && \ + git fetch origin "${COMMON_GERRIT_REFSPEC}" && \ + git checkout FETCH_HEAD &&\ + cd - && \ + pip install --no-cache-dir -r /tmp/osm-common/requirements.txt && \ + pip install --no-cache-dir /tmp/osm-common + +# Install MON +COPY . . +RUN --mount=type=cache,target=/root/.cache/pip \ + pip install --no-cache-dir -r requirements.txt \ + && pip install --no-cache-dir . + + +########################################################################################################################################################### + +######################## +# Stage 2: Final image # +######################## + +FROM python:3.10-alpine AS final + +# Install runtime dependencies +RUN apk add --no-cache \ + ca-certificates \ + openssh-client + +# Copy virtual environment from build stage +COPY --from=builder /app/mon/.venv /app/mon/.venv +ENV PATH="/app/mon/.venv/bin:$PATH" + +# Copy necessary binaries and libraries +COPY --from=builder /usr/lib/ /usr/lib/ +COPY --from=builder /lib/ /lib/ + +# Copy application scripts +COPY scripts/ /app/mon/scripts/ + +# Create app user and directories +RUN addgroup -g 1000 appuser && \ + adduser -u 1000 -G appuser -D -h /app appuser && \ + mkdir -p /app/mon && \ + mkdir -p /app/storage/kafka && \ + mkdir /app/log && \ + chown -R appuser:appuser /app + +WORKDIR /app/mon + +USER appuser + +# Environment variables +ENV OSMMON_MESSAGE_DRIVER kafka \ + OSMMON_MESSAGE_HOST kafka \ + OSMMON_MESSAGE_PORT 9092 \ + OSMMON_DATABASE_DRIVER mongo \ + OSMMON_DATABASE_URI mongodb://mongo:27017 \ + OSMMON_SQL_DATABASE_URI sqlite:///mon_sqlite.db \ + OSMMON_OPENSTACK_DEFAULT_GRANULARITY 300 \ + OSMMON_GLOBAL_REQUEST_TIMEOUT 10 \ + OSMMON_GLOBAL_LOGLEVEL INFO \ + OSMMON_VCA_HOST localhost \ + OSMMON_VCA_SECRET secret \ + OSMMON_VCA_USER admin \ + OSMMON_VCA_CACERT cacert \ + OSMMON_DATABASE_COMMONKEY changeme \ + OSMMON_COLLECTOR_INTERVAL 30 \ + OSMMON_EVALUATOR_INTERVAL 30 \ + OSMMON_PROMETHEUS_URL http://prometheus:9090 \ + OSMMON_GRAFANA_URL http://grafana:3000 \ + OSMMON_GRAFANA_USER admin \ + OSMMON_GRAFANA_PASSWORD admin + +EXPOSE 8000 + +HEALTHCHECK --start-period=120s --interval=5s --timeout=2s --retries=12\ + CMD osm-mon-healthcheck || exit 1 + +# Switch to app user +USER appuser + +CMD ["/bin/sh", "scripts/dashboarder-start.sh] diff --git a/scripts/dashboarder-start.sh b/scripts/dashboarder-start.sh new file mode 100644 index 0000000..171f75d --- /dev/null +++ b/scripts/dashboarder-start.sh @@ -0,0 +1,18 @@ +####################################################################################### +# 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. +####################################################################################### + +osm-mon-dashboarder -- 2.25.1