mercredi 14 avril 2021

Should I run tests during the docker build?

I have a Dockerfile like this:

FROM python:3.9

WORKDIR /app

RUN apt-get update && apt-get upgrade -y

RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python -

ENV PATH /root/.local/bin:$PATH

COPY pyproject.toml poetry.lock Makefile ./

COPY src ./src

COPY tests ./tests

RUN poetry install && poetry run pytest && make clean

CMD ["bash"]

As you can see that tests will be run during the build. It could slow down the build little bit, but will ensure that my code runs in the Docker container.

If tests pass in my local machine, does not mean that they will also pass in the docker container.

Suppose I add a feature in my code that uses chromedriver or ffmpeg binaries, that is present in my system, so tests will pass in my system.

But, suppose I forget to install those dependencies in the Dockerfile, then the docker build will fail (as tests are running during the build)

What is the standard way of doing what i am trying to do ?

Is my Dockerfile good ? or should i do something differently ?

Aucun commentaire:

Enregistrer un commentaire