Skip to content

Commit 0f26b58

Browse files
committed
Remove setup.py and switch to venv in Dockerfile.
1 parent eb4e6bd commit 0f26b58

6 files changed

Lines changed: 42 additions & 106 deletions

File tree

MANIFEST.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,16 @@ python3 -m blueprint
99

1010
### Using Docker
1111

12+
Development image:
1213
```shell
13-
...
14+
docker build -t blueprint -f dev.Dockerfile -t blueprint:dev .
15+
docker run blueprint:dev
16+
```
17+
18+
Production (Distroless) image:
19+
```shell
20+
docker build -t blueprint -f prod.Dockerfile -t blueprint:prod .
21+
docker run blueprint:prod
1422
```
1523

1624
### Resources

dev.Dockerfile

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
FROM python:3.8-slim AS builder
2-
RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc
2+
RUN apt-get update && apt-get install -y --no-install-recommends --yes python3-venv gcc libpython3-dev && \
3+
python3 -m venv /venv && \
4+
/venv/bin/pip install --upgrade pip
5+
6+
FROM builder AS builder-venv
37

48
COPY requirements.txt .
5-
RUN pip install -r requirements.txt
9+
RUN /venv/bin/pip install -r /requirements.txt
610

7-
COPY . .
8-
RUN python setup.py install
11+
FROM builder-venv AS tester
912

10-
FROM python:3.8.1-alpine3.11 AS runner
11-
COPY --from=builder /usr/local/lib/python3.8/site-packages/ /usr/local/lib/python3.8/site-packages/
13+
COPY . /app
14+
WORKDIR /app
15+
RUN /venv/bin/pytest
1216

13-
CMD ["python", "-m", "blueprint"]
17+
FROM python:3.8.1-alpine3.11 AS runner
18+
COPY --from=tester /venv /venv
19+
COPY --from=tester /app /app
1420

21+
WORKDIR /app
1522

16-
# TODO add test run to this image build
23+
ENTRYPOINT ["/venv/bin/python3", "-m", "blueprint"]
24+
USER 1001

prod.Dockerfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
FROM python:3.5-slim AS builder
2-
RUN apt-get update && apt-get install -y --no-install-recommends build-essential gcc
2+
RUN apt-get update && apt-get install -y --no-install-recommends --yes python3-venv gcc libpython3-dev && \
3+
python3 -m venv /venv && \
4+
/venv/bin/pip install --upgrade pip
5+
6+
FROM builder AS builder-venv
37

48
COPY requirements.txt .
5-
RUN pip install -r requirements.txt
9+
RUN /venv/bin/pip install -r /requirements.txt
10+
11+
FROM builder-venv AS tester
612

7-
COPY . .
8-
RUN python setup.py install
13+
COPY . /app
14+
WORKDIR /app
15+
RUN /venv/bin/pytest
916

10-
FROM gcr.io/distroless/python3 as runner
11-
COPY --from=builder /usr/local/lib/python3.5/site-packages/ /usr/local/lib/python3.5/site-packages/
17+
FROM gcr.io/distroless/python3-debian10 AS runner
18+
COPY --from=tester /venv /venv
19+
COPY --from=tester /app /app
1220

13-
ENV PYTHONPATH=/usr/local/lib/python3.5/site-packages/blueprint-0.0.1-py3.5.egg
14-
ENTRYPOINT ["python", "-m", "blueprint"]
21+
WORKDIR /app
1522

16-
# TODO parametrize the version (Python and package version)
17-
# TODO add test run to this image build
23+
ENTRYPOINT ["/venv/bin/python3", "-m", "blueprint"]
24+
USER 1001

setup.py

Lines changed: 0 additions & 76 deletions
This file was deleted.

test.Dockerfile

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)