Skip to content

Instantly share code, notes, and snippets.

@sairamkrish
Last active June 20, 2024 10:59
Show Gist options
  • Save sairamkrish/4325a28f66be125c3aa4d68a950950cb to your computer and use it in GitHub Desktop.
Save sairamkrish/4325a28f66be125c3aa4d68a950950cb to your computer and use it in GitHub Desktop.
Python | Poetry | Dockerfile and private repositories. Details - https://sairamkrish.medium.com/python-poetry-dockerfile-and-private-repositories-1b1108af3c6
# gather requirements
FROM python:3.9.2-slim as requirements-stage
WORKDIR /tmp
COPY ./pyproject.toml ./poetry.lock /tmp/
RUN apt-get update && \
apt-get install -y git && \
pip install poetry && \
poetry export -f requirements.txt --output requirements.txt --without-hashes
# Final stage
FROM apache/spark-py:v3.3.0
ARG spark_uid=185
ARG private_repo_username
ARG private_repo_token
USER ${spark_uid}
WORKDIR /app
COPY --from=requirements-stage /tmp/requirements.txt .
RUN git config --global credential.helper store && \
echo "@gitlab.com">https://${private_repo_username}:${private_repo_token}@gitlab.com" > ${HOME}/.git-credentials && \
pip install --no-cache-dir --upgrade -r /app/requirements.txt && \
rm -rf ${HOME}/.git-credentials
COPY . .
CMD ["python", "app.main:app"]
@sairamkrish
Copy link
Author

When we have an ecosystem like python — poetry — dockerfile and private repositories, there are few areas that will cause issues. Here are my notes while solving such issues.

Issue and solution is explained in this blog - https://sairamkrish.medium.com/python-poetry-dockerfile-and-private-repositories-1b1108af3c6

@jineshpaloor
Copy link

jineshpaloor commented Jun 20, 2024

@sairamkrish Looks like there is typo in line 19

should be

    echo "https://${private_repo_username}:${private_repo_token}@gitlab.com" > ${HOME}/.git-credentials && \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment