FROM python:3.11-alpine
WORKDIR /app

ARG ARTIFACT_VERSION

RUN apk add --no-cache gcc libc-dev libffi-dev curl vim && \
    addgroup -S appgroup && adduser -S appuser -G appgroup -h /app

RUN pip install \
    --pre \
    --trusted-host 150.254.211.2 \
    --extra-index-url https://150.254.211.2/artifactory/api/pypi/geant-swd-pypi/simple \
    --target /app \
    geant-service-orchestrator==${ARTIFACT_VERSION}

# Set the environment variable for the translations directory
ENV TRANSLATIONS_DIR=/app/gso/translations/

# Copy the shell scripts and ensure scripts do not have Windows line endings and make them executable
COPY start-app.sh start-worker.sh start-scheduler.sh /app/
RUN sed -i 's/\r$//' start-app.sh start-worker.sh start-scheduler.sh && \
    chmod 755 start-app.sh start-worker.sh start-scheduler.sh

RUN chown -R appuser:appgroup /app
USER appuser
EXPOSE 8080
ENTRYPOINT ["/app/start-app.sh"]