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.