kaizendorks / kaizendorks/pymongo_inmemory

pymongo_inmemory doesn't work in docker container alpine

Open
#54 5 comments 0 reactions 1 assignee Claimed by @ekarademir View on GitHub
bug
Dominant language
Python
Stars
53
Forks
18
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
I am having troubles in running my tests inside my docker alpine container. I installed the pymongo_inmemory properly and started the tests and this was returned to me:

`FileNotFoundError: [Errno 2] No such file or directory: '/usr/src/venv/lib/python3.9/site-packages/pymongo_inmemory/downloader/../.cache/extract/mongodb-linux-x86_64-4.0.23-tgz/mongodb-linux-x86_64-4.0.23/bin/mongod'`

I verified it and the mongod binary is there. So i tried to run the `subprocess.Popen` to just `ls` the folders and indeed the error appeared.
With a little bit of research I've found that using the `shell=True` option in the `Popen()` class like this: `subprocess.Popen(["ls path/to/bin"], shell=True)` worked, but when I tried to run the mongod with this command it gave me this error:

`/bin/sh: /usr/src/venv/lib/python3.9/site-packages/pymongo_inmemory/downloader/../.cache/extract/mongodb-linux-x86_64-4.0.23-tgz/mongodb-linux-x86_64-4.0.23/bin/mongod: not found`

Obs: In my machine works if I don't use the docker container

**To Reproduce**
Steps to reproduce the behavior:
1. Create tests (I used pytest)
2. Create a dockerfile (I used the alpine):
```
FROM python:3.9-alpine AS builder

RUN pip install --user pipenv

WORKDIR /usr/src

RUN apk update
RUN apk add postgresql-dev gcc python3-dev musl-dev
RUN apk add postgresql

ADD Pipfile.lock Pipfile /usr/src/

RUN /root/.local/bin/pipenv lock --dev -r > requirements.txt

RUN python -m venv venv
RUN venv/bin/pip install -r requirements.txt

FROM python:3.9-alpine AS runtime

RUN mkdir -v /usr/src/venv
COPY --from=builder /usr/src/venv /usr/src/venv

RUN apk update
RUN apk add gcc postgresql

WORKDIR /usr/src

RUN ln -snf /usr/share/zoneinfo/America/Sao_Paulo \
/etc/localtime && \
echo "America/Sao_Paulo" > /etc/timezone

COPY ./src/app ./app
COPY ./src/tests ./tests
COPY ./src/main.py ./

# Copy the crontab configuration file
COPY ./cronjobs/execute_updater.dev ./cronjobs/execute_updater
RUN /usr/bin/crontab ./cronjobs/execute_updater
RUN touch /var/log/cron.log

# path the python venv bin - tru not to change since its needed in the ci pipeline
# CMD /usr/sbin/crond -f -l 8 & tail -f /var/log/cron.log
CMD ["python", "-m", "http.server", "8080"]
```

3. Run the container and then run the tests (I ran inside the container itself)
4. The error appears

**Expected behavior**
It's expected that the tests pass

**Screenshots**
![image](https://user-images.githubusercontent.com/21108976/162024186-53ec646a-f806-4ca1-bacc-f7ed14d065fb.png)

**Context:**
- Version of pymongo_inmemory [~=0.2.5]
- python3.9-alpine docker image

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.