FROM --platform=$TARGETPLATFORM entplus.jfrog.io/jfrog-docker/jfrog/echo-base:20260629 AS base
LABEL maintainer=infra@jfrog.com
LABEL name=jfrog/platformfederation

ARG TARGETARCH
ARG HTTP=8017
ARG GRPC=8018

ENV uname=platformfederation \
    gname=platformfederation \
    JF_PRODUCT_DATA_INTERNAL=/var/opt/jfrog/platformfederation \
    JF_PRODUCT_HOME=/opt/jfrog/platformfederation \
    TARGETARCH=${TARGETARCH:-arm64} \
    HTTP=${HTTP} \
    GRPC=${GRPC}

USER root

RUN groupadd -g 1129 platformfederation \
    && useradd -Ms /bin/bash  -g platformfederation -u 1129 platformfederation

# Drop unused OpenSSL config leftovers from the base image; their X.509
# extension keywords trigger false-positive matches in secret scanners.
RUN rm -f /etc/ssl/openssl.cnf.orig /etc/ssl/openssl-fips.cnf \
          /usr/lib/ssl/openssl.cnf.orig /usr/lib/ssl/openssl-fips.cnf

FROM base as builder

USER root

COPY ./bin/jf-platformfederation-linux-${TARGETARCH} ${JF_PRODUCT_HOME}/app/platformfederation/bin/platformfederation
COPY ./app/doc/JFrog-Platform-Federation-Third-Parties-Usage-About-Box.html ${JF_PRODUCT_HOME}/app/doc/JFrog-Platform-Federation-Third-Parties-Usage-About-Box.html

RUN chmod -R 775 ${JF_PRODUCT_HOME}/app/platformfederation/bin/* && chown -R ${uname}:${gname} ${JF_PRODUCT_HOME}

FROM base

USER root

# Copy scripts
COPY --chown=${uname}:${uname} Dockerfile /docker/platformfederation/
COPY --chown=${uname}:${uname} entrypoint-platformfederation.sh ${JF_PRODUCT_HOME}/app/bin/
RUN chmod +x ${JF_PRODUCT_HOME}/app/bin/entrypoint-platformfederation.sh

COPY --from=builder $JF_PRODUCT_HOME $JF_PRODUCT_HOME

RUN mkdir -p ${JF_PRODUCT_DATA_INTERNAL}/etc/security \
             ${JF_PRODUCT_HOME}/app/run && \
    chown -R ${uname}:0 ${JF_PRODUCT_HOME} ${JF_PRODUCT_DATA_INTERNAL} && \
    chmod -R g=u ${JF_PRODUCT_HOME} ${JF_PRODUCT_DATA_INTERNAL} && \
    ln -s ${JF_PRODUCT_DATA_INTERNAL} ${JF_PRODUCT_HOME}/var

EXPOSE ${HTTP} ${GRPC}

USER ${uname}

WORKDIR ${JF_PRODUCT_HOME}

ENTRYPOINT ["/usr/local/bin/fips-entrypoint.sh","/opt/jfrog/platformfederation/app/bin/entrypoint-platformfederation.sh"]