# Build stage
FROM eu.gcr.io/revolut-labs/ecom-store-base:php8.2 as build
COPY . /var/module
RUN rm -f /etc/nginx/sites-enabled/default \
    && rm -f /etc/nginx/conf.d/default.conf
RUN cp /var/module/docker/nginx.conf /etc/nginx/sites-available/ps.conf \
    && ln -sf /etc/nginx/sites-available/ps.conf /etc/nginx/sites-enabled/ps.conf
    
WORKDIR /var/module
RUN composer install
RUN ./docker/bin/build-release.sh
RUN chmod +x ./build/build.sh
RUN ./build/build.sh
# Deployment stage
FROM eu.gcr.io/revolut-labs/ecom-store-base:php8.2 as deployment

RUN apt-get update -y
RUN apt-get upgrade -y
RUN rm -rf /var/lib/apt/lists/*

COPY --from=build /var/module/deployment/ps.nginx.conf /etc/nginx/sites-available/ps.conf
COPY --from=build /var/module/deployment/health_check.php /var/www/
COPY --from=build /var/module/revolutpayment.zip /var/module/revolutpayment.zip
COPY --from=build /var/module/deployment/start.sh /start.sh

RUN ln -sf /etc/nginx/sites-available/ps.conf /etc/nginx/sites-enabled/ps.conf \
    && rm -f /etc/nginx/sites-enabled/default

RUN chmod +x /start.sh

EXPOSE 8080

CMD ["sh", "-c", "/start.sh"]
ENTRYPOINT []

LABEL com.revolut.base.maintainer=acquiring.online-payment-integrations@revolut.com
LABEL com.revolut.base.role=prestashop-dev-store
LABEL com.revolut.base.release_branch=$RELEASE_BRANCH
LABEL com.revolut.base.release_number=$RELEASE_NUMBER