FROM 475275892927.dkr.ecr.us-east-1.amazonaws.com/python:3.10-aws2-builder
ARG PACKAGE
COPY . /${PACKAGE}
WORKDIR /${PACKAGE}
USER ${ROOT_USER}
RUN chown -R ${APP_USER}:${APP_GROUP} /${PACKAGE}
USER ${APP_USER}
RUN python3 -m venv venv && \
    source ./venv/bin/activate && \
        cp pip.conf ./venv/ && \
        pip3 install -U pip setuptools wheel twine && \
        python3 setup.py bdist_wheel && \
        pip3 wheel -r requirements/base.pip --wheel-dir ./dist && \
        twine upload -r pypi --config-file .pypirc ./dist/*

FROM 475275892927.dkr.ecr.us-east-1.amazonaws.com/python:3.10-aws2
ARG PACKAGE
ARG APP
COPY --from=builder /${PACKAGE}/pip.conf /app/pip.conf
COPY --from=builder /${PACKAGE}/.pypirc /app/.pypirc
COPY --from=builder /${PACKAGE}/dist /app/dist
COPY --from=builder /${PACKAGE}/requirements /app/requirements
USER ${ROOT_USER}
RUN chown -R ${APP_USER}:${APP_GROUP} /app
USER ${APP_USER}
WORKDIR /app
RUN python3 -m venv venv && \
    source ./venv/bin/activate && \
        cp pip.conf ./venv/ && \
        pip3 install -U pip && \
        pip3 install -r /app/requirements/base.pip -f /app/dist && \
        pip3 install ${APP} -f /app/dist && \
        rm -rf /app/dist
ENTRYPOINT ["./venv/bin/python3", "-m", "s3_uploader"]
