~cadence/tube-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
2 2

[PATCH v2] Removed default config file from Dockerfile, added .git folder to dockerignore

Details
Message ID
<20210301204549.17645-1-beltramo.ale@gmail.com>
DKIM signature
pass
Download raw message
Patch: +27 -0
---
 .dockerignore | 13 +++++++++++++
 .gitignore    |  1 +
 Dockerfile    | 13 +++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 .dockerignore
 create mode 100644 Dockerfile

diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..ae20a5b
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,13 @@
# Editor crud files
*~
\#*#
.vscode
.idea
.git

# Artifacts
__pycache__

# Personal
/generic-updater
/configuration.py
diff --git a/.gitignore b/.gitignore
index f276bd1..dfb5a99 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
*~
\#*#
.vscode
.idea

# Artifacts
__pycache__
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..df3ef97
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,13 @@
FROM python:3.9-buster

WORKDIR /workdir

COPY ./requirements.txt /workdir/requirements.txt

RUN pip install -r requirements.txt

COPY . /workdir

EXPOSE 3000

CMD python index.py
\ No newline at end of file
-- 
2.30.0
Details
Message ID
<20210318234429.d58f6f60afc733a4d00e0042@disroot.org>
In-Reply-To
<20210301204549.17645-1-beltramo.ale@gmail.com> (view parent)
DKIM signature
pass
Download raw message
Hi, I'm finally getting to look at this. Thank you so much for your
patience.

> +/configuration.py

Did you mean to put the main configuration file in dockerignore?

> +COPY ./requirements.txt /workdir/requirements.txt
> +
> +RUN pip install -r requirements.txt
> +
> +COPY . /workdir

Is there a reason why you don't `COPY .` straight away? Why 2 copy
operations?
Details
Message ID
<CANFMze3R3R3qzq84zW=fYhnS+5C2_EDWn_Z-w692_WVEZ+nxhA@mail.gmail.com>
In-Reply-To
<20210318234429.d58f6f60afc733a4d00e0042@disroot.org> (view parent)
DKIM signature
pass
Download raw message
>> +/configuration.py
>
> Did you mean to put the main configuration file in dockerignore?

Yes, my understanding is that it’s preferred to avoid giving a default
configuration file to users, so we avoid copying it in the docker
image. In order to run it a user need to create a configuration.py
file and mount it inside the container from the local filesystem.
Correct me if something is wrong here.

>> +COPY ./requirements.txt /workdir/requirements.txt
>> +
>> +RUN pip install -r requirements.txt
>> +
>> +COPY . /workdir
>
> Is there a reason why you don't `COPY .` straight away? Why 2 copy
> operations?


This really is an optimisation on the way docker builds the image and
it’s not strictly needed but a nice to have.

When docker builds an image it runs every instruction one at a time
and cache it in a layer. By separating pip install from the code copy
means that as long as you don’t change the requirements.txt file
dependencies will not be re-downloaded during each build run.
Another big advantage is that layer cache works even across images for
users: let’s say I already have a working image of cloudtube locally
that is tagged :v1.
Tomorrow a new version :v2 is released, this new version have the same
dependencies as :v1 but lots of changes across the python source
files.
By using the cache I only have to download the changed source files
and not all the dependencies again.

If, instead, you first run COPY . /workdir and then run pip install
the cache will be invalidated by any small change in any file that is
part of the project. The final resulting image will be the same but
you’ll lose all the caching benefits.
Reply to thread Export thread (mbox)