From a1ec3df6b5c5bf6459ab3db85c57617cb85cd582 Mon Sep 17 00:00:00 2001 From: jogerj <30559735+jogerj@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:16:45 +0200 Subject: [PATCH 1/3] feat(docker): docker-compose setup --- docker-compose.yml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..87f10d2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,4 @@ +services: + runner: + build: . + restart: unless-stopped From 974cd3d32abdbbe24b8d2f248f47a799251014c4 Mon Sep 17 00:00:00 2001 From: jogerj <30559735+jogerj@users.noreply.github.com> Date: Tue, 8 Aug 2023 20:34:16 +0200 Subject: [PATCH 2/3] feat(docker): minimize image build size --- .dockerignore | 16 ++++++++++++++++ Dockerfile | 24 ++++++++++++++++++------ requirements.txt | 16 ++++++++-------- 3 files changed, 42 insertions(+), 14 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..55160c6 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +# https://github.com/garygitton/dockerignore +# Common +README.md +CHANGELOG.md +docker-compose.yml +Dockerfile +.dockerignore + +# git +.git +.github +.gitattributes +.gitignore + +.editorconfig +.env.example diff --git a/Dockerfile b/Dockerfile index 1344ec3..7ed5f5f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,25 @@ -FROM python:3.11-alpine +FROM alpine:3.18 AS compile-image RUN apk update -RUN apk add make automake gcc g++ subversion python3-dev libffi-dev +RUN apk add --no-cache python3 make automake gcc g++ subversion python3-dev libffi-dev WORKDIR /app -COPY ./requirements.txt requirements.txt -RUN pip install -r requirements.txt +COPY ./requirements.txt /app/ +RUN python3 -m venv /app +RUN /app/bin/pip install -r requirements.txt +RUN rm -rf /app/lib/python3.11/site-packages/setuptools* && \ + rm -rf /app/lib/python3.11/site-packages/pip* && \ + rm -rf /app/bin/pip* -COPY . . +FROM alpine:3.18 AS runtime-image -CMD ["python3", "src/main.py"] +RUN apk add --no-cache python3 + +WORKDIR /app + +COPY . /app + +COPY --from=compile-image /app/ ./ + +CMD ["/app/bin/python3", "src/main.py"] diff --git a/requirements.txt b/requirements.txt index f5685ee..236ef70 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,8 @@ -aiodns==3.0.0 -aiohttp==3.8.5 -aiohttp-socks==0.7.1 -loguru==0.6.0 -pydantic==1.10.2 -python-dotenv==0.21.0 -typing_extensions==4.4.0 -cryptography==41.0.3 +aiodns~=3.0.0 +aiohttp~=3.8.5 +aiohttp-socks~=0.7.1 +loguru~=0.6.0 +pydantic~=1.10.2 +python-dotenv~=0.21.0 +typing_extensions~=4.4.0 +cryptography~=41.0.3 From d056f1e8958bc6fa7eb17808aee136385953dddf Mon Sep 17 00:00:00 2001 From: jogerj <30559735+jogerj@users.noreply.github.com> Date: Tue, 8 Aug 2023 21:08:26 +0200 Subject: [PATCH 3/3] fix(docker): remove duplicate python3 dep --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7ed5f5f..97dfcda 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM alpine:3.18 AS compile-image RUN apk update -RUN apk add --no-cache python3 make automake gcc g++ subversion python3-dev libffi-dev +RUN apk add --no-cache make automake gcc g++ subversion python3-dev libffi-dev WORKDIR /app