Move Dockerfile from devops to the repo, base image Alpine Linux 22/15222/4
authormesaj <juanmanuel.mesamendez.ext@telefonica.com>
Tue, 10 Jun 2025 16:44:35 +0000 (18:44 +0200)
committergarciadeblas <gerardo.garciadeblas@telefonica.com>
Thu, 9 Oct 2025 14:47:43 +0000 (16:47 +0200)
Change-Id: I54397ceda9519766519822251aff5e852ca52238
Signed-off-by: mesaj <juanmanuel.mesamendez.ext@telefonica.com>
Signed-off-by: garciadeblas <gerardo.garciadeblas@telefonica.com>
airflow/Dockerfile.production [new file with mode: 0644]
osm_webhook_translator/Dockerfile.production [new file with mode: 0644]

diff --git a/airflow/Dockerfile.production b/airflow/Dockerfile.production
new file mode 100644 (file)
index 0000000..89dc88f
--- /dev/null
@@ -0,0 +1,86 @@
+# 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: Build Stage #
+##########################
+
+FROM apache/airflow:2.5.3-python3.10 AS build
+
+ENV PIP_DISABLE_PIP_VERSION_CHECK=1
+
+ARG COMMON_GERRIT_REFSPEC=master
+
+USER root
+
+# Install only essential build dependencies
+RUN apt-get update && \
+      apt-get install -y --no-install-recommends \
+      gcc git python3-dev && \
+    rm -rf /var/lib/apt/lists/*
+
+USER airflow
+# Install base requirements
+RUN pip install --no-cache-dir setuptools-scm wheel
+
+# Install OSM common from Git
+RUN 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 - && \
+  pip3 wheel --no-cache-dir -r /tmp/osm-common/requirements.txt -w /tmp/wheels && \
+  pip3 wheel --no-cache-dir /tmp/osm-common -w /tmp/wheels
+
+# Install NG_SA requirements
+COPY requirements.txt /tmp/osm-ngsa/requirements.txt
+RUN pip wheel --no-cache-dir -r /tmp/osm-ngsa/requirements.txt -w /tmp/wheels
+
+# Install NG_SA
+COPY . /tmp/osm-ngsa
+USER root
+# workaound to allow the airflow user to write files in the copied folder
+RUN chown -R airflow:root /tmp/osm-ngsa && \
+  chmod -R u+w /tmp/osm-ngsa
+USER airflow
+RUN pip wheel --no-cache-dir /tmp/osm-ngsa -w /tmp/wheels
+
+
+#########################################################################################################################################################################
+
+################################
+# Stage 2: Runtime environment #
+################################
+
+FROM apache/airflow:2.5.3-python3.10
+
+USER airflow
+
+# Copy all artifacts to install
+COPY --chown=airflow:root --from=build /tmp/wheels /tmp/wheels
+COPY --chown=airflow:root --from=build /tmp/osm-common/requirements.txt /tmp/osm-requirements.txt
+COPY --chown=airflow:root --from=build /tmp/osm-ngsa/requirements.txt /tmp/ngsa-requirements.txt
+
+RUN pip install --no-cache-dir --no-index --find-links=/tmp/wheels \
+    -r /tmp/osm-requirements.txt \
+    -r /tmp/ngsa-requirements.txt \
+    osm_common \
+    osm_ngsa && \
+  rm -rf /tmp/wheels
+
diff --git a/osm_webhook_translator/Dockerfile.production b/osm_webhook_translator/Dockerfile.production
new file mode 100644 (file)
index 0000000..21ca2b9
--- /dev/null
@@ -0,0 +1,79 @@
+# 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: Build stage #
+########################
+FROM base AS build
+
+RUN --mount=type=cache,target=/var/cache/apk \
+    apk add --no-cache --virtual .build-deps \
+        build-base git curl
+
+WORKDIR /app
+
+# Create the virtual environment
+RUN python -m venv /app/.venv
+ENV PATH="/app/.venv/bin:$PATH"
+
+COPY requirements.txt ./
+
+RUN --mount=type=cache,target=/root/.cache/pip \
+    pip install --no-cache-dir -r requirements.txt
+
+COPY . .
+RUN --mount=type=cache,target=/root/.cache/pip \
+ pip install --no-cache-dir .
+
+
+####################################################################################################################################################################
+
+########################
+# Stage 3: Final Stage #
+########################
+FROM base AS final
+
+WORKDIR /app/osm_webhook_translator
+
+RUN  addgroup -g 1000 appuser && \
+ adduser  -u 1000 -G appuser -D appuser && \
+ chown -R appuser:appuser /app
+
+USER appuser
+
+ENV VIRTUAL_ENV=/app/.venv \
+  PATH="/app/.venv/bin:$PATH"
+
+COPY --from=build --chown=appuser:appuser /app/.venv /app/.venv
+
+EXPOSE 9998
+CMD ["uvicorn", "osm_webhook_translator.main:app", "--host", "0.0.0.0", "--port", "9998"]
+