From f46782e6cf28afa37cde3e299c8725630d22dbd3 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Sun, 24 Mar 2024 17:10:41 -0700 Subject: [PATCH 1/9] use venv to allow running as any user --- Dockerfile | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a66379b..0abc1a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,22 @@ # ---- Base ---- FROM python:alpine AS base +ENV VENV_DIR="/app" +ENV PATH="${VENV_DIR}/bin:$PATH" + # # ---- Dependencies ---- FROM base AS dependencies # install dependencies -COPY requirements.txt . -RUN pip install --user -r requirements.txt +COPY requirements.txt / +RUN python3 -m venv "${VENV_DIR}" +RUN pip install -r /requirements.txt # # ---- Release ---- FROM base AS release # copy installed dependencies and project source file(s) -WORKDIR / -COPY --from=dependencies /root/.local /root/.local -COPY cloudflare-ddns.py . +WORKDIR "${VENV_DIR}" +COPY --from=dependencies "${VENV_DIR}" "${VENV_DIR}" +COPY cloudflare-ddns.py / CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"] From b3d08b3776feecf77865a750e3a3d42683058a50 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Sun, 24 Mar 2024 17:10:49 -0700 Subject: [PATCH 2/9] we dont need the entire project in our docker build context --- .dockerignore | 6 ++++++ .vscode/settings.json | 1 + 2 files changed, 7 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a56b6f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +# Ignore everything +* + +# Allow specific files and folders +!/requirements.txt +!/cloudflare-ddns.py diff --git a/.vscode/settings.json b/.vscode/settings.json index 4f20a6d..a90a6ea 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -8,6 +8,7 @@ "**/Thumbs.db": true, ".github": true, ".gitignore": true, + ".dockerignore": true, ".vscode": true, "Dockerfile": true, "LICENSE": true, From 32d597f2c3802fdca722f52dd583f9a0c5bda397 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Sun, 24 Mar 2024 17:13:21 -0700 Subject: [PATCH 3/9] update readme to run container as non-root user --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index d774c0f..af78226 100755 --- a/README.md +++ b/README.md @@ -277,9 +277,7 @@ services: security_opt: - no-new-privileges:true network_mode: 'host' - environment: - - PUID=1000 - - PGID=1000 + user: 1000:1000 volumes: - /YOUR/PATH/HERE/config.json:/config.json restart: unless-stopped From d28c304f3d4d9501b96974d08296b5ed16683074 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:12:26 -0700 Subject: [PATCH 4/9] update user in docker-compose file --- docker/docker-compose.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index bb8b21c..6e73039 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -6,9 +6,7 @@ services: security_opt: - no-new-privileges:true network_mode: 'host' - environment: - - PUID=1000 - - PGID=1000 + user: 1000:1000 volumes: - /YOUR/PATH/HERE/config.json:/config.json restart: unless-stopped From 4931cf0de28ff158a65152216a7d7e9f3f6ce753 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:17:17 -0700 Subject: [PATCH 5/9] docker compose version is deprecated --- docker/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index 6e73039..20f0910 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -1,4 +1,3 @@ -version: '3.9' services: cloudflare-ddns: image: timothyjmiller/cloudflare-ddns:latest From e2efb6a27b31d4d1b1e868cc1044e8928fd29698 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:30:27 -0700 Subject: [PATCH 6/9] correct workdir --- Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 0abc1a0..8cf7450 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,6 @@ RUN pip install -r /requirements.txt # ---- Release ---- FROM base AS release # copy installed dependencies and project source file(s) -WORKDIR "${VENV_DIR}" COPY --from=dependencies "${VENV_DIR}" "${VENV_DIR}" COPY cloudflare-ddns.py / CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"] From 10a6f6ed802c35addbae544c5888b9b99ba1c7f5 Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:31:24 -0700 Subject: [PATCH 7/9] revert workdir --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 8cf7450..2546571 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ RUN pip install -r /requirements.txt # ---- Release ---- FROM base AS release # copy installed dependencies and project source file(s) +WORKDIR / COPY --from=dependencies "${VENV_DIR}" "${VENV_DIR}" COPY cloudflare-ddns.py / CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"] From 0f862fd297ed658196f5784c88e0247625772fdb Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:32:11 -0700 Subject: [PATCH 8/9] revert cloudflare copy for no reason --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2546571..87d6a9f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,5 +18,5 @@ FROM base AS release # copy installed dependencies and project source file(s) WORKDIR / COPY --from=dependencies "${VENV_DIR}" "${VENV_DIR}" -COPY cloudflare-ddns.py / +COPY cloudflare-ddns.py . CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"] From 1adb7587accca0fe090ba7f4404b6997acc2606b Mon Sep 17 00:00:00 2001 From: JtMotoX <7191259+JtMotoX@users.noreply.github.com> Date: Tue, 22 Oct 2024 18:34:05 -0700 Subject: [PATCH 9/9] revert more lines for no reason but to help owner feel more comfortable --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 87d6a9f..1830201 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,9 +8,9 @@ ENV PATH="${VENV_DIR}/bin:$PATH" # ---- Dependencies ---- FROM base AS dependencies # install dependencies -COPY requirements.txt / +COPY requirements.txt . RUN python3 -m venv "${VENV_DIR}" -RUN pip install -r /requirements.txt +RUN pip install -r requirements.txt # # ---- Release ----