0

I am working on building and publishing a python library using hatch library to our local pypiserver. I would like to build and publish it from the Docker container.

What is a proper way to do so? Do I need to run the container and then connect to it, pull the source code, build, test and publish? Other approaches?

My current implementation is building and publishing the library when docker is building a new image:

FROM python:3.6.8-stretch

ARG PYPI_USERNAME
ARG PYPI_PASSWORD

RUN mkdir /code

WORKDIR /code

RUN echo "machine pypi.myserver.com\n\tlogin $PYPI_USERNAME\n\tpassword $PYPI_PASSWORD" >> ~/.netrc && \
    mkdir ~/.pip && \
    echo "[global]\nextra-index-url = https://pypi.myserver.com\ntrusted-host = pypi.myserver.com" >> ~/.pip/pip.conf

RUN echo "\n[distutils]\nindex-servers=\n    myserver\n\n[myserver]\nrepository: https://pypi.myserver.com/\nusername: $PYPI_USERNAME\npassword: $PYPI_PASSWORD\n" > ~/.pypirc

COPY . .

RUN pip install . && rm -r ~/.pip && rm ~/.netrc

RUN py.test

RUN hatch build && hatch release -r myserver -u admin
RUN rm ~/.pypirc

CMD [ "echo", "OK" ]

Then I verify the exit status code ($?) and make a conclusion whether it was successful or not.

In the end, I remove all images from the Docker.

Thank you.

  • What are you gaining by using Docker here? – David Maze Jun 12 '19 at 12:54
  • We are using different version of Python (2.7, 3.6, 3.7) I thought to use `virtualenv`, but then decided to come up with a better isolation in build process and do not install all dependency on host machine. Overhead? – Stanislav Hordiyenko Jun 13 '19 at 00:44
  • [tox](https://tox.readthedocs.io/en/latest/) is a purpose-built tool for running installation and tests against multiple Python versions. It in effect spins up multiple virtual environments. I might start there. – David Maze Jun 13 '19 at 09:53

0 Answers0